From 9de7397043f98ab4cc41fc406aeca5ec2e130939 Mon Sep 17 00:00:00 2001 From: Rinigus Date: Sun, 23 Apr 2017 22:48:35 +0300 Subject: [PATCH] add twkb support to sqlite plugin --- plugins/input/sqlite/sqlite_datasource.cpp | 15 +++++++++++++-- plugins/input/sqlite/sqlite_datasource.hpp | 1 + plugins/input/sqlite/sqlite_featureset.cpp | 6 +++++- plugins/input/sqlite/sqlite_featureset.hpp | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index e76ef41bb..e1002cfd6 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -68,7 +68,8 @@ sqlite_datasource::sqlite_datasource(parameters const& params) row_limit_(*params.get("row_limit", 0)), intersects_token_("!intersects!"), desc_(sqlite_datasource::name(), *params.get("encoding", "utf-8")), - format_(mapnik::wkbAuto) + format_(mapnik::wkbAuto), + twkb_encoding_(false) { /* TODO - throw if no primary key but spatial index is present? @@ -113,6 +114,11 @@ sqlite_datasource::sqlite_datasource(parameters const& params) { format_ = mapnik::wkbGeneric; } + else if (*wkb == "twkb") + { + format_ = mapnik::wkbGeneric; + twkb_encoding_ = true; + } else { format_ = mapnik::wkbAuto; @@ -448,7 +454,10 @@ boost::optional sqlite_datasource::get_geometry_t if (data) { - mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, format_); + mapnik::geometry::geometry geom; + + if (twkb_encoding_) geom = mapnik::geometry_utils::from_twkb(data, size); + else geom = mapnik::geometry_utils::from_wkb(data, size, format_); if (mapnik::geometry::is_empty(geom)) { continue; @@ -547,6 +556,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const desc_.get_encoding(), e, format_, + twkb_encoding_, has_spatial_index_, using_subquery_); } @@ -627,6 +637,7 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double to desc_.get_encoding(), e, format_, + twkb_encoding_, has_spatial_index_, using_subquery_); } diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index e73e0c3e8..8128b09cb 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -82,6 +82,7 @@ private: const std::string intersects_token_; mapnik::layer_descriptor desc_; mapnik::wkbFormat format_; + bool twkb_encoding_; bool use_spatial_index_; bool has_spatial_index_; bool using_subquery_; diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 9226f40d0..4f3ba5014 100644 --- a/plugins/input/sqlite/sqlite_featureset.cpp +++ b/plugins/input/sqlite/sqlite_featureset.cpp @@ -49,6 +49,7 @@ sqlite_featureset::sqlite_featureset(std::shared_ptr rs, std::string const& encoding, mapnik::box2d const& bbox, mapnik::wkbFormat format, + bool twkb_encoding, bool spatial_index, bool using_subquery) : rs_(rs), @@ -56,6 +57,7 @@ sqlite_featureset::sqlite_featureset(std::shared_ptr rs, tr_(new transcoder(encoding)), bbox_(bbox), format_(format), + twkb_encoding_(twkb_encoding), spatial_index_(spatial_index), using_subquery_(using_subquery) {} @@ -81,7 +83,9 @@ feature_ptr sqlite_featureset::next() } feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1)); - mapnik::geometry::geometry geom = geometry_utils::from_wkb(data, size, format_); + mapnik::geometry::geometry geom; + if (twkb_encoding_) geom = geometry_utils::from_twkb(data, size); + else geom = geometry_utils::from_wkb(data, size, format_); if (mapnik::geometry::is_empty(geom)) { continue; diff --git a/plugins/input/sqlite/sqlite_featureset.hpp b/plugins/input/sqlite/sqlite_featureset.hpp index 9e2f1c20a..23f948016 100644 --- a/plugins/input/sqlite/sqlite_featureset.hpp +++ b/plugins/input/sqlite/sqlite_featureset.hpp @@ -44,6 +44,7 @@ public: std::string const& encoding, mapnik::box2d const& bbox, mapnik::wkbFormat format, + bool twkb_encoding, bool spatial_index, bool using_subquery); virtual ~sqlite_featureset(); @@ -55,6 +56,7 @@ private: const std::unique_ptr tr_; mapnik::box2d bbox_; mapnik::wkbFormat format_; + bool twkb_encoding_; bool spatial_index_; bool using_subquery_;