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
|
|
|
*
|
2011-10-23 15:04:25 +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/debug.hpp>
|
2009-07-03 15:29:50 +02:00
|
|
|
#include <mapnik/global.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/wkb.hpp>
|
2012-07-25 18:31:57 +02:00
|
|
|
#include <mapnik/coord_array.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/geom_util.hpp>
|
2007-09-16 13:23:51 +02:00
|
|
|
#include <mapnik/feature.hpp>
|
2012-12-17 03:19:52 +01:00
|
|
|
#include <mapnik/noncopyable.hpp>
|
2009-07-03 15:29:50 +02:00
|
|
|
|
2009-06-29 16:15:31 +02:00
|
|
|
// boost
|
2011-10-19 13:25:42 +02:00
|
|
|
#include <boost/format.hpp>
|
2009-06-08 09:08:30 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2012-07-25 18:31:57 +02:00
|
|
|
|
|
|
|
typedef coord_array<coord2d> CoordinateArray;
|
|
|
|
|
2012-12-17 03:19:52 +01:00
|
|
|
struct wkb_reader : mapnik::noncopyable
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
enum wkbByteOrder {
|
|
|
|
wkbXDR=0,
|
|
|
|
wkbNDR=1
|
|
|
|
};
|
2011-10-18 22:19:03 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
const char* wkb_;
|
|
|
|
unsigned size_;
|
|
|
|
unsigned pos_;
|
|
|
|
wkbByteOrder byteOrder_;
|
|
|
|
bool needSwap_;
|
|
|
|
wkbFormat format_;
|
2009-02-09 20:43:57 +01:00
|
|
|
|
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,
|
2011-10-19 13:25:42 +02:00
|
|
|
wkbGeometryCollection=7,
|
|
|
|
wkbPointZ=1001,
|
|
|
|
wkbLineStringZ=1002,
|
|
|
|
wkbPolygonZ=1003,
|
|
|
|
wkbMultiPointZ=1004,
|
|
|
|
wkbMultiLineStringZ=1005,
|
|
|
|
wkbMultiPolygonZ=1006,
|
|
|
|
wkbGeometryCollectionZ=1007
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
2011-10-19 13:25:42 +02:00
|
|
|
|
2011-10-23 02:25:09 +02:00
|
|
|
wkb_reader(const char* wkb, unsigned size, wkbFormat format)
|
2010-06-02 13:03:30 +02:00
|
|
|
: wkb_(wkb),
|
|
|
|
size_(size),
|
|
|
|
pos_(0),
|
|
|
|
format_(format)
|
|
|
|
{
|
2011-10-18 22:19:03 +02:00
|
|
|
// try to determine WKB format automatically
|
|
|
|
if (format_ == wkbAuto)
|
|
|
|
{
|
2012-07-19 17:24:29 +02:00
|
|
|
if (size_ >= 44
|
2011-10-23 02:25:09 +02:00
|
|
|
&& (unsigned char)(wkb_[0]) == (unsigned char)(0x00)
|
|
|
|
&& (unsigned char)(wkb_[38]) == (unsigned char)(0x7C))
|
|
|
|
{
|
|
|
|
format_ = wkbSpatiaLite;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format_ = wkbGeneric;
|
|
|
|
}
|
2011-10-18 22:19:03 +02:00
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
switch (format_)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbSpatiaLite:
|
|
|
|
byteOrder_ = (wkbByteOrder) wkb_[1];
|
|
|
|
pos_ = 39;
|
|
|
|
break;
|
2009-02-10 20:09:16 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbGeneric:
|
|
|
|
default:
|
|
|
|
byteOrder_ = (wkbByteOrder) wkb_[0];
|
|
|
|
pos_ = 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-09 20:43:57 +01:00
|
|
|
|
2010-03-08 12:55:15 +01:00
|
|
|
#ifndef MAPNIK_BIG_ENDIAN
|
2011-10-19 13:25:42 +02:00
|
|
|
needSwap_ = byteOrder_ ? wkbXDR : wkbNDR;
|
2010-03-08 12:55:15 +01:00
|
|
|
#else
|
2011-10-19 13:25:42 +02:00
|
|
|
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
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
int type = read_integer();
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
switch (type)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbPoint:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_point(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
|
|
|
case wkbLineString:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_linestring(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
|
|
|
case wkbPolygon:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_polygon(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
|
|
|
case wkbMultiPoint:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_multipoint(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
|
|
|
case wkbMultiLineString:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_multilinestring(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
|
|
|
case wkbMultiPolygon:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_multipolygon(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
|
|
|
case wkbGeometryCollection:
|
2011-09-13 13:54:04 +02:00
|
|
|
read_collection(paths);
|
2010-06-02 13:03:30 +02:00
|
|
|
break;
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbPointZ:
|
|
|
|
read_point_xyz(paths);
|
|
|
|
break;
|
|
|
|
case wkbLineStringZ:
|
|
|
|
read_linestring_xyz(paths);
|
|
|
|
break;
|
|
|
|
case wkbPolygonZ:
|
|
|
|
read_polygon_xyz(paths);
|
|
|
|
break;
|
|
|
|
case wkbMultiPointZ:
|
|
|
|
read_multipoint_xyz(paths);
|
|
|
|
break;
|
|
|
|
case wkbMultiLineStringZ:
|
|
|
|
read_multilinestring_xyz(paths);
|
|
|
|
break;
|
|
|
|
case wkbMultiPolygonZ:
|
|
|
|
read_multipolygon_xyz(paths);
|
|
|
|
break;
|
|
|
|
case wkbGeometryCollectionZ:
|
|
|
|
read_collection(paths);
|
|
|
|
break;
|
2010-06-02 13:03:30 +02:00
|
|
|
default:
|
|
|
|
break;
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
boost::int32_t n;
|
|
|
|
if (needSwap_)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
read_int32_xdr(wkb_ + pos_, n);
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
|
|
|
else
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
read_int32_ndr(wkb_ + pos_, n);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2011-10-19 13:25:42 +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);
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
else
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
read_double_ndr(wkb_ + pos_, d);
|
|
|
|
}
|
2011-10-19 13:25:42 +02:00
|
|
|
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)
|
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
if (! needSwap_)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +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
|
|
|
|
}
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
else
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
for (unsigned i=0;i<ar.size();++i)
|
2006-10-04 13:22:18 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
read_double_xdr(wkb_ + pos_, ar[i].x);
|
|
|
|
read_double_xdr(wkb_ + pos_ + 8, ar[i].y);
|
|
|
|
pos_ += 16; // skip XY
|
2006-10-04 13:22:18 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-19 13:25:42 +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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 13:54:04 +02:00
|
|
|
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();
|
2012-07-21 00:28:10 +02:00
|
|
|
std::auto_ptr<geometry_type> pt(new geometry_type(Point));
|
2011-10-19 13:25:42 +02:00
|
|
|
pt->move_to(x, y);
|
2011-09-13 13:54:04 +02:00
|
|
|
paths.push_back(pt);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-09-13 13:54:04 +02:00
|
|
|
void read_multipoint(boost::ptr_vector<geometry_type> & paths)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
int num_points = read_integer();
|
2011-10-19 13:25:42 +02:00
|
|
|
for (int i = 0; i < num_points; ++i)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 5;
|
2011-09-13 13:54:04 +02:00
|
|
|
read_point(paths);
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-10-19 13:25:42 +02:00
|
|
|
void read_point_xyz(boost::ptr_vector<geometry_type> & paths)
|
|
|
|
{
|
|
|
|
double x = read_double();
|
|
|
|
double y = read_double();
|
2012-07-21 00:28:10 +02:00
|
|
|
std::auto_ptr<geometry_type> pt(new geometry_type(Point));
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 8; // double z = read_double();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-13 13:54:04 +02:00
|
|
|
void read_linestring(boost::ptr_vector<geometry_type> & paths)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
int num_points = read_integer();
|
2012-07-21 00:28:10 +02:00
|
|
|
if (num_points > 0)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
CoordinateArray ar(num_points);
|
|
|
|
read_coords(ar);
|
|
|
|
std::auto_ptr<geometry_type> line(new geometry_type(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);
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-09-13 13:54:04 +02:00
|
|
|
void read_multilinestring(boost::ptr_vector<geometry_type> & paths)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
int num_lines = read_integer();
|
|
|
|
for (int i = 0; i < num_lines; ++i)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 5;
|
2011-09-13 13:54:04 +02:00
|
|
|
read_linestring(paths);
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-10-19 13:25:42 +02:00
|
|
|
void read_linestring_xyz(boost::ptr_vector<geometry_type> & paths)
|
|
|
|
{
|
|
|
|
int num_points = read_integer();
|
2012-07-21 00:28:10 +02:00
|
|
|
if (num_points > 0)
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
CoordinateArray ar(num_points);
|
|
|
|
read_coords_xyz(ar);
|
|
|
|
std::auto_ptr<geometry_type> line(new geometry_type(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);
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
int num_rings = read_integer();
|
2012-07-21 00:28:10 +02:00
|
|
|
if (num_rings > 0)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
std::auto_ptr<geometry_type> poly(new geometry_type(Polygon));
|
|
|
|
for (int i = 0; i < num_rings; ++i)
|
2006-10-04 13:22:18 +02:00
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
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);
|
2012-07-26 16:20:56 +02:00
|
|
|
for (int j = 1; j < num_points - 1; ++j)
|
2012-07-21 00:28:10 +02:00
|
|
|
{
|
|
|
|
poly->line_to(ar[j].x, ar[j].y);
|
|
|
|
}
|
2012-12-18 12:44:35 +01:00
|
|
|
|
|
|
|
if (ar[0].x == ar[num_points-1].x &&
|
|
|
|
ar[0].y == ar[num_points-1].y)
|
|
|
|
{
|
|
|
|
poly->close(ar[num_points-1].x, ar[num_points-1].y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// leave un-closed polygon intact - don't attempt to close them
|
|
|
|
poly->line_to(ar[num_points-1].x, ar[num_points-1].y);
|
|
|
|
}
|
|
|
|
poly->set_close();
|
2012-07-21 00:28:10 +02:00
|
|
|
}
|
2006-10-04 13:22:18 +02:00
|
|
|
}
|
2012-07-21 00:28:10 +02:00
|
|
|
if (poly->size() > 2) // ignore if polygon has less than 3 vertices
|
|
|
|
paths.push_back(poly);
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-09-13 13:54:04 +02:00
|
|
|
void read_multipolygon(boost::ptr_vector<geometry_type> & paths)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
int num_polys = read_integer();
|
|
|
|
for (int i = 0; i < num_polys; ++i)
|
2009-07-03 15:29:50 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 5;
|
2011-09-13 13:54:04 +02:00
|
|
|
read_polygon(paths);
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-10-19 13:25:42 +02:00
|
|
|
void read_polygon_xyz(boost::ptr_vector<geometry_type> & paths)
|
|
|
|
{
|
|
|
|
int num_rings = read_integer();
|
2012-07-21 00:28:10 +02:00
|
|
|
if (num_rings > 0)
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
std::auto_ptr<geometry_type> poly(new geometry_type(Polygon));
|
|
|
|
for (int i = 0; i < num_rings; ++i)
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
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);
|
2012-07-26 16:20:56 +02:00
|
|
|
for (int j = 1; j < num_points - 1; ++j)
|
2012-07-21 00:28:10 +02:00
|
|
|
{
|
|
|
|
poly->line_to(ar[j].x, ar[j].y);
|
|
|
|
}
|
2012-12-18 12:44:35 +01:00
|
|
|
if (ar[0].x == ar[num_points-1].x &&
|
|
|
|
ar[0].y == ar[num_points-1].y)
|
|
|
|
{
|
|
|
|
poly->close(ar[num_points-1].x, ar[num_points-1].y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// leave un-closed polygon intact- don't attempt to close them
|
|
|
|
poly->line_to(ar[num_points-1].x, ar[num_points-1].y);
|
|
|
|
}
|
2012-07-21 00:28:10 +02:00
|
|
|
}
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
2012-07-21 00:28:10 +02:00
|
|
|
if (poly->size() > 2) // ignore if polygon has less than 3 vertices
|
|
|
|
paths.push_back(poly);
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-13 13:54:04 +02:00
|
|
|
void read_collection(boost::ptr_vector<geometry_type> & paths)
|
2010-11-18 22:52:20 +01:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
int num_geometries = read_integer();
|
|
|
|
for (int i = 0; i < num_geometries; ++i)
|
2010-11-18 22:52:20 +01:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 1; // skip byte order
|
2011-09-13 13:54:04 +02:00
|
|
|
read(paths);
|
2010-11-18 22:52:20 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-10-19 13:25:42 +02:00
|
|
|
std::string wkb_geometry_type_string(int type)
|
|
|
|
{
|
|
|
|
std::stringstream s;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2012-07-21 00:28:10 +02:00
|
|
|
case wkbPoint: s << "Point"; break;
|
|
|
|
case wkbLineString: s << "LineString"; break;
|
|
|
|
case wkbPolygon: s << "Polygon"; break;
|
|
|
|
case wkbMultiPoint: s << "MultiPoint"; break;
|
|
|
|
case wkbMultiLineString: s << "MultiLineString"; break;
|
|
|
|
case wkbMultiPolygon: s << "MultiPolygon"; break;
|
|
|
|
case wkbGeometryCollection: s << "GeometryCollection"; break;
|
|
|
|
case wkbPointZ: s << "PointZ"; break;
|
|
|
|
case wkbLineStringZ: s << "LineStringZ"; break;
|
|
|
|
case wkbPolygonZ: s << "PolygonZ"; break;
|
|
|
|
case wkbMultiPointZ: s << "MultiPointZ"; break;
|
|
|
|
case wkbMultiLineStringZ: s << "MultiLineStringZ"; break;
|
|
|
|
case wkbMultiPolygonZ: s << "MultiPolygonZ"; break;
|
|
|
|
case wkbGeometryCollectionZ: s << "GeometryCollectionZ"; break;
|
|
|
|
default: s << "wkbUknown(" << type << ")"; break;
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return s.str();
|
|
|
|
}
|
2012-07-21 00:28:10 +02:00
|
|
|
|
2010-11-18 22:52:20 +01:00
|
|
|
};
|
|
|
|
|
2012-07-21 00:09:01 +02: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
|
|
|
{
|
2012-07-21 00:09:01 +02:00
|
|
|
unsigned geom_count = paths.size();
|
2011-10-19 13:25:42 +02:00
|
|
|
wkb_reader reader(wkb, size, format);
|
2012-07-21 00:09:01 +02:00
|
|
|
reader.read(paths);
|
|
|
|
if (paths.size() > geom_count)
|
|
|
|
return true;
|
|
|
|
return false;
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
2011-12-06 13:53:16 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|