From 568d3cbf41534d10b59a204bfe515c82a8e4ddbf Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 23 Feb 2015 11:43:32 -0800 Subject: [PATCH] don't use geom collection, instead diff geom per feature --- .../templates/helloworld/hello_featureset.cpp | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/plugins/input/templates/helloworld/hello_featureset.cpp b/plugins/input/templates/helloworld/hello_featureset.cpp index bd39b704d..dfefc7906 100644 --- a/plugins/input/templates/helloworld/hello_featureset.cpp +++ b/plugins/input/templates/helloworld/hello_featureset.cpp @@ -11,7 +11,10 @@ hello_featureset::hello_featureset(mapnik::box2d const& box, std::string : box_(box), feature_id_(1), tr_(new mapnik::transcoder(encoding)), - ctx_(std::make_shared()) { } + ctx_(std::make_shared()) { + // add known field names to attributes schema + ctx_->push("key"); + } hello_featureset::~hello_featureset() { } @@ -19,33 +22,38 @@ mapnik::feature_ptr hello_featureset::next() { if (feature_id_ == 1) { - // let us pretend it just has one column/attribute name - std::string attribute("key"); - - // the featureset context needs to know the field schema - ctx_->push(attribute); - // create a new feature mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); - // increment the count so that we only return one feature + // increment the count ++feature_id_; // create an attribute pair of key:value - mapnik::value_unicode_string ustr = tr_->transcode("hello world!"); - feature->put(attribute,ustr); + feature->put("key",tr_->transcode("hello world point!")); - // we need a geometry to display so just for fun here - // we take the center of the bbox that was used to query - // since we don't actually have any data to pull from... + // take the center of the bbox that was used to query + // to dynamically generate a fake point mapnik::coord2d center = box_.center(); // create a new point geometry feature->set_geometry(mapnik::new_geometry::point(center.x,center.y)); - // A feature usually will have just one geometry of a given type - // but mapnik supports many geometries per feature of any type - // so here we draw a line around the point + // return the feature! + return feature; + } + else if (feature_id_ == 2) + { + // create a second feature + mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); + + // increment the count + ++feature_id_; + + // create an attribute pair of key:value + feature->put("key",tr_->transcode("hello world line!")); + + // take the outer ring of the bbox that was used to query + // to dynamically generate a fake line mapnik::new_geometry::line_string line; line.reserve(4); line.add_coord(box_.minx(),box_.maxy()); @@ -53,8 +61,6 @@ mapnik::feature_ptr hello_featureset::next() line.add_coord(box_.maxx(),box_.miny()); line.add_coord(box_.minx(),box_.miny()); feature->set_geometry(std::move(line)); - - // return the feature! return feature; }