From 367208ece19895ccaf10b502917c9c80b11e18d8 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 24 Feb 2015 11:17:00 +0100 Subject: [PATCH] generic geometry_type impl remove geometry_type from mapnik::datasource --- include/mapnik/datasource.hpp | 6 +- include/mapnik/geometry_impl.hpp | 12 --- include/mapnik/geometry_type.hpp | 84 ++++++++++++++++++++ include/mapnik/geometry_types.hpp | 43 ++++++++++ include/mapnik/util/geometry_to_ds_type.hpp | 2 - plugins/input/geojson/geojson_datasource.cpp | 76 ------------------ plugins/input/geojson/geojson_datasource.hpp | 3 +- 7 files changed, 129 insertions(+), 97 deletions(-) create mode 100644 include/mapnik/geometry_type.hpp create mode 100644 include/mapnik/geometry_types.hpp diff --git a/include/mapnik/datasource.hpp b/include/mapnik/datasource.hpp index ae2524c06..224584d0b 100644 --- a/include/mapnik/datasource.hpp +++ b/include/mapnik/datasource.hpp @@ -33,13 +33,10 @@ #include #include -// boost -#include -#include - // stl #include #include +#include namespace mapnik { @@ -118,7 +115,6 @@ public: virtual featureset_ptr features(query const& q) const = 0; virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0; virtual box2d envelope() const = 0; - virtual boost::optional get_geometry_type() const = 0; virtual layer_descriptor get_descriptor() const = 0; virtual ~datasource() {} protected: diff --git a/include/mapnik/geometry_impl.hpp b/include/mapnik/geometry_impl.hpp index 2bfbd87a8..3dac76291 100644 --- a/include/mapnik/geometry_impl.hpp +++ b/include/mapnik/geometry_impl.hpp @@ -37,18 +37,6 @@ namespace mapnik { namespace new_geometry { -enum geometry_types : std::uint8_t -{ - Unknown = 0, - Point = 1, - LineString = 2, - Polygon = 3, - MultiPoint = 4, - MultiLineString = 5, - MultiPolygon = 6, - GeometryCollection = 7, -}; - struct point { point() {} diff --git a/include/mapnik/geometry_type.hpp b/include/mapnik/geometry_type.hpp new file mode 100644 index 000000000..78078f497 --- /dev/null +++ b/include/mapnik/geometry_type.hpp @@ -0,0 +1,84 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 Artem Pavlenko + * + * 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, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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 + * + *****************************************************************************/ + +#ifndef MAPNIK_GEOMETRY_TYPE_HPP +#define MAPNIK_GEOMETRY_TYPE_HPP + +// mapnik +#include +#include + +namespace mapnik { namespace new_geometry { namespace detail { + +struct geometry_type +{ + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::geometry const& geom) const + { + return mapnik::util::apply_visitor(*this, geom); + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::point const&) const + { + return mapnik::new_geometry::geometry_types::Point; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::line_string const&) const + { + return mapnik::new_geometry::geometry_types::LineString; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::polygon3 const&) const + { + return mapnik::new_geometry::geometry_types::Polygon; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::multi_point const&) const + { + return mapnik::new_geometry::geometry_types::MultiPoint; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::multi_line_string const&) const + { + return mapnik::new_geometry::geometry_types::MultiLineString; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::multi_polygon const&) const + { + return mapnik::new_geometry::geometry_types::MultiPolygon; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::geometry_collection const&) const + { + return mapnik::new_geometry::geometry_types::GeometryCollection; + } +}; +} // detail + +static mapnik::new_geometry::geometry_types geometry_type(mapnik::new_geometry::geometry const& geom) +{ + return detail::geometry_type()(geom); +} + +}} + + +#endif // MAPNIK_GEOMETRY_TYPE_HPP diff --git a/include/mapnik/geometry_types.hpp b/include/mapnik/geometry_types.hpp new file mode 100644 index 000000000..ebff492cb --- /dev/null +++ b/include/mapnik/geometry_types.hpp @@ -0,0 +1,43 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 Artem Pavlenko + * + * 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, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * 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 + * + *****************************************************************************/ + +#ifndef MAPNIK_GEOMETRY_TYPES_HPP +#define MAPNIK_GEOMETRY_TYPES_HPP + +namespace mapnik { namespace new_geometry { + +// OGC compatible types +enum geometry_types : std::uint8_t +{ + Unknown = 0, + Point = 1, + LineString = 2, + Polygon = 3, + MultiPoint = 4, + MultiLineString = 5, + MultiPolygon = 6, + GeometryCollection = 7, +}; + +}} + +#endif // MAPNIK_GEOMETRY_TYPES_HPP diff --git a/include/mapnik/util/geometry_to_ds_type.hpp b/include/mapnik/util/geometry_to_ds_type.hpp index 598d332e4..2e8fe798f 100644 --- a/include/mapnik/util/geometry_to_ds_type.hpp +++ b/include/mapnik/util/geometry_to_ds_type.hpp @@ -27,8 +27,6 @@ #include #include -//#include - // boost #include diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 3318e9fec..89e2b7e88 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -287,82 +287,6 @@ const char * geojson_datasource::name() return "geojson"; } -boost::optional geojson_datasource::get_geometry_type() const -{ - boost::optional result; - return result; // FIXME - -#if 0 - int multi_type = 0; - if (cache_features_) - { - unsigned num_features = features_.size(); - for (unsigned i = 0; i < num_features && i < 5; ++i) - { - mapnik::util::to_ds_type(features_[i]->paths(),result); - if (result) - { - int type = static_cast(*result); - if (multi_type > 0 && multi_type != type) - { - result.reset(mapnik::datasource::Collection); - return result; - } - multi_type = type; - } - } - } - else - { - mapnik::util::file file(filename_); - if (!file.open()) - { - throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'"); - } - auto itr = tree_->qbegin(boost::geometry::index::intersects(extent_)); - auto end = tree_->qend(); - mapnik::context_ptr ctx = std::make_shared(); - for (std::size_t count = 0; itr !=end && count < 5; ++itr,++count) - { - geojson_datasource::item_type const& item = *itr; - std::size_t file_offset = item.second.first; - std::size_t size = item.second.second; - - std::fseek(file.get(), file_offset, SEEK_SET); - std::vector json; - json.resize(size); - std::fread(json.data(), size, 1, file.get()); - - using chr_iterator_type = char const*; - chr_iterator_type start = json.data(); - chr_iterator_type end = start + json.size(); - - static const mapnik::transcoder tr("utf8"); - static const mapnik::json::feature_grammar grammar(tr); - using namespace boost::spirit; - ascii::space_type space; - mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); - if (!qi::phrase_parse(start, end, (grammar)(boost::phoenix::ref(*feature)), space)) - { - throw std::runtime_error("Failed to parse geojson feature"); - } - mapnik::util::to_ds_type(feature->paths(),result); - if (result) - { - int type = static_cast(*result); - if (multi_type > 0 && multi_type != type) - { - result.reset(mapnik::datasource::Collection); - return result; - } - multi_type = type; - } - } - } - return result; -#endif // -} - mapnik::datasource::datasource_t geojson_datasource::type() const { return type_; diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index 04f1421b8..39d9222e7 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -94,8 +94,7 @@ public: mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const; mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; - boost::optional get_geometry_type() const; - // + template void parse_geojson(Iterator start, Iterator end); template