Metawriter support for LineSymbolizer and LinePatternSymbolizer

This commit is contained in:
Hermann Kraus 2010-08-12 19:12:15 +00:00
parent 4cb09a8aca
commit fb4baa4fcf
6 changed files with 58 additions and 13 deletions

View file

@ -71,6 +71,7 @@ class metawriter_properties : public std::set<std::string>
class metawriter
{
public:
typedef coord_transform2<CoordTransform,geometry2d> 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<double> 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, ...

View file

@ -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\": \""<<type<<"\",\n \"coordinates\":";
}
void write_properties(Feature const& feature, metawriter_properties const& properties);

View file

@ -156,10 +156,7 @@ void agg_renderer<T>::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);
}
}
}

View file

@ -105,6 +105,7 @@ void agg_renderer<T>::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<num_geometries;++i)
{
geometry2d const& geom = feature.get_geometry(i);
@ -112,6 +113,7 @@ void agg_renderer<T>::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);

View file

@ -63,7 +63,7 @@ void agg_renderer<T>::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<feature.num_geometries();++i)
{
geometry2d const& geom=feature.get_geometry(i);
@ -71,6 +71,7 @@ void agg_renderer<T>::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())));

View file

@ -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