示例#1
0
std::shared_ptr<mapnik::memory_datasource> build_ds(double x,double y, bool second) {
    mapnik::parameters params;
    params["type"] = "memory";
    std::shared_ptr<mapnik::memory_datasource> ds = std::make_shared<mapnik::memory_datasource>(params);
    mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
    ctx->push("name");
    mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1));
    mapnik::transcoder tr("utf-8");
    feature->put("name",tr.transcode("null island"));
    // NOTE: all types below that are not part of mapnik::value
    // are likely getting converted, e.g. float -> double
    feature->put_new("int",static_cast<int64_t>(-73));
    feature->put_new("uint",static_cast<uint64_t>(37));
    feature->put_new("float",static_cast<float>(99.2));
    feature->put_new("double",static_cast<double>(83.4));
    feature->put_new("bool",true);
    feature->put_new("boolf",false);
    feature->set_geometry(mapnik::geometry::point<double>(x,y));
    ds->push(feature);
    if (second) {
        ctx->push("name2");
        mapnik::feature_ptr feature2(mapnik::feature_factory::create(ctx,1));
        feature2->put("name",tr.transcode("null island"));
        feature2->put("name2",tr.transcode("null island 2"));
        feature2->set_geometry(mapnik::geometry::point<double>(x+1,y+1));
        ds->push(feature2);
    }
    return ds;
}
示例#2
0
文件: grid.cpp 项目: Andrey-VI/mapnik
void hit_grid<T>::add_feature(mapnik::feature_impl const& feature)
{
    value_type feature_id = feature.id();
    // avoid adding duplicate features (e.g. in the case of both a line symbolizer and a polygon symbolizer)
    typename feature_key_type::const_iterator feature_pos = f_keys_.find(feature_id);
    if (feature_pos != f_keys_.end())
    {
        return;
    }

    if (ctx_->size() == 0)
    {
        context_type::map_type::const_iterator itr = feature.context()->begin();
        context_type::map_type::const_iterator end = feature.context()->end();
        for ( ;itr!=end; ++itr)
        {
            ctx_->add(itr->first,itr->second);
        }
    }
    // NOTE: currently lookup keys must be strings,
    // but this should be revisited
    lookup_type lookup_value;
    if (key_ == id_name_)
    {
        mapnik::util::to_string(lookup_value,feature_id);
    }
    else
    {
        if (feature.has_key(key_))
        {
            lookup_value = feature.get(key_).to_string();
        }
        else
        {
            MAPNIK_LOG_DEBUG(grid) << "hit_grid: Should not get here: key '" << key_ << "' not found in feature properties";
        }
    }

    if (!lookup_value.empty())
    {
        // TODO - consider shortcutting f_keys if feature_id == lookup_value
        // create a mapping between the pixel id and the feature key
        f_keys_.emplace(feature_id,lookup_value);
        // if extra fields have been supplied, push them into grid memory
        if (!names_.empty())
        {
            // it is ~ 2x faster to copy feature attributes compared
            // to building up a in-memory cache of feature_ptrs
            // https://github.com/mapnik/mapnik/issues/1198
            mapnik::feature_ptr feature2(mapnik::feature_factory::create(ctx_,feature_id));
            feature2->set_data(feature.get_data());
            features_.emplace(lookup_value,feature2);
        }
    }
    else
    {
        MAPNIK_LOG_DEBUG(grid) << "hit_grid: Warning - key '" << key_ << "' was blank for " << feature;
    }
}
示例#3
0
文件: kvld.cpp 项目: mdqyy/KVLD
void writeResult(const std::string output,const std::vector<keypoint>& F1,const std::vector<keypoint>& F2,const std::vector<Pair>& matches,
  const std::vector<Pair>& matchesFiltered,const std::vector<double>& score){
//========features
    std::ofstream feature1((output+"Detectors1.txt"));
    if (!feature1.is_open())
      std::cout<<"error while writing Features1.txt"<<std::endl;
    
    feature1<<F1.size()<<std::endl;
    for (std::vector<keypoint>::const_iterator it=F1.begin(); it!=F1.end();it++){
        writeDetector(feature1,(*it));
    }
    feature1.close();

    std::ofstream feature2((output+"Detectors2.txt"));
    if (!feature2.is_open())
      std::cout<<"error while writing Features2.txt"<<std::endl;
    feature2<<F2.size()<<std::endl;
    for (std::vector<keypoint>::const_iterator it=F2.begin(); it!=F2.end();it++){
        writeDetector(feature2,(*it));
    }
    feature2.close();

//========matches
    std::ofstream initialmatches((output+"initial_matches.txt"));
    if (!initialmatches.is_open())
      std::cout<<"error while writing initial_matches.txt"<<std::endl;
    initialmatches<<matches.size()<<std::endl;
    for (std::vector<Pair>::const_iterator it=matches.begin(); it!=matches.end();it++){
        initialmatches<<it->first<<" "<<it->second<<std::endl;
        
    }
    initialmatches.close();

//==========kvld filtered matches
    std::ofstream filteredmatches((output+"kvld_matches.txt"));
    if (!filteredmatches.is_open())
      std::cout<<"error while writing kvld_filtered_matches.txt"<<std::endl;

    filteredmatches<<matchesFiltered.size()<<std::endl;
    for (std::vector<Pair>::const_iterator it=matchesFiltered.begin(); it!=matchesFiltered.end();it++){
        filteredmatches<<it->first<<" "<<it->second<<std::endl;
        
    }
   filteredmatches.close();

//====== KVLD score of matches
   std::ofstream kvldScore((output+"kvld_matches_score.txt"));
    if (!kvldScore.is_open())
      std::cout<<"error while writing kvld_matches_score.txt"<<std::endl;
    
    for (std::vector<double>::const_iterator it=score.begin(); it!=score.end();it++){
        filteredmatches<<*it<<std::endl;
        
    }
   kvldScore.close();
}