From fb4baa4fcffccff4efac9a798a2f92dcabe3d2db Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Thu, 12 Aug 2010 19:12:15 +0000 Subject: [PATCH] Metawriter support for LineSymbolizer and LinePatternSymbolizer --- include/mapnik/metawriter.hpp | 9 ++++- include/mapnik/metawriter_json.hpp | 15 +++++--- src/agg/process_point_symbolizer.cpp | 5 +-- .../process_polygon_pattern_symbolizer.cpp | 2 + src/agg/process_polygon_symbolizer.cpp | 3 +- src/metawriter.cpp | 37 ++++++++++++++++++- 6 files changed, 58 insertions(+), 13 deletions(-) diff --git a/include/mapnik/metawriter.hpp b/include/mapnik/metawriter.hpp index a18c3ecfa..db4cbccb0 100644 --- a/include/mapnik/metawriter.hpp +++ b/include/mapnik/metawriter.hpp @@ -71,6 +71,7 @@ class metawriter_properties : public std::set class metawriter { public: + typedef coord_transform2 path_type; metawriter(metawriter_properties dflt_properties) : dflt_properties_(dflt_properties) {} virtual ~metawriter() {}; /** Output a rectangular area. @@ -82,12 +83,16 @@ class metawriter */ virtual void add_box(box2d const& box, Feature const& feature, CoordTransform const& t, - metawriter_properties const& properties = metawriter_properties())=0; + metawriter_properties const& properties)=0; virtual void add_text(placement const& placement, face_set_ptr face, Feature const& feature, CoordTransform const& t, - metawriter_properties const& properties = metawriter_properties())=0; + metawriter_properties const& properties)=0; + virtual void add_polygon(path_type & path, + Feature const& feature, + CoordTransform const& t, + metawriter_properties const& properties)=0; /** Start processing. * Write file header, init database connection, ... diff --git a/include/mapnik/metawriter_json.hpp b/include/mapnik/metawriter_json.hpp index 21e25eab4..7e7830754 100644 --- a/include/mapnik/metawriter_json.hpp +++ b/include/mapnik/metawriter_json.hpp @@ -47,7 +47,11 @@ public: face_set_ptr face, Feature const& feature, CoordTransform const& t, - metawriter_properties const& properties = metawriter_properties()); + metawriter_properties const& properties); + virtual void add_polygon(path_type & path, + Feature const& feature, + CoordTransform const& t, + metawriter_properties const& properties); virtual void start(metawriter_property_map const& properties); virtual void stop(); @@ -74,14 +78,15 @@ protected: projection output_srs_; virtual void write_header(); inline void write_feature_header(std::string type) { - if (count_ == HEADER_NOT_WRITTEN) write_header(); - if (count_++) *f_ << ",\n"; - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG if (count_ == STOPPED) { std::cerr << "WARNING: Metawriter not started before using it.\n"; } - #endif +#endif + if (count_ == HEADER_NOT_WRITTEN) write_header(); + if (count_++) *f_ << ",\n"; + *f_ << "{ \"type\": \"Feature\",\n \"geometry\": { \"type\": \""<::process(point_symbolizer const& sym, pixmap_.set_rectangle_alpha2(*(*data), px, py, sym.get_opacity()); detector_.insert(label_ext); metawriter_with_properties writer = sym.get_metawriter(); - if (writer.first) - { - writer.first->add_box(label_ext, feature, t_, writer.second); - } + if (writer.first) writer.first->add_box(label_ext, feature, t_, writer.second); } } } diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index 7c3f6842c..201b15e19 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -105,6 +105,7 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, span_gen_type sg(img_src, offset_x, offset_y); renderer_type rp(renb,sa, sg); + metawriter_with_properties writer = sym.get_metawriter(); for (unsigned i=0;i::process(polygon_pattern_symbolizer const& sym, { path_type path(t_,geom,prj_trans); ras_ptr->add_path(path); + if (writer.first) writer.first->add_polygon(path, feature, t_, writer.second); } } agg::render_scanlines(*ras_ptr, sl, rp); diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index 9d421b476..6cbf3eab1 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -63,7 +63,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, ras_ptr->reset(); ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma())); - + metawriter_with_properties writer = sym.get_metawriter(); for (unsigned i=0;i::process(polygon_symbolizer const& sym, { path_type path(t_,geom,prj_trans); ras_ptr->add_path(path); + if (writer.first) writer.first->add_polygon(path, feature, t_, writer.second); } } ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity()))); diff --git a/src/metawriter.cpp b/src/metawriter.cpp index c9f78593e..927efdc12 100644 --- a/src/metawriter.cpp +++ b/src/metawriter.cpp @@ -257,6 +257,41 @@ void metawriter_json_stream::add_text(placement const& p, } } +void metawriter_json_stream::add_polygon(path_type & path, + Feature const& feature, + CoordTransform const& t, + metawriter_properties const& properties) +{ + std::cout << count_ << "Polygon\n"; + write_feature_header("Polygon"); + std::cout << count_ << "Polygon started\n"; + + *f_ << " ["; + double x, y, last_x=0.0, last_y=0.0; + unsigned cmd, last_cmd = SEG_END; + path.rewind(0); + + int polygon_count = 0; + while ((cmd = path.vertex(&x, &y)) != SEG_END) { + if (cmd == SEG_LINETO) { + if (last_cmd == SEG_MOVETO) { + //Start new polygon + if (polygon_count++) *f_ << "], "; + *f_ << "["; + write_point(t, last_x, last_y, true); + } + *f_ << ","; + write_point(t, x, y, true); + } + last_x = x; + last_y = y; + last_cmd = cmd; + } + *f_ << "]]"; + write_properties(feature, properties); + +} + void metawriter_json_stream::set_map_srs(projection const& input_srs_) { @@ -297,7 +332,7 @@ void metawriter_json::stop() f_.close(); } #ifdef MAPNIK_DEBUG - else { + else if (count_ >= STARTED){ std::clog << "WARNING: File not open in metawriter_json::stop()!\n"; } #endif