refactor
This commit is contained in:
parent
2c4a86d4cb
commit
66a0cfc81f
11 changed files with 48 additions and 132 deletions
|
@ -96,15 +96,6 @@ boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
|
|||
mapnik::layer_descriptor ld = ds->get_descriptor();
|
||||
description["name"] = ld.get_name();
|
||||
description["encoding"] = ld.get_encoding();
|
||||
std::string geometry_type = ld.get_geometry_type();
|
||||
if (geometry_type.empty())
|
||||
{
|
||||
description["geometry_type"] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
description["geometry_type"] = geometry_type;
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
|
@ -163,6 +154,13 @@ void export_datasource()
|
|||
{
|
||||
using namespace boost::python;
|
||||
|
||||
enum_<mapnik::datasource::datasource_geom_t>("DatasourceGeometryType")
|
||||
.value("PointT",mapnik::datasource::PointT)
|
||||
.value("LineStringT",mapnik::datasource::LineStringT)
|
||||
.value("PolygonT",mapnik::datasource::PolygonT)
|
||||
.value("CollectionT",mapnik::datasource::CollectionT)
|
||||
;
|
||||
|
||||
class_<datasource,boost::shared_ptr<datasource>,
|
||||
boost::noncopyable>("Datasource",no_init)
|
||||
.def("describe",&describe)
|
||||
|
|
|
@ -74,6 +74,13 @@ public:
|
|||
Raster
|
||||
};
|
||||
|
||||
enum datasource_geom_t {
|
||||
PointT,
|
||||
LineStringT,
|
||||
PolygonT,
|
||||
CollectionT
|
||||
};
|
||||
|
||||
datasource (parameters const& params)
|
||||
: params_(params),
|
||||
is_bound_(false)
|
||||
|
@ -105,6 +112,7 @@ public:
|
|||
virtual featureset_ptr features(const query& q) const=0;
|
||||
virtual featureset_ptr features_at_point(coord2d const& pt) const=0;
|
||||
virtual box2d<double> envelope() const=0;
|
||||
virtual boost::optional<datasource_geom_t> get_geometry_type() const=0;
|
||||
virtual layer_descriptor get_descriptor() const=0;
|
||||
virtual ~datasource() {};
|
||||
protected:
|
||||
|
|
|
@ -39,13 +39,11 @@ class layer_descriptor
|
|||
public:
|
||||
layer_descriptor(std::string const& name, std::string const& encoding)
|
||||
: name_(name),
|
||||
encoding_(encoding),
|
||||
geometry_type_("") {}
|
||||
encoding_(encoding) {}
|
||||
|
||||
layer_descriptor(layer_descriptor const& other)
|
||||
: name_(other.name_),
|
||||
encoding_(other.encoding_),
|
||||
geometry_type_(other.geometry_type_),
|
||||
desc_ar_(other.desc_ar_) {}
|
||||
|
||||
void set_name(std::string const& name)
|
||||
|
@ -68,16 +66,6 @@ public:
|
|||
return encoding_;
|
||||
}
|
||||
|
||||
void set_geometry_type(std::string const& geometry_type)
|
||||
{
|
||||
geometry_type_ = geometry_type;
|
||||
}
|
||||
|
||||
std::string const& get_geometry_type() const
|
||||
{
|
||||
return geometry_type_;
|
||||
}
|
||||
|
||||
void add_descriptor(attribute_descriptor const& desc)
|
||||
{
|
||||
desc_ar_.push_back(desc);
|
||||
|
@ -96,7 +84,6 @@ public:
|
|||
private:
|
||||
std::string name_;
|
||||
std::string encoding_;
|
||||
std::string geometry_type_;
|
||||
std::vector<attribute_descriptor> desc_ar_;
|
||||
};
|
||||
|
||||
|
@ -107,7 +94,6 @@ operator << (std::basic_ostream<charT,traits>& out,
|
|||
{
|
||||
out << "name: " << ld.get_name() << "\n";
|
||||
out << "encoding: " << ld.get_encoding() << "\n";
|
||||
out << "geometry_type: " << ld.get_geometry_type() << "\n";
|
||||
std::vector<attribute_descriptor> const& desc_ar = ld.get_descriptors();
|
||||
std::vector<attribute_descriptor>::const_iterator pos = desc_ar.begin();
|
||||
while (pos != desc_ar.end())
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
box2d<double> envelope() const;
|
||||
boost::optional<datasource_geom_t> get_geometry_type() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
size_t size() const;
|
||||
void clear();
|
||||
|
|
|
@ -39,8 +39,8 @@
|
|||
namespace mapnik
|
||||
{
|
||||
typedef boost::variant<value_null,int,double,std::string> value_holder;
|
||||
typedef std::pair<const std::string, value_holder> parameter;
|
||||
typedef std::map<const std::string, value_holder> param_map;
|
||||
typedef std::pair<std::string, value_holder> parameter;
|
||||
typedef std::map<std::string, value_holder> param_map;
|
||||
|
||||
template <typename T>
|
||||
struct value_extractor_visitor : public boost::static_visitor<>
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2012 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_GEOMETRY_DESCRIBE
|
||||
#define MAPNIK_GEOMETRY_DESCRIBE
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
void to_type_str(mapnik::geometry_type const& g, std::string & geometry_string_type )
|
||||
{
|
||||
switch (g.type())
|
||||
{
|
||||
case mapnik::Point:
|
||||
geometry_string_type = "point";
|
||||
break;
|
||||
case mapnik::LineString:
|
||||
geometry_string_type = "linestring";
|
||||
break;
|
||||
case mapnik::Polygon:
|
||||
geometry_string_type = "polygon";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void to_type_str(mapnik::geometry_container const& paths, std::string & geometry_string_type )
|
||||
{
|
||||
if (paths.size() == 1)
|
||||
{
|
||||
// single geometry
|
||||
to_type_str(paths.front(), geometry_string_type);
|
||||
}
|
||||
else if (paths.size() > 1)
|
||||
{
|
||||
int multi_type = 0;
|
||||
geometry_container::const_iterator itr = paths.begin();
|
||||
geometry_container::const_iterator end = paths.end();
|
||||
for ( ; itr!=end; ++itr)
|
||||
{
|
||||
int type = static_cast<int>(itr->type());
|
||||
if (multi_type > 0 && multi_type != itr->type())
|
||||
{
|
||||
geometry_string_type = "collection";
|
||||
break;
|
||||
}
|
||||
to_type_str(*itr, geometry_string_type);
|
||||
multi_type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_DESCRIBE
|
|
@ -13,7 +13,7 @@
|
|||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/memory_featureset.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include <mapnik/util/geometry_to_type_str.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
#include <mapnik/ptree_helpers.hpp> // mapnik::boolean
|
||||
|
||||
// stl
|
||||
|
@ -831,24 +831,6 @@ void csv_datasource::parse_csv(T& stream,
|
|||
{
|
||||
if (!quiet_) std::clog << "CSV Plugin: could not parse any lines of data\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string g_type("");
|
||||
std::string prev_type("");
|
||||
boost::ptr_vector<mapnik::geometry_type> paths;
|
||||
unsigned num_features = features_.size();
|
||||
for (int i = 0; i < num_features; ++i)
|
||||
{
|
||||
mapnik::util::to_type_str(features_[i]->paths(),g_type);
|
||||
if (!prev_type.empty() && g_type != prev_type)
|
||||
{
|
||||
g_type = "collection";
|
||||
break;
|
||||
}
|
||||
prev_type = g_type;
|
||||
}
|
||||
desc_.set_geometry_type(g_type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string csv_datasource::name()
|
||||
|
@ -868,6 +850,25 @@ mapnik::box2d<double> csv_datasource::envelope() const
|
|||
return extent_;
|
||||
}
|
||||
|
||||
boost::optional<mapnik::datasource::datasource_geom_t> csv_datasource::get_geometry_type() const
|
||||
{
|
||||
boost::optional<mapnik::datasource::datasource_geom_t> result;
|
||||
int multi_type = 0;
|
||||
unsigned num_features = features_.size();
|
||||
for (int i = 0; i < num_features || i < 5; ++i)
|
||||
{
|
||||
mapnik::datasource::datasource_geom_t type = mapnik::util::to_ds_type(features_[i]->paths());
|
||||
if (multi_type > 0 && multi_type != type)
|
||||
{
|
||||
result.reset(mapnik::datasource::CollectionT);
|
||||
return result;
|
||||
}
|
||||
result.reset(type);
|
||||
multi_type = type;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
mapnik::layer_descriptor csv_datasource::get_descriptor() const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::datasource_geom_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
void bind() const;
|
||||
template <typename T>
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/ptree_helpers.hpp>
|
||||
#include <mapnik/sql_utils.hpp>
|
||||
#include <mapnik/util/geometry_to_type_str.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/ptree_helpers.hpp>
|
||||
#include <mapnik/sql_utils.hpp>
|
||||
#include <mapnik/util/geometry_to_type_str.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
||||
// boost
|
||||
|
|
|
@ -97,6 +97,11 @@ box2d<double> memory_datasource::envelope() const
|
|||
return ext;
|
||||
}
|
||||
|
||||
boost::optional<datasource::datasource_geom_t> memory_datasource::get_geometry_type() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
layer_descriptor memory_datasource::get_descriptor() const
|
||||
{
|
||||
return desc_;
|
||||
|
|
Loading…
Reference in a new issue