当前位置: 首页>>代码示例>>C++>>正文


C++ mapnik类代码示例

本文整理汇总了C++中mapnik的典型用法代码示例。如果您正苦于以下问题:C++ mapnik类的具体用法?C++ mapnik怎么用?C++ mapnik使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了mapnik类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MAPNIK_LOG_DEBUG

feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
{
    if (band_ > 0)
    {
        unsigned raster_xsize = dataset_.GetRasterXSize();
        unsigned raster_ysize = dataset_.GetRasterYSize();

        double gt[6];
        dataset_.GetGeoTransform(gt);

        double det = gt[1] * gt[5] - gt[2] * gt[4];
        // subtract half a pixel width & height because gdal coord reference
        // is the top-left corner of a pixel, not the center.
        double X = pt.x - gt[0] - gt[1]/2;
        double Y = pt.y - gt[3] - gt[5]/2;
        double det1 = gt[1]*Y + gt[4]*X;
        double det2 = gt[2]*Y + gt[5]*X;
        unsigned x = det2/det, y = det1/det;

        if (x < raster_xsize && y < raster_ysize)
        {
            MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: pt.x=" << pt.x << " pt.y=" << pt.y;
            MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: x=" << x << " y=" << y;

            GDALRasterBand* band = dataset_.GetRasterBand(band_);
            int hasNoData;
            double nodata = band->GetNoDataValue(&hasNoData);
            double value;
            band->RasterIO(GF_Read, x, y, 1, 1, &value, 1, 1, GDT_Float64, 0, 0);

            if (! hasNoData || value != nodata)
            {
                // construct feature
                feature_ptr feature = feature_factory::create(ctx_,1);
                geometry_type * point = new geometry_type(mapnik::Point);
                point->move_to(pt.x, pt.y);
                feature->add_geometry(point);
                feature->put("value",value);
                return feature;
            }
        }
    }
    return feature_ptr();
}
开发者ID:chriskoli,项目名称:mapnik,代码行数:44,代码来源:gdal_featureset.cpp

示例2: datasource

sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
   : datasource(params),
     extent_(),
     extent_initialized_(false),
     type_(datasource::Vector),
     table_(*params.get<std::string>("table","")),
     fields_(*params.get<std::string>("fields","*")),
     metadata_(*params.get<std::string>("metadata","")),
     geometry_field_(*params.get<std::string>("geometry_field","the_geom")),
     key_field_(*params.get<std::string>("key_field","OGC_FID")),
     row_offset_(*params_.get<int>("row_offset",0)),
     row_limit_(*params_.get<int>("row_limit",0)),
     desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")),
     format_(mapnik::wkbGeneric)
{
    boost::optional<std::string> file = params.get<std::string>("file");
    if (!file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");

    boost::optional<std::string> wkb = params.get<std::string>("wkb_format");
    if (wkb)
    {
        if (*wkb == "spatialite")
            format_ = mapnik::wkbSpatiaLite;  
    }

    multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
    use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true);

    boost::optional<std::string> ext  = params_.get<std::string>("extent");
    if (ext) extent_initialized_ = extent_.from_string(*ext);

    boost::optional<std::string> base = params.get<std::string>("base");
    if (base)
        dataset_name_ = *base + "/" + *file;
    else
        dataset_name_ = *file;

    if (bind)
    {
        this->bind();
    }
}
开发者ID:BenMoores,项目名称:mapnik-trunk,代码行数:42,代码来源:sqlite_datasource.cpp

示例3: __stats__

featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const
{
#ifdef MAPNIK_STATS
    mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features_at_point");
#endif

    gdal_query gq = pt;

    // TODO - move to std::make_shared, but must reduce # of args to <= 9
    return featureset_ptr(new gdal_featureset(*open_dataset(),
                                              band_,
                                              gq,
                                              extent_,
                                              width_,
                                              height_,
                                              nbands_,
                                              dx_,
                                              dy_,
                                              nodata_value_,
                                              nodata_tolerance_));
}
开发者ID:NavtechInc,项目名称:mapnik,代码行数:21,代码来源:gdal_datasource.cpp

示例4: datasource

ogr_datasource::ogr_datasource(parameters const& params, bool bind)
  : datasource(params),
    extent_(),
    type_(datasource::Vector),
    desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
    indexed_(false)
{
    boost::optional<std::string> file = params.get<std::string>("file");
    boost::optional<std::string> string = params.get<std::string>("string");
    if (! file && ! string)
    {
        throw datasource_exception("missing <file> or <string> parameter");
    }

    multiple_geometries_ = *params.get<mapnik::boolean>("multiple_geometries", false);

    if (string)
    {
       dataset_name_ = *string;
    }
    else
    {
        boost::optional<std::string> base = params.get<std::string>("base");
        if (base)
        {
            dataset_name_ = *base + "/" + *file;
        }
        else
        {
            dataset_name_ = *file;
        }
    }

    if (bind)
    {
        this->bind();
    }
}
开发者ID:ParveenArora,项目名称:mapnik,代码行数:38,代码来源:ogr_datasource.cpp

示例5: if

feature_ptr kismet_featureset::next()
{
    if (knd_list_it != knd_list_.end ())
    {
        const kismet_network_data& knd = *knd_list_it;
        const std::string key = "internet_access";

        std::string value;
        if (knd.crypt_ == crypt_none)
        {
            value = "wlan_uncrypted";
        }
        else if (knd.crypt_ == crypt_wep)
        {
            value = "wlan_wep";
        }
        else
        {
            value = "wlan_crypted";
        }

        feature_ptr feature(feature_factory::create(feature_id_));
        ++feature_id_;
      
        geometry_type* pt = new geometry_type(mapnik::Point);
        pt->move_to(knd.bestlon_, knd.bestlat_);
        feature->add_geometry(pt);
      
        boost::put(*feature, key, tr_->transcode(value.c_str()));
      
        ++knd_list_it;
        
        return feature;
    }
    
    return feature_ptr();
}
开发者ID:dpaleino,项目名称:mapnik,代码行数:37,代码来源:kismet_featureset.cpp

示例6: datasource_exception

void sqlite_datasource::bind() const
{
    if (is_bound_) return;
    
    if (!boost::filesystem::exists(dataset_name_))
        throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist");
          
    dataset_ = new sqlite_connection (dataset_name_);

    if(geometry_table_.empty())
    {
        geometry_table_ = mapnik::table_from_sql(table_);
    }
    

    // should we deduce column names and types using PRAGMA?
    bool use_pragma_table_info = true;
    
    if (table_ != geometry_table_)
    {
        // if 'table_' is a subquery then we try to deduce names
        // and types from the first row returned from that query
        use_pragma_table_info = false;
    }

    if (!use_pragma_table_info)
    {
        std::ostringstream s;
        s << "SELECT " << fields_ << " FROM (" << table_ << ") LIMIT 1";

        boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
        if (rs->is_valid () && rs->step_next())
        {
            for (int i = 0; i < rs->column_count (); ++i)
            {
               const int type_oid = rs->column_type (i);
               const char* fld_name = rs->column_name (i);
               switch (type_oid)
               {
                  case SQLITE_INTEGER:
                     desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
                     break;
                     
                  case SQLITE_FLOAT:
                     desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
                     break;
                     
                  case SQLITE_TEXT:
                     desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
                     break;
                     
                  case SQLITE_NULL:
                     // sqlite reports based on value, not actual column type unless
                     // PRAGMA table_info is used so here we assume the column is a string
                     // which is a lesser evil than altogether dropping the column
                     desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));

                  case SQLITE_BLOB:
                        if (geometry_field_.empty() && 
                             (boost::algorithm::icontains(fld_name,"geom") ||
                              boost::algorithm::icontains(fld_name,"point") ||
                              boost::algorithm::icontains(fld_name,"linestring") ||
                              boost::algorithm::icontains(fld_name,"polygon"))
                            )
                            geometry_field_ = std::string(fld_name);
                     break;
                     
                  default:
#ifdef MAPNIK_DEBUG
                     std::clog << "Sqlite Plugin: unknown type_oid=" << type_oid << std::endl;
#endif
                     break;
                }
            }
        }
        else
        {
            // if we do not have at least a row and
            // we cannot determine the right columns types and names 
            // as all column_type are SQLITE_NULL
            // so we fallback to using PRAGMA table_info
            use_pragma_table_info = true;
        }
    }

    // TODO - ensure that the supplied key_field is a valid "integer primary key"
    desc_.add_descriptor(attribute_descriptor("rowid",mapnik::Integer));
    
    if (use_pragma_table_info)
    {
        std::ostringstream s;
        s << "PRAGMA table_info(" << geometry_table_ << ")";
        boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
        bool found_table = false;
        while (rs->is_valid () && rs->step_next())
        {
            found_table = true;
            const char* fld_name = rs->column_text(1);
            std::string fld_type(rs->column_text(2));
            boost::algorithm::to_lower(fld_type);
//.........这里部分代码省略.........
开发者ID:makinacorpus,项目名称:mapnik2,代码行数:101,代码来源:sqlite_datasource.cpp

示例7: datasource

raster_datasource::raster_datasource(parameters const& params)
: datasource(params),
    desc_(*params.get<std::string>("type"), "utf-8"),
    extent_initialized_(false)
{
    MAPNIK_LOG_DEBUG(raster) << "raster_datasource: Initializing...";

    boost::optional<std::string> file = params.get<std::string>("file");
    if (! file) throw datasource_exception("Raster Plugin: missing <file> parameter ");

    boost::optional<std::string> base = params.get<std::string>("base");
    if (base)
        filename_ = *base + "/" + *file;
    else
        filename_ = *file;

    multi_tiles_ = *params.get<mapnik::boolean>("multi", false);
    tile_size_ = *params.get<int>("tile_size", 256);
    tile_stride_ = *params.get<int>("tile_stride", 1);

    boost::optional<std::string> format_from_filename = mapnik::type_from_filename(*file);
    format_ = *params.get<std::string>("format",format_from_filename?(*format_from_filename) : "tiff");

    boost::optional<double> lox = params.get<double>("lox");
    boost::optional<double> loy = params.get<double>("loy");
    boost::optional<double> hix = params.get<double>("hix");
    boost::optional<double> hiy = params.get<double>("hiy");

    boost::optional<std::string> ext = params.get<std::string>("extent");

    if (lox && loy && hix && hiy)
    {
        extent_.init(*lox, *loy, *hix, *hiy);
        extent_initialized_ = true;
    }
    else if (ext)
    {
        extent_initialized_ = extent_.from_string(*ext);
    }

    if (! extent_initialized_)
    {
        throw datasource_exception("Raster Plugin: valid <extent> or <lox> <loy> <hix> <hiy> are required");
    }

    if (multi_tiles_)
    {
        boost::optional<int> x_width = params.get<int>("x_width");
        boost::optional<int> y_width = params.get<int>("y_width");

        if (! x_width)
        {
            throw datasource_exception("Raster Plugin: x-width parameter not supplied for multi-tiled data source.");
        }

        if (! y_width)
        {
            throw datasource_exception("Raster Plugin: y-width parameter not supplied for multi-tiled data source.");
        }

        width_ = x_width.get() * tile_size_;
        height_ = y_width.get() * tile_size_;
    }
    else
    {
        if (!mapnik::util::exists(filename_))
        {
            throw datasource_exception("Raster Plugin: " + filename_ + " does not exist");
        }

        try
        {
            std::auto_ptr<image_reader> reader(mapnik::get_image_reader(filename_, format_));
            if (reader.get())
            {
                width_ = reader->width();
                height_ = reader->height();
            }
        }
        catch (mapnik::image_reader_exception const& ex)
        {
            throw datasource_exception("Raster Plugin: image reader exception: " + std::string(ex.what()));
        }
        catch (std::exception const& ex)
        {
            throw datasource_exception("Raster Plugin: " + std::string(ex.what()));
        }
        catch (...)
        {
            throw datasource_exception("Raster Plugin: image reader unknown exception caught");
        }
    }

    MAPNIK_LOG_DEBUG(raster) << "raster_datasource: Raster size=" << width_ << "," << height_;

}
开发者ID:Blaxxun,项目名称:mapnik,代码行数:96,代码来源:raster_datasource.cpp

示例8: open_dataset

void gdal_datasource::bind() const
{
    if (is_bound_) return;

    shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
    band_ = *params_.get<int>("band", -1);

    GDALDataset *dataset = open_dataset();

    nbands_ = dataset->GetRasterCount();
    width_ = dataset->GetRasterXSize();
    height_ = dataset->GetRasterYSize();

    double tr[6];
    bool bbox_override = false;
    boost::optional<std::string> bbox_s = params_.get<std::string>("bbox");
    if (bbox_s)
    {
#ifdef MAPNIK_DEBUG
        std::clog << "GDAL Plugin: bbox parameter=" << *bbox_s << std::endl;
#endif

        bbox_override = extent_.from_string(*bbox_s);
        if (! bbox_override)
        {
            throw datasource_exception("GDAL Plugin: bbox parameter '" + *bbox_s + "' invalid");
        }
    }

    if (bbox_override)
    {
        tr[0] = extent_.minx();
        tr[1] = extent_.width() / (double)width_;
        tr[2] = 0;
        tr[3] = extent_.maxy();
        tr[4] = 0;
        tr[5] = -extent_.height() / (double)height_;
    }
    else
    {
        dataset->GetGeoTransform(tr);
    }

#ifdef MAPNIK_DEBUG
    std::clog << "GDAL Plugin: geotransform=" << tr[0] << "," << tr[1] << ","
              << tr[2] << "," << tr[3] << ","
              << tr[4] << "," << tr[5] << std::endl;
#endif

    // TODO - We should throw for true non-north up images, but the check
    // below is clearly too restrictive.
    // https://github.com/mapnik/mapnik/issues/970
    /*
    if (tr[2] != 0 || tr[4] != 0)
    {
        throw datasource_exception("GDAL Plugin: only 'north up' images are supported");
    }
    */

    dx_ = tr[1];
    dy_ = tr[5];

    if (! bbox_override)
    {
        double x0 = tr[0];
        double y0 = tr[3];
        double x1 = tr[0] + width_ * dx_ + height_ *tr[2];
        double y1 = tr[3] + width_ *tr[4] + height_ * dy_;

        /*
          double x0 = tr[0] + (height_) * tr[2]; // minx
          double y0 = tr[3] + (height_) * tr[5]; // miny

          double x1 = tr[0] + (width_) * tr[1]; // maxx
          double y1 = tr[3] + (width_) * tr[4]; // maxy
        */

        extent_.init(x0, y0, x1, y1);
    }

    GDALClose(dataset);

#ifdef MAPNIK_DEBUG
    std::clog << "GDAL Plugin: Raster Size=" << width_ << "," << height_ << std::endl;
    std::clog << "GDAL Plugin: Raster Extent=" << extent_ << std::endl;
#endif

    is_bound_ = true;
}
开发者ID:eightysteele,项目名称:mapnik,代码行数:89,代码来源:gdal_datasource.cpp

示例9: while

feature_ptr sqlite_featureset::next()
{
    while (rs_->is_valid () && rs_->step_next ())
    {
        int size;
        const char* data = (const char*) rs_->column_blob(0, size);
        if (data == 0)
        {
            return feature_ptr();
        }

        // null feature id is not acceptable
        if (rs_->column_type(1) == SQLITE_NULL)
        {
            MAPNIK_LOG_ERROR(postgis) << "sqlite_featureset: null value encountered for key_field";
            continue;
        }

        feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1));
        if (!geometry_utils::from_wkb(feature->paths(), data, size, format_))
            continue;

        if (!spatial_index_)
        {
            // we are not using r-tree index, check if feature intersects bounding box
            if (!bbox_.intersects(feature->envelope()))
                continue;
        }

        for (int i = 2; i < rs_->column_count(); ++i)
        {
            const int type_oid = rs_->column_type(i);
            const char* fld_name = rs_->column_name(i);

            if (! fld_name)
                continue;

            std::string fld_name_str(fld_name);

            // subqueries in sqlite lead to field double quoting which we need to strip
            if (using_subquery_)
            {
                sqlite_utils::dequote(fld_name_str);
            }

            switch (type_oid)
            {
            case SQLITE_INTEGER:
            {
                feature->put<mapnik::value_integer>(fld_name_str, rs_->column_integer64(i));
                break;
            }

            case SQLITE_FLOAT:
            {
                feature->put(fld_name_str, rs_->column_double(i));
                break;
            }

            case SQLITE_TEXT:
            {
                int text_col_size;
                const char * text_data = rs_->column_text(i, text_col_size);
                feature->put(fld_name_str, tr_->transcode(text_data, text_col_size));
                break;
            }

            case SQLITE_NULL:
            {
                // NOTE: we intentionally do not store null here
                // since it is equivalent to the attribute not existing
                break;
            }

            case SQLITE_BLOB:
                break;

            default:
                MAPNIK_LOG_WARN(sqlite) << "sqlite_featureset: Field=" << fld_name_str << " unhandled type_oid=" << type_oid;
                break;
            }
        }

        return feature;
    }

    return feature_ptr();
}
开发者ID:Andrey-VI,项目名称:mapnik,代码行数:88,代码来源:sqlite_featureset.cpp

示例10: geometry_type

feature_ptr osm_featureset<filterT>::next()
{
    feature_ptr feature;

    osm_item* cur_item = dataset_->next_item();
    if (!cur_item) return feature_ptr();
    if (dataset_->current_item_is_node())
    {
        feature = feature_factory::create(ctx_, cur_item->id);
        double lat = static_cast<osm_node*>(cur_item)->lat;
        double lon = static_cast<osm_node*>(cur_item)->lon;
        geometry_type* point = new geometry_type(mapnik::Point);
        point->move_to(lon, lat);
        feature->add_geometry(point);
    }
    else if (dataset_->current_item_is_way())
    {
        // Loop until we find a feature which passes the filter
        while (cur_item)
        {
            bounds b = static_cast<osm_way*>(cur_item)->get_bounds();
            if (filter_.pass(box2d<double>(b.w, b.s, b.e, b.n))
                    &&
                static_cast<osm_way*>(cur_item)->nodes.size()) break;
            cur_item = dataset_->next_item();
        }

        if (!cur_item) return feature_ptr();
        feature = feature_factory::create(ctx_, cur_item->id);
        geometry_type* geom;
        if (static_cast<osm_way*>(cur_item)->is_polygon())
        {
            geom = new geometry_type(mapnik::Polygon);
        }
        else
        {
            geom = new geometry_type(mapnik::LineString);
        }

        geom->move_to(static_cast<osm_way*>(cur_item)->nodes[0]->lon,
                      static_cast<osm_way*>(cur_item)->nodes[0]->lat);

        for (unsigned int count = 1;
             count < static_cast<osm_way*>(cur_item)->nodes.size();
             count++)
        {
            geom->line_to(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
                          static_cast<osm_way*>(cur_item)->nodes[count]->lat);
        }
        feature->add_geometry(geom);
    }
    else
    {
        MAPNIK_LOG_ERROR(osm_featureset) << "Current item is neither node nor way.\n";
    }

    std::set<std::string>::const_iterator itr = attribute_names_.begin();
    std::set<std::string>::const_iterator end = attribute_names_.end();
    std::map<std::string,std::string>::iterator end_keyvals = cur_item->keyvals.end();
    for (; itr != end; itr++)
    {
        std::map<std::string,std::string>::iterator i = cur_item->keyvals.find(*itr);
        if (i != end_keyvals)
        {
            feature->put_new(i->first, tr_->transcode(i->second.c_str()));
        }
    }
    return feature;
}
开发者ID:mokerjoke,项目名称:mapnik,代码行数:69,代码来源:osm_featureset.cpp

示例11: get_feature_at_point

feature_ptr rasterlite_featureset::get_feature_at_point(mapnik::coord2d const& pt)
{
    return feature_ptr();
}
开发者ID:Airphrame,项目名称:mapnik,代码行数:4,代码来源:rasterlite_featureset.cpp

示例12: features

featureset_ptr gdal_datasource::features(query const& q) const
{
    if (! is_bound_) bind();

    gdal_query gq = q;

    // TODO - move to boost::make_shared, but must reduce # of args to <= 9
    return featureset_ptr(new gdal_featureset(*open_dataset(),
                                              band_,
                                              gq,
                                              extent_,
                                              width_,
                                              height_,
                                              nbands_,
                                              dx_,
                                              dy_,
                                              filter_factor_));
}
开发者ID:eightysteele,项目名称:mapnik,代码行数:18,代码来源:gdal_datasource.cpp

示例13:

/*
 * Opens a GDALDataset and returns a pointer to it.
 * Caller is responsible for calling GDALClose on it
 */
inline GDALDataset *gdal_datasource::open_dataset() const
{

#ifdef MAPNIK_DEBUG
    std::clog << "GDAL Plugin: opening: " << dataset_name_ << std::endl;
#endif

    GDALDataset *dataset;
#if GDAL_VERSION_NUM >= 1600
    if (shared_dataset_)
        dataset = reinterpret_cast<GDALDataset*>(GDALOpenShared((dataset_name_).c_str(),GA_ReadOnly));
    else
#endif
        dataset = reinterpret_cast<GDALDataset*>(GDALOpen((dataset_name_).c_str(),GA_ReadOnly));

    if (! dataset) throw datasource_exception(CPLGetLastErrorMsg());
    return dataset;
}
开发者ID:BenMoores,项目名称:mapnik-trunk,代码行数:22,代码来源:gdal_datasource.cpp

示例14: next

feature_ptr rasterlite_featureset::next()
{
   if (first_)
   {
      first_ = false;

      query *q = boost::get<query>(&gquery_);
      if(q) {
          return get_feature(*q);
      } else {
          coord2d *p = boost::get<coord2d>(&gquery_);
          if(p) {
              return get_feature_at_point(*p);
          }
      }
      // should never reach here
   }
   return feature_ptr();
}
开发者ID:h4ck3rm1k3,项目名称:MapNickAutotools,代码行数:19,代码来源:rasterlite_featureset.cpp

示例15: features_at_point

featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
{
    if (!is_bound_) bind();

    std::ostringstream s;
    s << "POINT(" << pt.x << " " << pt.y << ")";

#ifdef MAPNIK_DEBUG
    clog << "GEOS Plugin: using point: " << s.str() << endl;
#endif

    return featureset_ptr(new geos_featureset (*geometry_,
                                               GEOSGeomFromWKT(s.str().c_str()),
                                               geometry_id_,
                                               geometry_data_,
                                               geometry_data_name_,
                                               desc_.get_encoding(),
                                               multiple_geometries_));
}
开发者ID:BenMoores,项目名称:mapnik-trunk,代码行数:19,代码来源:geos_datasource.cpp


注:本文中的mapnik类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。