This commit is contained in:
Dane Springmeyer 2012-01-14 22:35:40 -08:00
parent 2c4a86d4cb
commit 66a0cfc81f
11 changed files with 48 additions and 132 deletions

View file

@ -96,15 +96,6 @@ boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
mapnik::layer_descriptor ld = ds->get_descriptor(); mapnik::layer_descriptor ld = ds->get_descriptor();
description["name"] = ld.get_name(); description["name"] = ld.get_name();
description["encoding"] = ld.get_encoding(); 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; return description;
} }
@ -163,6 +154,13 @@ void export_datasource()
{ {
using namespace boost::python; 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>, class_<datasource,boost::shared_ptr<datasource>,
boost::noncopyable>("Datasource",no_init) boost::noncopyable>("Datasource",no_init)
.def("describe",&describe) .def("describe",&describe)

View file

@ -40,7 +40,7 @@
#include <string> #include <string>
namespace mapnik { namespace mapnik {
typedef MAPNIK_DECL boost::shared_ptr<Feature> feature_ptr; typedef MAPNIK_DECL boost::shared_ptr<Feature> feature_ptr;
struct MAPNIK_DECL Featureset struct MAPNIK_DECL Featureset
@ -68,12 +68,19 @@ public:
class MAPNIK_DECL datasource : private boost::noncopyable class MAPNIK_DECL datasource : private boost::noncopyable
{ {
public: public:
enum datasource_t { enum datasource_t {
Vector, Vector,
Raster Raster
}; };
enum datasource_geom_t {
PointT,
LineStringT,
PolygonT,
CollectionT
};
datasource (parameters const& params) datasource (parameters const& params)
: params_(params), : params_(params),
is_bound_(false) is_bound_(false)
@ -105,6 +112,7 @@ public:
virtual featureset_ptr features(const query& q) const=0; virtual featureset_ptr features(const query& q) const=0;
virtual featureset_ptr features_at_point(coord2d const& pt) const=0; virtual featureset_ptr features_at_point(coord2d const& pt) const=0;
virtual box2d<double> envelope() 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 layer_descriptor get_descriptor() const=0;
virtual ~datasource() {}; virtual ~datasource() {};
protected: protected:

View file

@ -39,13 +39,11 @@ class layer_descriptor
public: public:
layer_descriptor(std::string const& name, std::string const& encoding) layer_descriptor(std::string const& name, std::string const& encoding)
: name_(name), : name_(name),
encoding_(encoding), encoding_(encoding) {}
geometry_type_("") {}
layer_descriptor(layer_descriptor const& other) layer_descriptor(layer_descriptor const& other)
: name_(other.name_), : name_(other.name_),
encoding_(other.encoding_), encoding_(other.encoding_),
geometry_type_(other.geometry_type_),
desc_ar_(other.desc_ar_) {} desc_ar_(other.desc_ar_) {}
void set_name(std::string const& name) void set_name(std::string const& name)
@ -68,16 +66,6 @@ public:
return encoding_; 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) void add_descriptor(attribute_descriptor const& desc)
{ {
desc_ar_.push_back(desc); desc_ar_.push_back(desc);
@ -96,7 +84,6 @@ public:
private: private:
std::string name_; std::string name_;
std::string encoding_; std::string encoding_;
std::string geometry_type_;
std::vector<attribute_descriptor> desc_ar_; std::vector<attribute_descriptor> desc_ar_;
}; };
@ -107,7 +94,6 @@ operator << (std::basic_ostream<charT,traits>& out,
{ {
out << "name: " << ld.get_name() << "\n"; out << "name: " << ld.get_name() << "\n";
out << "encoding: " << ld.get_encoding() << "\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& desc_ar = ld.get_descriptors();
std::vector<attribute_descriptor>::const_iterator pos = desc_ar.begin(); std::vector<attribute_descriptor>::const_iterator pos = desc_ar.begin();
while (pos != desc_ar.end()) while (pos != desc_ar.end())

View file

@ -43,6 +43,7 @@ public:
featureset_ptr features(const query& q) const; featureset_ptr features(const query& q) const;
featureset_ptr features_at_point(coord2d const& pt) const; featureset_ptr features_at_point(coord2d const& pt) const;
box2d<double> envelope() const; box2d<double> envelope() const;
boost::optional<datasource_geom_t> get_geometry_type() const;
layer_descriptor get_descriptor() const; layer_descriptor get_descriptor() const;
size_t size() const; size_t size() const;
void clear(); void clear();

View file

@ -39,8 +39,8 @@
namespace mapnik namespace mapnik
{ {
typedef boost::variant<value_null,int,double,std::string> value_holder; typedef boost::variant<value_null,int,double,std::string> value_holder;
typedef std::pair<const std::string, value_holder> parameter; typedef std::pair<std::string, value_holder> parameter;
typedef std::map<const std::string, value_holder> param_map; typedef std::map<std::string, value_holder> param_map;
template <typename T> template <typename T>
struct value_extractor_visitor : public boost::static_visitor<> struct value_extractor_visitor : public boost::static_visitor<>

View file

@ -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

View file

@ -13,7 +13,7 @@
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/memory_featureset.hpp> #include <mapnik/memory_featureset.hpp>
#include <mapnik/wkt/wkt_factory.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 #include <mapnik/ptree_helpers.hpp> // mapnik::boolean
// stl // 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"; 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() std::string csv_datasource::name()
@ -868,6 +850,25 @@ mapnik::box2d<double> csv_datasource::envelope() const
return extent_; 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 mapnik::layer_descriptor csv_datasource::get_descriptor() const
{ {
if (!is_bound_) bind(); if (!is_bound_) bind();

View file

@ -17,6 +17,7 @@ public:
mapnik::featureset_ptr features(mapnik::query const& q) const; mapnik::featureset_ptr features(mapnik::query const& q) const;
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::datasource_geom_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const; void bind() const;
template <typename T> template <typename T>

View file

@ -28,8 +28,6 @@
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/ptree_helpers.hpp> #include <mapnik/ptree_helpers.hpp>
#include <mapnik/sql_utils.hpp> #include <mapnik/sql_utils.hpp>
#include <mapnik/util/geometry_to_type_str.hpp>
#include <mapnik/wkb.hpp>
// boost // boost
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>

View file

@ -28,7 +28,7 @@
// mapnik // mapnik
#include <mapnik/ptree_helpers.hpp> #include <mapnik/ptree_helpers.hpp>
#include <mapnik/sql_utils.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> #include <mapnik/wkb.hpp>
// boost // boost

View file

@ -96,6 +96,11 @@ box2d<double> memory_datasource::envelope() const
std::for_each(features_.begin(),features_.end(),func); std::for_each(features_.begin(),features_.end(),func);
return ext; return ext;
} }
boost::optional<datasource::datasource_geom_t> memory_datasource::get_geometry_type() const
{
}
layer_descriptor memory_datasource::get_descriptor() const layer_descriptor memory_datasource::get_descriptor() const
{ {