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
|
|
|
*
|
2014-11-20 15:25:50 +01:00
|
|
|
* Copyright (C) 2014 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
|
2014-06-12 16:14:05 +02:00
|
|
|
#include <mapnik/make_unique.hpp>
|
2012-04-08 02:20:56 +02:00
|
|
|
#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>
|
2007-09-16 13:23:51 +02:00
|
|
|
#include <mapnik/feature.hpp>
|
2015-01-07 13:11:09 +01:00
|
|
|
#include <mapnik/util/noncopyable.hpp>
|
2015-03-04 12:09:08 +01:00
|
|
|
#include <mapnik/geometry_adapters.hpp>
|
|
|
|
// boost.geometry
|
|
|
|
#include <boost/geometry/algorithms/correct.hpp>
|
2009-07-03 15:29:50 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2012-07-25 18:31:57 +02:00
|
|
|
|
2015-01-07 13:11:09 +01:00
|
|
|
struct wkb_reader : util::noncopyable
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
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_;
|
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,
|
2014-04-10 01:40:14 +02:00
|
|
|
// Z
|
2011-10-19 13:25:42 +02:00
|
|
|
wkbPointZ=1001,
|
|
|
|
wkbLineStringZ=1002,
|
|
|
|
wkbPolygonZ=1003,
|
|
|
|
wkbMultiPointZ=1004,
|
|
|
|
wkbMultiLineStringZ=1005,
|
|
|
|
wkbMultiPolygonZ=1006,
|
2014-04-10 01:40:14 +02:00
|
|
|
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
|
2015-02-19 16:04:14 +01:00
|
|
|
};
|
2011-10-19 13:25:42 +02:00
|
|
|
|
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)
|
|
|
|
{
|
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
|
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;
|
|
|
|
}
|
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
|
|
|
|
2011-10-19 13:25:42 +02:00
|
|
|
needSwap_ = byteOrder_ ? wkbXDR : wkbNDR;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::geometry read()
|
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:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_point()));
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbLineString:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_linestring()));
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbPolygon:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_polygon()));
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbMultiPoint:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multipoint()));
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbMultiLineString:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multilinestring()));
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbMultiPolygon:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multipolygon()));
|
2010-06-02 13:03:30 +02:00
|
|
|
case wkbGeometryCollection:
|
2015-02-20 17:21:40 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_collection()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbPointZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbPointM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_point<true>()));
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbPointZM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_point<true,true>()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbLineStringZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbLineStringM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_linestring<true>()));
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbLineStringZM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_linestring<true,true>()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbPolygonZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbPolygonM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_polygon<true>()));
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbPolygonZM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_polygon<true,true>()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbMultiPointZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbMultiPointM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multipoint<true>()));
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbMultiPointZM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multipoint<true,true>()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbMultiLineStringZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbMultiLineStringM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multilinestring<true>()));
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbMultiLineStringZM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multilinestring<true,true>()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbMultiPolygonZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbMultiPolygonM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multipolygon<true>()));
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbMultiPolygonZM:
|
2015-02-19 16:04:14 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_multipolygon<true,true>()));
|
2011-10-19 13:25:42 +02:00
|
|
|
case wkbGeometryCollectionZ:
|
2014-04-10 01:40:14 +02:00
|
|
|
case wkbGeometryCollectionM:
|
|
|
|
case wkbGeometryCollectionZM:
|
2015-02-20 17:21:40 +01:00
|
|
|
return std::move(mapnik::new_geometry::geometry(read_collection()));
|
2010-06-02 13:03:30 +02:00
|
|
|
default:
|
|
|
|
break;
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2015-02-20 17:21:40 +01:00
|
|
|
throw std::runtime_error("Uknown WKB geometry type");
|
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_)
|
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
|
|
|
|
2015-02-19 17:13:43 +01:00
|
|
|
template <typename Ring, bool Z = false, bool M = false>
|
|
|
|
void read_coords(Ring & ring, std::size_t num_points)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2015-02-19 17:13:43 +01:00
|
|
|
double x,y;
|
|
|
|
if (!needSwap_)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2015-02-19 17:13:43 +01:00
|
|
|
for (std::size_t i = 0; i < num_points; ++i)
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2015-02-19 17:13:43 +01:00
|
|
|
read_double_ndr(wkb_ + pos_, x);
|
|
|
|
read_double_ndr(wkb_ + pos_ + 8, y);
|
|
|
|
ring.emplace_back(x,y);
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 16; // skip XY
|
2015-02-19 16:04:14 +01:00
|
|
|
if (Z) pos_ += 8;
|
|
|
|
if (M) pos_ += 8;
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
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
|
|
|
{
|
2015-02-19 17:13:43 +01:00
|
|
|
for (std::size_t i = 0; i < num_points; ++i)
|
2006-10-04 13:22:18 +02:00
|
|
|
{
|
2015-02-19 17:13:43 +01:00
|
|
|
read_double_xdr(wkb_ + pos_, x);
|
|
|
|
read_double_xdr(wkb_ + pos_ + 8, y);
|
|
|
|
ring.emplace_back(x,y);
|
2011-10-19 13:25:42 +02:00
|
|
|
pos_ += 16; // skip XY
|
2015-02-19 16:04:14 +01:00
|
|
|
if (Z) pos_ += 8;
|
|
|
|
if (M) pos_ += 8;
|
2006-10-04 13:22:18 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-19 13:25:42 +02:00
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
template <bool Z = false, bool M = false>
|
|
|
|
mapnik::new_geometry::point read_point()
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
double x = read_double();
|
|
|
|
double y = read_double();
|
2015-02-19 16:04:14 +01:00
|
|
|
if (Z) pos_ += 8;
|
|
|
|
if (M) pos_ += 8;
|
|
|
|
return mapnik::new_geometry::point(x, y);
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
template <bool Z = false, bool M = false>
|
|
|
|
mapnik::new_geometry::multi_point read_multipoint()
|
2014-04-10 01:40:14 +02:00
|
|
|
{
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::multi_point multi_point;
|
2014-04-10 01:40:14 +02:00
|
|
|
int num_points = read_integer();
|
2015-02-19 16:04:14 +01:00
|
|
|
multi_point.reserve(num_points);
|
2014-04-10 01:40:14 +02:00
|
|
|
for (int i = 0; i < num_points; ++i)
|
|
|
|
{
|
|
|
|
pos_ += 5;
|
2015-02-19 16:04:14 +01:00
|
|
|
multi_point.emplace_back(read_point<Z,M>());
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2015-02-19 16:04:14 +01:00
|
|
|
return multi_point;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
template <bool M = false, bool Z = false>
|
|
|
|
mapnik::new_geometry::line_string read_linestring()
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::line_string line;
|
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)
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2015-02-19 16:04:14 +01:00
|
|
|
line.reserve(num_points);
|
2015-02-19 17:13:43 +01:00
|
|
|
read_coords<mapnik::new_geometry::line_string, M, Z>(line, num_points);
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
2015-02-19 16:04:14 +01:00
|
|
|
return line;
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
template <bool M = false, bool Z = false>
|
|
|
|
mapnik::new_geometry::multi_line_string read_multilinestring()
|
2014-04-10 01:40:14 +02:00
|
|
|
{
|
|
|
|
int num_lines = read_integer();
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::multi_line_string multi_line;
|
|
|
|
multi_line.reserve(num_lines);
|
2014-04-10 01:40:14 +02:00
|
|
|
for (int i = 0; i < num_lines; ++i)
|
|
|
|
{
|
|
|
|
pos_ += 5;
|
2015-02-19 16:04:14 +01:00
|
|
|
multi_line.push_back(std::move(read_linestring<M, Z>()));
|
2009-07-03 15:29:50 +02:00
|
|
|
}
|
2015-02-19 16:04:14 +01:00
|
|
|
return multi_line;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
template <bool M = false, bool Z = false>
|
2015-02-24 14:13:00 +01:00
|
|
|
mapnik::new_geometry::polygon read_polygon()
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
|
|
|
int num_rings = read_integer();
|
2015-02-24 14:13:00 +01:00
|
|
|
mapnik::new_geometry::polygon poly;
|
2015-02-19 16:04:14 +01:00
|
|
|
if (num_rings > 1)
|
2011-10-19 13:25:42 +02:00
|
|
|
{
|
2015-02-19 16:04:14 +01:00
|
|
|
poly.interior_rings.reserve(num_rings - 1);
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
for (int i = 0; i < num_rings; ++i)
|
2014-04-10 01:40:14 +02:00
|
|
|
{
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::linear_ring ring;
|
|
|
|
int num_points = read_integer();
|
|
|
|
if (num_points > 0)
|
2014-04-10 01:40:14 +02:00
|
|
|
{
|
2015-02-19 16:04:14 +01:00
|
|
|
ring.reserve(num_points);
|
2015-02-19 17:13:43 +01:00
|
|
|
read_coords<mapnik::new_geometry::linear_ring, M, Z>(ring, num_points);
|
2014-04-10 01:40:14 +02:00
|
|
|
}
|
2015-02-19 16:04:14 +01:00
|
|
|
if ( i == 0) poly.set_exterior_ring(std::move(ring));
|
|
|
|
else poly.add_hole(std::move(ring));
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
2015-03-04 12:09:08 +01:00
|
|
|
// correct orientations etc
|
|
|
|
boost::geometry::correct(poly);
|
2015-02-19 16:04:14 +01:00
|
|
|
return poly;
|
2011-10-19 13:25:42 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
template <bool M = false, bool Z = false>
|
|
|
|
mapnik::new_geometry::multi_polygon read_multipolygon()
|
2014-04-10 01:40:14 +02:00
|
|
|
{
|
|
|
|
int num_polys = read_integer();
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::multi_polygon multi_poly;
|
2014-04-10 01:40:14 +02:00
|
|
|
for (int i = 0; i < num_polys; ++i)
|
|
|
|
{
|
|
|
|
pos_ += 5;
|
2015-02-19 16:04:14 +01:00
|
|
|
multi_poly.push_back(std::move(read_polygon<M, Z>()));
|
2010-11-18 22:52:20 +01:00
|
|
|
}
|
2015-02-19 16:04:14 +01:00
|
|
|
return multi_poly;
|
2010-11-18 22:52:20 +01:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2015-02-20 17:21:40 +01:00
|
|
|
mapnik::new_geometry::geometry_collection read_collection()
|
|
|
|
{
|
|
|
|
int num_geometries = read_integer();
|
|
|
|
mapnik::new_geometry::geometry_collection collection;
|
|
|
|
for (int i = 0; i < num_geometries; ++i)
|
|
|
|
{
|
|
|
|
pos_ += 1; // skip byte order
|
|
|
|
collection.push_back(std::move(read()));
|
|
|
|
}
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
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 wkbPointZ: s << "PointZ"; break;
|
2014-05-06 02:05:00 +02:00
|
|
|
case wkbPointM: s << "PointM"; break;
|
|
|
|
case wkbPointZM: s << "PointZM"; break;
|
|
|
|
case wkbMultiPoint: s << "MultiPoint"; break;
|
2012-07-21 00:28:10 +02:00
|
|
|
case wkbMultiPointZ: s << "MultiPointZ"; break;
|
2014-05-06 02:05:00 +02:00
|
|
|
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;
|
2012-07-21 00:28:10 +02:00
|
|
|
case wkbMultiLineStringZ: s << "MultiLineStringZ"; break;
|
2014-05-06 02:05:00 +02:00
|
|
|
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;
|
2012-07-21 00:28:10 +02:00
|
|
|
case wkbMultiPolygonZ: s << "MultiPolygonZ"; break;
|
2014-05-06 02:05:00 +02:00
|
|
|
case wkbMultiPolygonM: s << "MultiPolygonM"; break;
|
|
|
|
case wkbMultiPolygonZM: s << "MultiPolygonZM"; break;
|
|
|
|
case wkbGeometryCollection: s << "GeometryCollection"; break;
|
2012-07-21 00:28:10 +02:00
|
|
|
case wkbGeometryCollectionZ: s << "GeometryCollectionZ"; break;
|
2014-05-06 02:05:00 +02:00
|
|
|
case wkbGeometryCollectionM: s << "GeometryCollectionM"; break;
|
2015-02-19 16:04:14 +01:00
|
|
|
case wkbGeometryCollectionZM:s << "GeometryCollectionZM"; break;
|
2013-04-17 23:23:04 +02:00
|
|
|
default: s << "wkbUnknown(" << 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
|
|
|
};
|
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
mapnik::new_geometry::geometry geometry_utils::from_wkb(const char* wkb,
|
|
|
|
unsigned size,
|
|
|
|
wkbFormat format)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-10-19 13:25:42 +02:00
|
|
|
wkb_reader reader(wkb, size, format);
|
2015-02-19 16:04:14 +01:00
|
|
|
return mapnik::new_geometry::geometry(reader.read());
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
2011-12-06 13:53:16 +01:00
|
|
|
|
2015-02-19 16:04:14 +01:00
|
|
|
} // namespace mapnik
|