adapt to use mapnik::new_geometry::geometry (shape.input only)

This commit is contained in:
artemp 2015-02-18 13:21:16 +01:00
parent 0223e1f93e
commit 2e4e1f71b8
9 changed files with 116 additions and 81 deletions

View file

@ -178,48 +178,51 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
if (fs)
{
feature_ptr feat = fs->next();
if (feat)
{
feature_ptr feat = fs->next();
if (feat)
{
feature_kv_iterator itr(*feat,true);
feature_kv_iterator end(*feat);
// FIXME
#if 0
feature_kv_iterator itr(*feat,true);
feature_kv_iterator end(*feat);
for ( ;itr!=end; ++itr)
{
info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
std::get<1>(*itr).to_string().c_str()));
}
for ( ;itr!=end; ++itr)
{
info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
std::get<1>(*itr).to_string().c_str()));
}
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
for (unsigned i=0; i<feat->num_geometries();++i)
{
mapnik::geometry_type const& geom = feat->get_geometry(i);
mapnik::vertex_adapter va(geom);
path_type path(t,va,prj_trans);
if (va.size() > 0)
{
QPainterPath qpath;
double x,y;
va.vertex(&x,&y);
qpath.moveTo(x,y);
for (unsigned j = 1; j < geom.size(); ++j)
for (unsigned i=0; i<feat->num_geometries();++i)
{
mapnik::geometry_type const& geom = feat->get_geometry(i);
mapnik::vertex_adapter va(geom);
path_type path(t,va,prj_trans);
if (va.size() > 0)
{
va.vertex(&x,&y);
qpath.lineTo(x,y);
QPainterPath qpath;
double x,y;
va.vertex(&x,&y);
qpath.moveTo(x,y);
for (unsigned j = 1; j < geom.size(); ++j)
{
va.vertex(&x,&y);
qpath.lineTo(x,y);
}
QPainter painter(&pix_);
QPen pen(QColor(255,0,0,96));
pen.setWidth(3);
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
painter.setPen(pen);
painter.drawPath(qpath);
update();
}
QPainter painter(&pix_);
QPen pen(QColor(255,0,0,96));
pen.setWidth(3);
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
painter.setPen(pen);
painter.drawPath(qpath);
update();
}
}
}
}
#endif
}
}
if (info.size() > 0)
@ -530,8 +533,8 @@ void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{
#ifdef HAVE_CAIRO
// FIXME
#if 0 //def HAVE_CAIRO
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
mapnik::cairo_surface_closer());
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);

View file

@ -40,6 +40,7 @@
#include <ostream> // for basic_ostream, operator<<, etc
#include <sstream> // for basic_stringstream
#include <stdexcept> // for out_of_range
#include <iostream>
namespace mapnik {
@ -206,6 +207,7 @@ public:
inline box2d<double> envelope() const
{
box2d<double> result;
std::cerr << "ENVELOPE" << std::endl;
return result;
}

View file

@ -196,7 +196,7 @@ struct polygon : vertex_sequence
}
};
typedef mapnik::util::variant< point,line_string, polygon, polygon2, polygon3> geometry;
typedef mapnik::util::variant< point,line_string, polygon3, multi_point, multi_line_string, multi_polygon> geometry;
struct point_vertex_adapter
{

View file

@ -390,9 +390,10 @@ struct vertex_converter : private util::noncopyable
double scale_factor)
: disp_(proc,bbox,sym,tr,prj_trans,affine_trans,feature,vars,scale_factor) {}
void apply(vertex_adapter & geom)
template <typename VertexAdapter>
void apply(VertexAdapter & geom)
{
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template forward<vertex_adapter>(disp_, geom);
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template forward<VertexAdapter>(disp_, geom);
}
template <typename Converter>

View file

@ -88,9 +88,11 @@ feature_ptr shape_featureset<filterT>::next()
double y = record.read_double();
if (!filter_.pass(mapnik::box2d<double>(x,y,x,y)))
continue;
std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
point->move_to(x, y);
feature->paths().push_back(point.release());
//std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
//point->move_to(x, y);
//feature->paths().push_back(point.release());
mapnik::new_geometry::point pt(x, y);
feature->set_geometry(std::move(pt));
break;
}
case shape_io::shape_multipoint:
@ -100,14 +102,18 @@ feature_ptr shape_featureset<filterT>::next()
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer();
mapnik::new_geometry::multi_point multi_pt;
for (int i = 0; i < num_points; ++i)
{
double x = record.read_double();
double y = record.read_double();
std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
point->move_to(x, y);
feature->paths().push_back(point.release());
mapnik::new_geometry::point pt(x, y);
//std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
//point->move_to(x, y);
//feature->paths().push_back(point.release());
multi_pt.push_back(std::move(pt));
}
feature->set_geometry(std::move(multi_pt));
break;
}
@ -117,7 +123,12 @@ feature_ptr shape_featureset<filterT>::next()
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polyline(record, feature->paths());
mapnik::new_geometry::geometry && geometry = shape_io::read_polyline(record);
if (geometry.is<mapnik::new_geometry::line_string>())
{
auto const& line = mapnik::util::get<mapnik::new_geometry::line_string>(geometry);
}
feature->set_geometry(std::move(geometry));
break;
}
case shape_io::shape_polygon:
@ -126,7 +137,7 @@ feature_ptr shape_featureset<filterT>::next()
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polygon(record, feature->paths());
//shape_io::read_polygon(record, feature->paths());
break;
}
default :

View file

@ -104,9 +104,11 @@ feature_ptr shape_index_featureset<filterT>::next()
{
double x = record.read_double();
double y = record.read_double();
std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
point->move_to(x, y);
feature->paths().push_back(point.release());
mapnik::new_geometry::point point(x, y);
//std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
//point->move_to(x, y);
//feature->paths().push_back(point.release());
feature->set_geometry(std::move(point));
break;
}
case shape_io::shape_multipoint:
@ -116,14 +118,18 @@ feature_ptr shape_index_featureset<filterT>::next()
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer();
mapnik::new_geometry::multi_point multi_point;
for (int i = 0; i < num_points; ++i)
{
double x = record.read_double();
double y = record.read_double();
std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
point->move_to(x, y);
feature->paths().push_back(point.release());
mapnik::new_geometry::point point(x, y);
//std::unique_ptr<geometry_type> point(new geometry_type(mapnik::geometry_type::types::Point));
//point->move_to(x, y);
//feature->paths().push_back(point.release());
multi_point.emplace_back(point);
}
feature->set_geometry(std::move(multi_point));
break;
}
case shape_io::shape_polyline:
@ -132,7 +138,8 @@ feature_ptr shape_index_featureset<filterT>::next()
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polyline(record,feature->paths());
mapnik::new_geometry::geometry && geometry = shape_io::read_polyline(record);
feature->set_geometry(std::move(geometry));
break;
}
case shape_io::shape_polygon:
@ -141,7 +148,8 @@ feature_ptr shape_index_featureset<filterT>::next()
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polygon(record,feature->paths());
// FIXME
//shape_io::read_polygon(record,feature->paths());
break;
}
default :

View file

@ -90,24 +90,23 @@ void shape_io::read_bbox(shape_file::record_type & record, mapnik::box2d<double>
bbox.init(lox, loy, hix, hiy);
}
void shape_io::read_polyline( shape_file::record_type & record, mapnik::geometry_container & geom)
mapnik::new_geometry::geometry shape_io::read_polyline(shape_file::record_type & record)
{
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
if (num_parts == 1)
{
std::unique_ptr<geometry_type> line(new geometry_type(mapnik::geometry_type::types::LineString));
mapnik::new_geometry::line_string line;
record.skip(4);
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int i = 1; i < num_points; ++i)
for (int i = 0; i < num_points; ++i)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
double x = record.read_double();
double y = record.read_double();
line.add_coord(x, y);
}
geom.push_back(line.release());
return std::move(mapnik::new_geometry::geometry(std::move(line)));
}
else
{
@ -118,9 +117,9 @@ void shape_io::read_polyline( shape_file::record_type & record, mapnik::geometry
}
int start, end;
mapnik::new_geometry::multi_line_string multi_line;
for (int k = 0; k < num_parts; ++k)
{
std::unique_ptr<geometry_type> line(new geometry_type(mapnik::geometry_type::types::LineString));
start = parts[k];
if (k == num_parts - 1)
{
@ -131,18 +130,16 @@ void shape_io::read_polyline( shape_file::record_type & record, mapnik::geometry
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int j = start + 1; j < end; ++j)
mapnik::new_geometry::line_string line;
for (int j = start; j < end; ++j)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
double x = record.read_double();
double y = record.read_double();
line.add_coord(x, y);
}
geom.push_back(line.release());
multi_line.push_back(std::move(line));
}
return std::move(mapnik::new_geometry::geometry(std::move(multi_line)));
}
}
@ -160,8 +157,11 @@ bool is_clockwise(T const& points, int start, int end)
return ( area < 0.0) ? true : false;
}
void shape_io::read_polygon(shape_file::record_type & record, mapnik::geometry_container & geom)
mapnik::new_geometry::geometry shape_io::read_polygon(shape_file::record_type & record)
{
// FIXME
return std::move(mapnik::new_geometry::geometry(mapnik::new_geometry::polygon3()));
#if 0
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
std::vector<int> parts(num_parts);
@ -182,7 +182,8 @@ void shape_io::read_polygon(shape_file::record_type & record, mapnik::geometry_c
points.emplace_back(x,y);
}
std::unique_ptr<geometry_type> poly(new geometry_type(mapnik::geometry_type::types::Polygon));
//std::unique_ptr<geometry_type> poly(new geometry_type(mapnik::geometry_type::types::Polygon));
mapnik::new_geometry::polygon3 poly;
for (int k = 0; k < num_parts; ++k)
{
int start = parts[k];
@ -208,4 +209,5 @@ void shape_io::read_polygon(shape_file::record_type & record, mapnik::geometry_c
poly->close_path();
}
geom.push_back(poly.release());
#endif
}

View file

@ -77,8 +77,8 @@ public:
void move_to(std::streampos pos);
static void read_bbox(shape_file::record_type & record, mapnik::box2d<double> & bbox);
static void read_polyline(shape_file::record_type & record,mapnik::geometry_container & geom);
static void read_polygon(shape_file::record_type & record,mapnik::geometry_container & geom);
static mapnik::new_geometry::geometry read_polyline(shape_file::record_type & record);
static mapnik::new_geometry::geometry read_polygon(shape_file::record_type & record);
shapeType type_;
shape_file shp_;

View file

@ -209,6 +209,14 @@ void agg_renderer<T0,T1>::process(line_symbolizer const& sym,
converter.set<dash_tag>();
converter.set<stroke_tag>(); //always stroke
// FIXME
mapnik::new_geometry::geometry const& geometry = feature.get_geometry();
if (geometry.is<mapnik::new_geometry::line_string>())
{
mapnik::new_geometry::line_string const& line = mapnik::util::get<mapnik::new_geometry::line_string>(geometry);
mapnik::new_geometry::line_string_vertex_adapter va(line);
converter.apply(va);
}
/*
for (geometry_type const& geom : feature.paths())
{