mapnik/src/wkb.cpp

628 lines
18 KiB
C++
Raw Normal View History

2006-03-31 12:32:02 +02:00
/*****************************************************************************
2012-02-02 02:53:35 +01:00
*
2006-03-31 12:32:02 +02:00
* This file is part of Mapnik (c++ mapping toolkit)
2005-06-14 17:06:59 +02:00
*
* Copyright (C) 2011 Artem Pavlenko
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
2005-06-14 17:06:59 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2006-03-31 12:32:02 +02:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
*****************************************************************************/
2005-06-14 17:06:59 +02:00
2012-04-08 02:20:56 +02:00
// mapnik
#include <mapnik/make_unique.hpp>
2012-04-08 02:20:56 +02:00
#include <mapnik/debug.hpp>
#include <mapnik/global.hpp>
#include <mapnik/wkb.hpp>
2012-07-25 18:31:57 +02:00
#include <mapnik/coord_array.hpp>
#include <mapnik/geom_util.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/noncopyable.hpp>
2009-06-29 16:15:31 +02:00
// boost
#include <boost/format.hpp>
2005-06-14 17:06:59 +02:00
namespace mapnik
{
2012-07-25 18:31:57 +02:00
typedef coord_array<coord2d> CoordinateArray;
struct wkb_reader : mapnik::noncopyable
2010-06-02 13:03:30 +02:00
{
private:
enum wkbByteOrder {
wkbXDR=0,
wkbNDR=1
};
2010-06-02 13:03:30 +02:00
const char* wkb_;
2013-09-19 05:31:59 +02:00
std::size_t size_;
std::size_t pos_;
2010-06-02 13:03:30 +02:00
wkbByteOrder byteOrder_;
bool needSwap_;
wkbFormat format_;
2010-06-02 13:03:30 +02:00
public:
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
enum wkbGeometryType {
wkbPoint=1,
wkbLineString=2,
wkbPolygon=3,
wkbMultiPoint=4,
wkbMultiLineString=5,
wkbMultiPolygon=6,
wkbGeometryCollection=7,
// Z
wkbPointZ=1001,
wkbLineStringZ=1002,
wkbPolygonZ=1003,
wkbMultiPointZ=1004,
wkbMultiLineStringZ=1005,
wkbMultiPolygonZ=1006,
wkbGeometryCollectionZ=1007,
// M
wkbPointM=2001,
wkbLineStringM=2002,
wkbPolygonM=2003,
wkbMultiPointM=2004,
wkbMultiLineStringM=2005,
wkbMultiPolygonM=2006,
wkbGeometryCollectionM=2007,
// ZM
wkbPointZM=3001,
wkbLineStringZM=3002,
wkbPolygonZM=3003,
wkbMultiPointZM=3004,
wkbMultiLineStringZM=3005,
wkbMultiPolygonZM=3006,
wkbGeometryCollectionZM=3007
};
2013-09-19 05:35:14 +02:00
wkb_reader(const char* wkb, std::size_t size, wkbFormat format)
2010-06-02 13:03:30 +02:00
: wkb_(wkb),
size_(size),
pos_(0),
format_(format)
{
// try to determine WKB format automatically
if (format_ == wkbAuto)
{
2012-07-19 17:24:29 +02:00
if (size_ >= 44
2013-09-19 05:35:14 +02:00
&& static_cast<unsigned char>(wkb_[0]) == static_cast<unsigned char>(0x00)
&& static_cast<unsigned char>(wkb_[38]) == static_cast<unsigned char>(0x7C)
&& static_cast<unsigned char>(wkb_[size_ - 1]) == static_cast<unsigned char>(0xFE))
2011-10-23 02:25:09 +02:00
{
format_ = wkbSpatiaLite;
}
else
{
format_ = wkbGeneric;
}
}
2010-06-02 13:03:30 +02:00
switch (format_)
{
2010-06-02 13:03:30 +02:00
case wkbSpatiaLite:
byteOrder_ = (wkbByteOrder) wkb_[1];
pos_ = 39;
break;
2010-06-02 13:03:30 +02:00
case wkbGeneric:
default:
byteOrder_ = (wkbByteOrder) wkb_[0];
pos_ = 1;
break;
}
#ifndef MAPNIK_BIG_ENDIAN
needSwap_ = byteOrder_ ? wkbXDR : wkbNDR;
#else
needSwap_ = byteOrder_ ? wkbNDR : wkbXDR;
2012-02-02 02:53:35 +01:00
#endif
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
int type = read_integer();
2010-06-02 13:03:30 +02:00
switch (type)
{
2010-06-02 13:03:30 +02:00
case wkbPoint:
read_point(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbLineString:
read_linestring(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbPolygon:
read_polygon(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbMultiPoint:
read_multipoint(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbMultiLineString:
read_multilinestring(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbMultiPolygon:
read_multipolygon(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbGeometryCollection:
read_collection(paths);
2010-06-02 13:03:30 +02:00
break;
case wkbPointZ:
case wkbPointM:
read_point_xyz(paths);
break;
case wkbPointZM:
read_point_xyzm(paths);
break;
case wkbLineStringZ:
case wkbLineStringM:
read_linestring_xyz(paths);
break;
case wkbLineStringZM:
read_linestring_xyzm(paths);
break;
case wkbPolygonZ:
case wkbPolygonM:
read_polygon_xyz(paths);
break;
case wkbPolygonZM:
read_polygon_xyzm(paths);
break;
case wkbMultiPointZ:
case wkbMultiPointM:
read_multipoint_xyz(paths);
break;
case wkbMultiPointZM:
read_multipoint_xyzm(paths);
break;
case wkbMultiLineStringZ:
case wkbMultiLineStringM:
read_multilinestring_xyz(paths);
break;
case wkbMultiLineStringZM:
read_multilinestring_xyzm(paths);
break;
case wkbMultiPolygonZ:
case wkbMultiPolygonM:
read_multipolygon_xyz(paths);
break;
case wkbMultiPolygonZM:
read_multipolygon_xyzm(paths);
break;
case wkbGeometryCollectionZ:
case wkbGeometryCollectionM:
case wkbGeometryCollectionZM:
read_collection(paths);
break;
2010-06-02 13:03:30 +02:00
default:
break;
}
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
private:
2012-02-02 02:53:35 +01:00
int read_integer()
2010-06-02 13:03:30 +02:00
{
2014-05-06 19:06:47 +02:00
std::int32_t n;
2010-06-02 13:03:30 +02:00
if (needSwap_)
{
read_int32_xdr(wkb_ + pos_, n);
2012-02-02 02:53:35 +01:00
}
else
2010-06-02 13:03:30 +02:00
{
read_int32_ndr(wkb_ + pos_, n);
2010-06-02 13:03:30 +02:00
}
pos_ += 4;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
return n;
}
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
double read_double()
{
double d;
if (needSwap_)
{
read_double_xdr(wkb_ + pos_, d);
}
2012-02-02 02:53:35 +01:00
else
{
2010-06-02 13:03:30 +02:00
read_double_ndr(wkb_ + pos_, d);
}
pos_ += 8;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
return d;
}
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
void read_coords(CoordinateArray& ar)
{
if (! needSwap_)
2010-06-02 13:03:30 +02:00
{
for (unsigned i = 0; i < ar.size(); ++i)
{
read_double_ndr(wkb_ + pos_, ar[i].x);
read_double_ndr(wkb_ + pos_ + 8, ar[i].y);
pos_ += 16; // skip XY
}
}
2012-02-02 02:53:35 +01:00
else
{
2010-06-02 13:03:30 +02:00
for (unsigned i=0;i<ar.size();++i)
{
read_double_xdr(wkb_ + pos_, ar[i].x);
read_double_xdr(wkb_ + pos_ + 8, ar[i].y);
pos_ += 16; // skip XY
}
2010-06-02 13:03:30 +02:00
}
}
void read_coords_xyz(CoordinateArray& ar)
{
if (! needSwap_)
{
for (unsigned i = 0; i < ar.size(); ++i)
{
read_double_ndr(wkb_ + pos_, ar[i].x);
read_double_ndr(wkb_ + pos_ + 8, ar[i].y);
pos_ += 24; // skip XYZ
}
}
else
{
for (unsigned i = 0; i < ar.size(); ++i)
{
read_double_xdr(wkb_ + pos_, ar[i].x);
read_double_xdr(wkb_ + pos_ + 8, ar[i].y);
pos_ += 24; // skip XYZ
}
}
}
void read_coords_xyzm(CoordinateArray& ar)
{
if (! needSwap_)
{
for (unsigned i = 0; i < ar.size(); ++i)
{
read_double_ndr(wkb_ + pos_, ar[i].x);
read_double_ndr(wkb_ + pos_ + 8, ar[i].y);
pos_ += 32; // skip XYZM
}
}
else
{
for (unsigned i = 0; i < ar.size(); ++i)
{
read_double_xdr(wkb_ + pos_, ar[i].x);
read_double_xdr(wkb_ + pos_ + 8, ar[i].y);
pos_ += 32; // skip XYZM
}
}
}
void read_point(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
double x = read_double();
double y = read_double();
2014-03-11 05:34:48 +01:00
auto pt = std::make_unique<geometry_type>(geometry_type::types::Point);
pt->move_to(x, y);
paths.push_back(pt.release());
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read_multipoint(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
int num_points = read_integer();
for (int i = 0; i < num_points; ++i)
2010-06-02 13:03:30 +02:00
{
pos_ += 5;
read_point(paths);
}
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read_point_xyz(boost::ptr_vector<geometry_type> & paths)
{
double x = read_double();
double y = read_double();
2014-03-11 05:34:48 +01:00
auto pt = std::make_unique<geometry_type>(geometry_type::types::Point);
pos_ += 8; // double z = read_double();
pt->move_to(x, y);
paths.push_back(pt.release());
}
void read_point_xyzm(boost::ptr_vector<geometry_type> & paths)
{
double x = read_double();
double y = read_double();
Merge branch '2.3.x' of github.com:mapnik/mapnik Conflicts: .travis.yml CHANGELOG.md bindings/python/build.py include/mapnik/feature_style_processor_context.hpp include/mapnik/feature_style_processor_impl.hpp include/mapnik/json/feature_collection_grammar.hpp include/mapnik/json/feature_collection_parser.hpp include/mapnik/json/feature_generator_grammar.hpp include/mapnik/json/feature_parser.hpp include/mapnik/json/geojson_generator.hpp include/mapnik/json/geometry_generator_grammar.hpp include/mapnik/json/geometry_parser.hpp plugins/input/gdal/gdal_featureset.cpp plugins/input/geojson/geojson_datasource.cpp plugins/input/occi/occi_featureset.cpp plugins/input/osm/osm_featureset.cpp plugins/input/postgis/build.py plugins/input/postgis/connection.hpp src/agg/agg_renderer.cpp src/build.py src/cairo_context.cpp src/datasource_cache.cpp src/grid/process_line_symbolizer.cpp src/grid/process_polygon_pattern_symbolizer.cpp src/grid/process_polygon_symbolizer.cpp src/grid/process_text_symbolizer.cpp src/json/feature_grammar.cpp tests/cpp_tests/fontset_runtime_test.cpp tests/visual_tests/images/collision-600-400-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-2.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-2.0-agg-reference.png tests/visual_tests/images/lines-1-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-2-400-400-1.0-cairo-reference.png tests/visual_tests/images/lines-2-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-2-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-3-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-6-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-cairo-reference.png tests/visual_tests/images/shield-on-polygon-600-400-1.0-agg-reference.png tests/visual_tests/images/shield-on-polygon-600-400-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-510-100-2.0-agg-reference.png tests/visual_tests/test.py
2014-04-24 23:50:55 +02:00
std::auto_ptr<geometry_type> pt(new geometry_type(geometry_type::types::Point));
pos_ += 16;
pt->move_to(x, y);
paths.push_back(pt);
}
void read_multipoint_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_points = read_integer();
for (int i = 0; i < num_points; ++i)
{
pos_ += 5;
read_point_xyz(paths);
}
}
void read_multipoint_xyzm(boost::ptr_vector<geometry_type> & paths)
{
int num_points = read_integer();
for (int i = 0; i < num_points; ++i)
{
pos_ += 5;
read_point_xyzm(paths);
}
}
void read_linestring(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords(ar);
2014-03-11 05:34:48 +01:00
auto line = std::make_unique<geometry_type>(geometry_type::types::LineString);
line->move_to(ar[0].x, ar[0].y);
for (int i = 1; i < num_points; ++i)
{
line->line_to(ar[i].x, ar[i].y);
}
paths.push_back(line.release());
}
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read_multilinestring(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
int num_lines = read_integer();
for (int i = 0; i < num_lines; ++i)
{
pos_ += 5;
read_linestring(paths);
}
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read_linestring_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords_xyz(ar);
2014-03-11 05:34:48 +01:00
auto line = std::make_unique<geometry_type>(geometry_type::types::LineString);
line->move_to(ar[0].x, ar[0].y);
for (int i = 1; i < num_points; ++i)
{
line->line_to(ar[i].x, ar[i].y);
}
paths.push_back(line.release());
}
}
void read_linestring_xyzm(boost::ptr_vector<geometry_type> & paths)
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords_xyzm(ar);
Merge branch '2.3.x' of github.com:mapnik/mapnik Conflicts: .travis.yml CHANGELOG.md bindings/python/build.py include/mapnik/feature_style_processor_context.hpp include/mapnik/feature_style_processor_impl.hpp include/mapnik/json/feature_collection_grammar.hpp include/mapnik/json/feature_collection_parser.hpp include/mapnik/json/feature_generator_grammar.hpp include/mapnik/json/feature_parser.hpp include/mapnik/json/geojson_generator.hpp include/mapnik/json/geometry_generator_grammar.hpp include/mapnik/json/geometry_parser.hpp plugins/input/gdal/gdal_featureset.cpp plugins/input/geojson/geojson_datasource.cpp plugins/input/occi/occi_featureset.cpp plugins/input/osm/osm_featureset.cpp plugins/input/postgis/build.py plugins/input/postgis/connection.hpp src/agg/agg_renderer.cpp src/build.py src/cairo_context.cpp src/datasource_cache.cpp src/grid/process_line_symbolizer.cpp src/grid/process_polygon_pattern_symbolizer.cpp src/grid/process_polygon_symbolizer.cpp src/grid/process_text_symbolizer.cpp src/json/feature_grammar.cpp tests/cpp_tests/fontset_runtime_test.cpp tests/visual_tests/images/collision-600-400-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-2.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-2.0-agg-reference.png tests/visual_tests/images/lines-1-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-2-400-400-1.0-cairo-reference.png tests/visual_tests/images/lines-2-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-2-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-3-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-6-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-cairo-reference.png tests/visual_tests/images/shield-on-polygon-600-400-1.0-agg-reference.png tests/visual_tests/images/shield-on-polygon-600-400-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-510-100-2.0-agg-reference.png tests/visual_tests/test.py
2014-04-24 23:50:55 +02:00
std::auto_ptr<geometry_type> line(new geometry_type(geometry_type::types::LineString));
line->move_to(ar[0].x, ar[0].y);
for (int i = 1; i < num_points; ++i)
{
line->line_to(ar[i].x, ar[i].y);
}
paths.push_back(line);
}
}
void read_multilinestring_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_lines = read_integer();
for (int i = 0; i < num_lines; ++i)
{
pos_ += 5;
read_linestring_xyz(paths);
}
}
void read_multilinestring_xyzm(boost::ptr_vector<geometry_type> & paths)
{
int num_lines = read_integer();
for (int i = 0; i < num_lines; ++i)
{
pos_ += 5;
read_linestring_xyzm(paths);
}
}
2012-02-02 02:53:35 +01:00
void read_polygon(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
int num_rings = read_integer();
if (num_rings > 0)
{
2014-03-11 05:34:48 +01:00
auto poly = std::make_unique<geometry_type>(geometry_type::types::Polygon);
for (int i = 0; i < num_rings; ++i)
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords(ar);
poly->move_to(ar[0].x, ar[0].y);
2013-03-01 17:06:44 +01:00
for (int j = 1; j < num_points ; ++j)
{
poly->line_to(ar[j].x, ar[j].y);
}
2013-03-01 17:06:44 +01:00
poly->close_path();
}
}
2013-03-01 17:06:44 +01:00
if (poly->size() > 3) // ignore if polygon has less than (3 + close_path) vertices
paths.push_back(poly.release());
}
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read_multipolygon(boost::ptr_vector<geometry_type> & paths)
2010-06-02 13:03:30 +02:00
{
int num_polys = read_integer();
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
read_polygon(paths);
}
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
void read_polygon_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_rings = read_integer();
if (num_rings > 0)
{
2014-03-11 05:34:48 +01:00
auto poly = std::make_unique<geometry_type>(geometry_type::types::Polygon);
for (int i = 0; i < num_rings; ++i)
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords_xyz(ar);
poly->move_to(ar[0].x, ar[0].y);
2013-03-01 17:06:44 +01:00
for (int j = 1; j < num_points; ++j)
{
poly->line_to(ar[j].x, ar[j].y);
}
2013-03-01 17:06:44 +01:00
poly->close_path();
}
}
if (poly->size() > 2) // ignore if polygon has less than 3 vertices
paths.push_back(poly.release());
}
}
void read_polygon_xyzm(boost::ptr_vector<geometry_type> & paths)
{
int num_rings = read_integer();
if (num_rings > 0)
{
Merge branch '2.3.x' of github.com:mapnik/mapnik Conflicts: .travis.yml CHANGELOG.md bindings/python/build.py include/mapnik/feature_style_processor_context.hpp include/mapnik/feature_style_processor_impl.hpp include/mapnik/json/feature_collection_grammar.hpp include/mapnik/json/feature_collection_parser.hpp include/mapnik/json/feature_generator_grammar.hpp include/mapnik/json/feature_parser.hpp include/mapnik/json/geojson_generator.hpp include/mapnik/json/geometry_generator_grammar.hpp include/mapnik/json/geometry_parser.hpp plugins/input/gdal/gdal_featureset.cpp plugins/input/geojson/geojson_datasource.cpp plugins/input/occi/occi_featureset.cpp plugins/input/osm/osm_featureset.cpp plugins/input/postgis/build.py plugins/input/postgis/connection.hpp src/agg/agg_renderer.cpp src/build.py src/cairo_context.cpp src/datasource_cache.cpp src/grid/process_line_symbolizer.cpp src/grid/process_polygon_pattern_symbolizer.cpp src/grid/process_polygon_symbolizer.cpp src/grid/process_text_symbolizer.cpp src/json/feature_grammar.cpp tests/cpp_tests/fontset_runtime_test.cpp tests/visual_tests/images/collision-600-400-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-2.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-2.0-agg-reference.png tests/visual_tests/images/lines-1-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-2-400-400-1.0-cairo-reference.png tests/visual_tests/images/lines-2-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-2-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-3-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-6-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-cairo-reference.png tests/visual_tests/images/shield-on-polygon-600-400-1.0-agg-reference.png tests/visual_tests/images/shield-on-polygon-600-400-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-510-100-2.0-agg-reference.png tests/visual_tests/test.py
2014-04-24 23:50:55 +02:00
std::auto_ptr<geometry_type> poly(new geometry_type(geometry_type::types::Polygon));
for (int i = 0; i < num_rings; ++i)
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords_xyzm(ar);
poly->move_to(ar[0].x, ar[0].y);
for (int j = 1; j < num_points; ++j)
{
poly->line_to(ar[j].x, ar[j].y);
}
poly->close_path();
}
}
if (poly->size() > 2) // ignore if polygon has less than 3 vertices
paths.push_back(poly);
}
}
void read_multipolygon_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_polys = read_integer();
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
read_polygon_xyz(paths);
}
}
void read_multipolygon_xyzm(boost::ptr_vector<geometry_type> & paths)
{
int num_polys = read_integer();
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
read_polygon_xyzm(paths);
}
}
void read_collection(boost::ptr_vector<geometry_type> & paths)
2010-11-18 22:52:20 +01:00
{
int num_geometries = read_integer();
for (int i = 0; i < num_geometries; ++i)
2010-11-18 22:52:20 +01:00
{
pos_ += 1; // skip byte order
read(paths);
2010-11-18 22:52:20 +01:00
}
}
2012-02-02 02:53:35 +01:00
std::string wkb_geometry_type_string(int type)
{
std::stringstream s;
switch (type)
{
case wkbPoint: s << "Point"; break;
case wkbPointZ: s << "PointZ"; break;
case wkbPointM: s << "PointM"; break;
case wkbPointZM: s << "PointZM"; break;
case wkbMultiPoint: s << "MultiPoint"; break;
case wkbMultiPointZ: s << "MultiPointZ"; break;
case wkbMultiPointM: s << "MultiPointM"; break;
case wkbMultiPointZM: s << "MultiPointZM"; break;
case wkbLineString: s << "LineString"; break;
case wkbLineStringZ: s << "LineStringZ"; break;
case wkbLineStringM: s << "LineStringM"; break;
case wkbLineStringZM: s << "LineStringZM"; break;
case wkbMultiLineString: s << "MultiLineString"; break;
case wkbMultiLineStringZ: s << "MultiLineStringZ"; break;
case wkbMultiLineStringM: s << "MultiLineStringM"; break;
case wkbMultiLineStringZM: s << "MultiLineStringZM"; break;
case wkbPolygon: s << "Polygon"; break;
case wkbPolygonZ: s << "PolygonZ"; break;
case wkbPolygonM: s << "PolygonM"; break;
case wkbPolygonZM: s << "PolygonZM"; break;
case wkbMultiPolygon: s << "MultiPolygon"; break;
case wkbMultiPolygonZ: s << "MultiPolygonZ"; break;
case wkbMultiPolygonM: s << "MultiPolygonM"; break;
case wkbMultiPolygonZM: s << "MultiPolygonZM"; break;
case wkbGeometryCollection: s << "GeometryCollection"; break;
case wkbGeometryCollectionZ: s << "GeometryCollectionZ"; break;
case wkbGeometryCollectionM: s << "GeometryCollectionM"; break;
case wkbGeometryCollectionZM: s << "GeometryCollectionZM"; break;
2013-04-17 23:23:04 +02:00
default: s << "wkbUnknown(" << type << ")"; break;
}
return s.str();
}
2010-11-18 22:52:20 +01:00
};
bool geometry_utils::from_wkb(boost::ptr_vector<geometry_type>& paths,
2010-06-02 13:03:30 +02:00
const char* wkb,
unsigned size,
2012-02-02 02:53:35 +01:00
wkbFormat format)
2010-06-02 13:03:30 +02:00
{
2013-09-19 05:31:59 +02:00
std::size_t geom_count = paths.size();
wkb_reader reader(wkb, size, format);
reader.read(paths);
if (paths.size() > geom_count)
return true;
return false;
2012-02-02 02:53:35 +01:00
}
2005-06-14 17:06:59 +02:00
}