generic geometry_type impl
remove geometry_type from mapnik::datasource
This commit is contained in:
parent
8400be91c7
commit
367208ece1
7 changed files with 129 additions and 97 deletions
|
@ -33,13 +33,10 @@
|
|||
#include <mapnik/util/noncopyable.hpp>
|
||||
#include <mapnik/feature_style_processor_context.hpp>
|
||||
|
||||
// boost
|
||||
#include <memory>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
// stl
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
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<double> envelope() const = 0;
|
||||
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
|
||||
virtual layer_descriptor get_descriptor() const = 0;
|
||||
virtual ~datasource() {}
|
||||
protected:
|
||||
|
|
|
@ -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() {}
|
||||
|
|
84
include/mapnik/geometry_type.hpp
Normal file
84
include/mapnik/geometry_type.hpp
Normal file
|
@ -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 <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/geometry_types.hpp>
|
||||
|
||||
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
|
43
include/mapnik/geometry_types.hpp
Normal file
43
include/mapnik/geometry_types.hpp
Normal file
|
@ -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
|
|
@ -27,8 +27,6 @@
|
|||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
|
||||
//#include <mapnik/datasource.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
|
|
|
@ -287,82 +287,6 @@ const char * geojson_datasource::name()
|
|||
return "geojson";
|
||||
}
|
||||
|
||||
boost::optional<mapnik::datasource::geometry_t> geojson_datasource::get_geometry_type() const
|
||||
{
|
||||
boost::optional<mapnik::datasource::geometry_t> 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<int>(*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<mapnik::context_type>();
|
||||
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<char> 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<chr_iterator_type,mapnik::feature_impl> 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<int>(*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_;
|
||||
|
|
|
@ -94,8 +94,7 @@ public:
|
|||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
//
|
||||
|
||||
template <typename Iterator>
|
||||
void parse_geojson(Iterator start, Iterator end);
|
||||
template <typename Iterator>
|
||||
|
|
Loading…
Reference in a new issue