Example #1
0
mapnik::feature_ptr csv_featureset::next()
{
    if (index_itr_ != index_end_)
    {
        csv_datasource::item_type const& item = *index_itr_++;
        std::uint64_t file_offset = item.second.first;
        std::uint64_t size = item.second.second;
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
        char const* start = (char const*)mapped_region_->get_address() + file_offset;
        char const*  end = start + size;
#else
        std::fseek(file_.get(), file_offset, SEEK_SET);
        std::vector<char> record;
        record.resize(size);
        if (std::fread(record.data(), size, 1, file_.get()) != 1)
        {
            return mapnik::feature_ptr();
        }
        auto const* start = record.data();
        auto const*  end = start + record.size();
#endif
        return parse_feature(start, end);
    }
    return mapnik::feature_ptr();
}
mapnik::feature_ptr csv_index_featureset::next()
{
    /*
    if (row_limit_ && count_ >= row_limit_)
    {
        return feature_ptr();
    }
    */

    while( itr_ != positions_.end())
    {
        auto pos = *itr_++;
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
        char const* start = (char const*)mapped_region_->get_address() + pos.first;
        char const*  end = start + pos.second;
#else
        std::fseek(file_.get(), pos.first, SEEK_SET);
        std::vector<char> record;
        record.resize(pos.second);
        if (std::fread(record.data(), pos.second, 1, file_.get()) != 1)
        {
            return mapnik::feature_ptr();
        }
        auto const* start = record.data();
        auto const*  end = start + record.size();
#endif
        auto feature = parse_feature(start, end);
        if (feature) return feature;
    }
    return mapnik::feature_ptr();
}
Example #3
0
void parse_geometry_or_feature(Iterator& itr, Iterator const& end, feature_impl& feature, transcoder const& tr )
{
    Iterator start = itr;
    try
    {
        parse_feature(start, end, feature, tr);
    }
    catch (...)
    {
        start = itr;
        parse_geometry(start, end, feature);
    }
}
Example #4
0
int parse_features(struct vzctl_features_param *features, const char *str)
{
	int ret = 0;
	char *buf = NULL, *token;
	char *savedptr;

	ret = xstrdup(&buf, str);
	if (ret)
		return ret;
	if ((token = strtok_r(buf, LIST_DELIMITERS, &savedptr)) != NULL) {
		do {
			ret = parse_feature(features, token);
			if (ret)
				break;

		} while ((token = strtok_r(NULL, LIST_DELIMITERS, &savedptr)) != NULL);
	}
	free(buf);

	return ret;
}
Example #5
0
int GBDTData::load_line(const char* line) {
    if (line == NULL || line[0] == 0) {
        return 1;
    }
    int ret = 0;
    GBDT_TUPLE_T* result = new GBDT_TUPLE_T();
    result -> feature = new GBDTValue[_m_feature_size];
    for (int i = 0; i < _m_feature_size; i++) {
        result -> feature[i] = GBDT_UNKNOWN_VALUE;
    }

    std::vector<std::string> tokens;
    ret = split_line(line, tokens);
    if (ret != 0) {
        return 1;
    }
    if (_m_load_initial_guess && tokens.size() < 3) {
        return 1;
    } else if (!_m_load_initial_guess && tokens.size() < 2) {
        return 1;
    }
    result -> label  = boost::lexical_cast<GBDTValue>(tokens[0]);
    if (_m_ignore_weight) {
        result -> weight = 1;
    } else {
        result -> weight = boost::lexical_cast<GBDTValue>(tokens[1]);
    }
    for (int i = 2; i < (int)tokens.size(); i++) {
        int idx           = 0;
        GBDTValue feature = 0;
        parse_feature(tokens[i].c_str(), idx, feature);
        result -> feature[idx] = feature;
    }
    _m_data.push_back(result);
    return 0;
}