This commit is contained in:
Dane Springmeyer 2011-12-16 16:07:57 -08:00
commit fd895f9533
55 changed files with 567 additions and 1016 deletions

View file

@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
Mapnik 2.1.0
------------
- SQLite - Added support for !intersects! token in sql subselects (#809) allow custom positioning of rtree spatial filter.
- New CSV plugin - reads tabular files - autodetecting geo columns, newlines, and delimiters. Uses in-memory featureset for fast rendering and is not designed for large files (#902)
- Fixed bug in shield line placement when dx/dy are used to shift the label relative to the placement point (Matt Amos) (#908)

View file

@ -142,7 +142,11 @@ paths += "__all__ = [mapniklibpath,inputpluginspath,fontscollectionpath]\n"
if not os.path.exists('mapnik'):
os.mkdir('mapnik')
file('mapnik/paths.py','w').write(paths % (os.path.relpath(env['MAPNIK_LIB_DIR'],target_path)))
if hasattr(os.path,'relpath'): # python 2.6 and above
file('mapnik/paths.py','w').write(paths % (os.path.relpath(env['MAPNIK_LIB_DIR'],target_path)))
else:
file('mapnik/paths.py','w').write(paths % (env['MAPNIK_LIB_DIR']))
# force open perms temporarily so that `sudo scons install`
# does not later break simple non-install non-sudo rebuild

View file

@ -593,7 +593,7 @@ class PDFPrinter:
for l in m.layers:
# extract the layer names for naming layers if we use OCG
self._layer_names.append(l.title or l.name)
self._layer_names.append(l.name)
layer_map = Map(m.width,m.height,m.srs)
layer_map.layers.append(l)
@ -884,7 +884,7 @@ class PDFPrinter:
for l in reversed(m.layers):
have_layer_header = False
added_styles={}
layer_title = l.title or l.name
layer_title = l.name
if layer_title in processed_layers:
continue
processed_layers.append(layer_title)
@ -906,8 +906,8 @@ class PDFPrinter:
if r.filter and str(r.filter) != "true":
if len(rule_text) > 0:
rule_text += " AND "
if r.title:
rule_text += r.title
if r.name:
rule_text += r.name
else:
rule_text += str(r.filter)
active_rules = tuple(active_rules)

View file

@ -45,7 +45,7 @@ using mapnik::from_wkt;
void feature_add_geometries_from_wkb(Feature &feature, std::string wkb)
{
geometry_utils::from_wkb(feature.paths(), wkb.c_str(), wkb.size(), true);
geometry_utils::from_wkb(feature.paths(), wkb.c_str(), wkb.size());
}
void feature_add_geometries_from_wkt(Feature &feature, std::string wkt)

View file

@ -62,7 +62,7 @@ void add_wkt_impl(path_type& p, std::string const& wkt)
void add_wkb_impl(path_type& p, std::string const& wkb)
{
mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size(), true);
mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size());
}
boost::shared_ptr<path_type> from_wkt_impl(std::string const& wkt)
@ -76,7 +76,7 @@ boost::shared_ptr<path_type> from_wkt_impl(std::string const& wkt)
boost::shared_ptr<path_type> from_wkb_impl(std::string const& wkb)
{
boost::shared_ptr<path_type> paths = boost::make_shared<path_type>();
mapnik::geometry_utils::from_wkb(*paths, wkb.c_str(), wkb.size(), true);
mapnik::geometry_utils::from_wkb(*paths, wkb.c_str(), wkb.size());
return paths;
}
@ -117,6 +117,24 @@ std::string to_wkt( geometry_type const& geom)
#endif
}
std::string to_wkt2( path_type const& geom)
{
#if BOOST_VERSION >= 104700
std::string wkt; // Use Python String directly ?
bool result = mapnik::util::to_wkt(wkt,geom);
if (!result)
{
throw std::runtime_error("Generate WKT failed");
}
return wkt;
#else
std::ostringstream s;
s << BOOST_VERSION/100000 << "." << BOOST_VERSION/100 % 1000 << "." << BOOST_VERSION % 100;
throw std::runtime_error("mapnik::to_wkt() requires at least boost 1.47 while your build was compiled against boost " + s.str());
#endif
}
void export_geometry()
{
using namespace boost::python;
@ -125,9 +143,6 @@ void export_geometry()
.value("Point",mapnik::Point)
.value("LineString",mapnik::LineString)
.value("Polygon",mapnik::Polygon)
.value("MultiPoint",mapnik::MultiPoint)
.value("MultiLineString",mapnik::MultiLineString)
.value("MultiPolygon",mapnik::MultiPolygon)
;
using mapnik::geometry_type;
@ -145,6 +160,7 @@ void export_geometry()
.def("__len__", &path_type::size)
.def("add_wkt",add_wkt_impl)
.def("add_wkb",add_wkb_impl)
.def("to_wkt",&to_wkt2)
.def("from_wkt",from_wkt_impl)
.def("from_wkb",from_wkb_impl)
.staticmethod("from_wkt")

View file

@ -54,7 +54,7 @@ struct layer_pickle_suite : boost::python::pickle_suite
{
s.append(style_names[i]);
}
return boost::python::make_tuple(l.abstract(),l.title(),l.clear_label_cache(),l.getMinZoom(),l.getMaxZoom(),l.isQueryable(),l.datasource()->params(),l.cache_features(),s);
return boost::python::make_tuple(l.clear_label_cache(),l.getMinZoom(),l.getMaxZoom(),l.isQueryable(),l.datasource()->params(),l.cache_features(),s);
}
static void
@ -70,28 +70,24 @@ struct layer_pickle_suite : boost::python::pickle_suite
throw_error_already_set();
}
l.set_abstract(extract<std::string>(state[0]));
l.set_clear_label_cache(extract<bool>(state[0]));
l.set_title(extract<std::string>(state[1]));
l.setMinZoom(extract<double>(state[1]));
l.set_clear_label_cache(extract<bool>(state[2]));
l.setMaxZoom(extract<double>(state[2]));
l.setMinZoom(extract<double>(state[3]));
l.setQueryable(extract<bool>(state[3]));
l.setMaxZoom(extract<double>(state[4]));
l.setQueryable(extract<bool>(state[5]));
mapnik::parameters params = extract<parameters>(state[6]);
mapnik::parameters params = extract<parameters>(state[4]);
l.set_datasource(datasource_cache::instance()->create(params));
boost::python::list s = extract<boost::python::list>(state[7]);
boost::python::list s = extract<boost::python::list>(state[5]);
for (int i=0;i<len(s);++i)
{
l.add_style(extract<std::string>(s[i]));
}
l.set_cache_features(extract<bool>(state[8]));
l.set_cache_features(extract<bool>(state[6]));
}
};
@ -152,21 +148,6 @@ void export_layer()
"False\n"
)
.add_property("abstract",
make_function(&layer::abstract,return_value_policy<copy_const_reference>()),
&layer::set_abstract,
"Get/Set the abstract of the layer.\n"
"\n"
"Usage:\n"
">>> from mapnik import Layer\n"
">>> lyr = Layer('My Layer','+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')\n"
">>> lyr.abstract\n"
"'' # default is en empty string\n"
">>> lyr.abstract = 'My Shapefile rendered with Mapnik'\n"
">>> lyr.abstract\n"
"'My Shapefile rendered with Mapnik'\n"
)
.add_property("active",
&layer::isActive,
&layer::setActive,
@ -310,20 +291,5 @@ void export_layer()
"'My Style'\n"
)
.add_property("title",
make_function(&layer::title, return_value_policy<copy_const_reference>()),
&layer::set_title,
"Get/Set the title of the layer.\n"
"\n"
"Usage:\n"
">>> from mapnik import layer\n"
">>> lyr = layer('My layer','+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')\n"
">>> lyr.title\n"
"''\n"
">>> lyr.title = 'My first layer'\n"
">>> lyr.title\n"
"'My first layer'\n"
)
;
}

View file

@ -86,7 +86,7 @@ struct rule_pickle_suite : boost::python::pickle_suite
static boost::python::tuple
getinitargs(const rule& r)
{
return boost::python::make_tuple(r.get_name(),r.get_title(),r.get_min_scale(),r.get_max_scale());
return boost::python::make_tuple(r.get_name(),r.get_min_scale(),r.get_max_scale());
}
static boost::python::tuple
@ -102,7 +102,7 @@ struct rule_pickle_suite : boost::python::pickle_suite
// We serialize filter expressions AST as strings
std::string filter_expr = to_expression_string(*r.get_filter());
return boost::python::make_tuple(r.get_abstract(),filter_expr,r.has_else_filter(),r.has_also_filter(),syms);
return boost::python::make_tuple(filter_expr,r.has_else_filter(),r.has_also_filter(),syms);
}
static void
@ -119,11 +119,6 @@ struct rule_pickle_suite : boost::python::pickle_suite
}
if (state[0])
{
r.set_title(extract<std::string>(state[0]));
}
if (state[1])
{
rule dfl;
std::string filter = extract<std::string>(state[1]);
@ -134,12 +129,12 @@ struct rule_pickle_suite : boost::python::pickle_suite
}
}
if (state[2])
if (state[1])
{
r.set_else(true);
}
if (state[3])
if (state[2])
{
r.set_also(true);
}
@ -176,18 +171,12 @@ void export_rule()
class_<rule>("Rule",init<>("default constructor"))
.def(init<std::string const&,
boost::python::optional<std::string const&,double,double> >())
boost::python::optional<double,double> >())
.def_pickle(rule_pickle_suite())
.add_property("name",make_function
(&rule::get_name,
return_value_policy<copy_const_reference>()),
&rule::set_name)
.add_property("title",make_function
(&rule::get_title,return_value_policy<copy_const_reference>()),
&rule::set_title)
.add_property("abstract",make_function
(&rule::get_abstract,return_value_policy<copy_const_reference>()),
&rule::set_abstract)
.add_property("filter",make_function
(&rule::get_filter,return_value_policy<copy_const_reference>()),
&rule::set_filter)

View file

@ -36,29 +36,24 @@ namespace mapnik {
enum eGeomType {
Point = 1,
LineString,
Polygon,
MultiPoint,
MultiLineString,
MultiPolygon
LineString = 2,
Polygon = 3
};
template <typename T, template <typename> class Container=vertex_vector>
class geometry
class geometry : private::boost::noncopyable
{
public:
typedef T coord_type;
typedef Container<coord_type> container_type;
typedef typename container_type::value_type value_type;
private:
container_type cont_;
eGeomType type_;
mutable unsigned itr_;
public:
geometry(eGeomType type)
explicit geometry(eGeomType type)
: type_(type),
itr_(0)
{}
@ -168,7 +163,7 @@ public:
*/
void label_position(double *x, double *y) const
{
if (type_ == LineString || type_ == MultiLineString)
if (type_ == LineString)
{
middle_point(x,y);
return;
@ -232,7 +227,7 @@ public:
/* summarized distance centroid */
void label_position3(double *x, double *y) const
{
if (type_ == LineString || type_ == MultiLineString)
if (type_ == LineString)
{
middle_point(x,y);
return;
@ -392,7 +387,7 @@ public:
typedef geometry<double,vertex_vector> geometry_type;
typedef boost::shared_ptr<geometry_type> geometry_ptr;
typedef boost::ptr_vector<geometry_type> geometry_containter;
typedef boost::ptr_vector<geometry_type> geometry_container;
}

View file

@ -56,28 +56,9 @@ public:
/*!
* @return the name of the layer.
*/
const std::string& name() const;
/*!
* @brief Set the title of the layer.
*/
void set_title(std::string const& title);
/*!
* @return the title of the layer.
*/
const std::string& title() const;
/*!
* @brief Set the abstract of the layer.
*/
void set_abstract(std::string const& abstract);
/*!
* @return the abstract of the layer.
*/
const std::string& abstract() const;
/*!
* @brief Set the SRS of the layer.
*/
@ -212,8 +193,6 @@ private:
void swap(const layer& other);
std::string name_;
std::string title_;
std::string abstract_;
std::string srs_;
double minZoom_;

View file

@ -132,8 +132,6 @@ public:
private:
std::string name_;
std::string title_;
std::string abstract_;
double min_scale_;
double max_scale_;
symbolizers syms_;
@ -143,8 +141,6 @@ private:
public:
rule()
: name_(),
title_(),
abstract_(),
min_scale_(0),
max_scale_(std::numeric_limits<double>::infinity()),
syms_(),
@ -153,11 +149,9 @@ public:
also_filter_(false) {}
rule(const std::string& name,
const std::string& title="",
double min_scale_denominator=0,
double max_scale_denominator=std::numeric_limits<double>::infinity())
: name_(name),
title_(title),
min_scale_(min_scale_denominator),
max_scale_(max_scale_denominator),
syms_(),
@ -167,8 +161,6 @@ public:
rule(const rule& rhs, bool deep_copy = false)
: name_(rhs.name_),
title_(rhs.title_),
abstract_(rhs.abstract_),
min_scale_(rhs.min_scale_),
max_scale_(rhs.max_scale_),
syms_(rhs.syms_),
@ -264,26 +256,6 @@ public:
return name_;
}
std::string const& get_title() const
{
return title_;
}
void set_title(std::string const& title)
{
title_=title;
}
void set_abstract(std::string const& abstract)
{
abstract_=abstract;
}
std::string const& get_abstract() const
{
return abstract_;
}
void append(const symbolizer& sym)
{
syms_.push_back(sym);
@ -362,8 +334,6 @@ private:
void swap(rule& rhs) throw()
{
name_=rhs.name_;
title_=rhs.title_;
abstract_=rhs.abstract_;
min_scale_=rhs.min_scale_;
max_scale_=rhs.max_scale_;
syms_=rhs.syms_;

View file

@ -219,10 +219,6 @@ wkb_buffer_ptr to_wkb(geometry_type const& g, wkbByteOrder byte_order )
case mapnik::Polygon:
wkb = to_polygon_wkb(g, byte_order);
break;
case mapnik::MultiPoint:
case mapnik::MultiLineString:
case mapnik::MultiPolygon:
break;
default:
break;
}

View file

@ -42,8 +42,19 @@ bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom)
{
typedef std::back_insert_iterator<std::string> sink_type;
sink_type sink(wkt);
wkt_generator<sink_type> generator;
bool result = karma::generate(sink, generator, geom);
// disable temporarily until compile works with g++
//wkt_generator<sink_type> generator(true);
bool result = false;//karma::generate(sink, generator, geom);
return result;
}
bool to_wkt(std::string & wkt, mapnik::geometry_container const& geom)
{
typedef std::back_insert_iterator<std::string> sink_type;
sink_type sink(wkt);
// disable temporarily until compile works with g++
//wkt_multi_generator<sink_type> generator;
bool result = false;//karma::generate(sink, generator, geom);
return result;
}

View file

@ -30,7 +30,6 @@
#include <mapnik/geometry.hpp>
#include <mapnik/util/vertex_iterator.hpp>
#include <mapnik/util/container_adapter.hpp>
// boost
#include <boost/tuple/tuple.hpp>
#include <boost/spirit/include/karma.hpp>
@ -49,6 +48,8 @@ namespace mapnik { namespace util {
namespace karma = boost::spirit::karma;
namespace phoenix = boost::phoenix;
namespace {
struct get_type
{
template <typename T>
@ -56,7 +57,7 @@ struct get_type
int operator() (geometry_type const& geom) const
{
return (int)geom.type();
return static_cast<int>(geom.type());
}
};
@ -73,21 +74,61 @@ struct get_first
}
};
struct multi_geometry_
{
template <typename T>
struct result { typedef bool type; };
bool operator() (geometry_container const& geom) const
{
return geom.size() > 1 ? true : false;
}
};
struct multi_geometry_type
{
template <typename T>
struct result { typedef boost::tuple<unsigned,bool> type; };
boost::tuple<unsigned,bool> operator() (geometry_container const& geom) const
{
unsigned type = 0u;
bool collection = false;
geometry_container::const_iterator itr = geom.begin();
geometry_container::const_iterator end = geom.end();
for ( ; itr != end; ++itr)
{
if (type != 0 && itr->type() != type)
{
collection = true;
break;
}
type = itr->type();
}
return boost::tuple<unsigned,bool>(type, collection);
}
};
template <typename T>
struct coordinate_policy : karma::real_policies<T>
struct wkt_coordinate_policy : karma::real_policies<T>
{
typedef boost::spirit::karma::real_policies<T> base_type;
static int floatfield(T n) { return base_type::fmtflags::fixed; }
static unsigned precision(T n) { return 6u ;}
static unsigned precision(T n) { return 6 ;}
};
}
template <typename OutputIterator>
struct wkt_generator :
karma::grammar<OutputIterator, geometry_type const& ()>
{
wkt_generator()
wkt_generator(bool single = false)
: wkt_generator::base_type(wkt)
{
using boost::spirit::karma::uint_;
@ -97,22 +138,27 @@ struct wkt_generator :
using boost::spirit::karma::_a;
using boost::spirit::karma::_r1;
using boost::spirit::karma::eps;
using boost::spirit::karma::string;
wkt = point | linestring | polygon
;
point = &uint_(mapnik::Point)[_1 = _type(_val)]
<< lit("Point(") << point_coord [_1 = _first(_val)] << lit(')')
<< string[ phoenix::if_ (single) [_1 = "Point("]
.else_[_1 = "("]]
<< point_coord [_1 = _first(_val)] << lit(')')
;
linestring = &uint_(mapnik::LineString)[_1 = _type(_val)]
<< lit("LineString(")
<< string[ phoenix::if_ (single) [_1 = "LineString("]
.else_[_1 = "("]]
<< coords
<< lit(')')
;
polygon = &uint_(mapnik::Polygon)[_1 = _type(_val)]
<< lit("Polygon(")
<< string[ phoenix::if_ (single) [_1 = "Polygon("]
.else_[_1 = "("]]
<< coords2
<< lit("))")
;
@ -121,7 +167,7 @@ struct wkt_generator :
;
polygon_coord %= ( &uint_(mapnik::SEG_MOVETO) << eps[_r1 += 1]
<< karma::string[ if_ (_r1 > 1) [_1 = "),("]
<< string[ if_ (_r1 > 1) [_1 = "),("]
.else_[_1 = "("] ] | &uint_ << ",")
<< coord_type
<< lit(' ')
@ -144,16 +190,69 @@ struct wkt_generator :
karma::rule<OutputIterator, geometry_type const& ()> coords;
karma::rule<OutputIterator, karma::locals<unsigned>, geometry_type const& ()> coords2;
karma::rule<OutputIterator, geometry_type::value_type ()> point_coord;
karma::rule<OutputIterator, geometry_type::value_type const& (unsigned& )> polygon_coord;
karma::rule<OutputIterator, geometry_type::value_type (unsigned& )> polygon_coord;
// phoenix functions
phoenix::function<get_type > _type;
phoenix::function<get_first> _first;
//
karma::real_generator<double, coordinate_policy<double> > coord_type;
karma::real_generator<double, wkt_coordinate_policy<double> > coord_type;
};
template <typename OutputIterator>
struct wkt_multi_generator :
karma::grammar<OutputIterator, karma::locals< boost::tuple<unsigned,bool> >, geometry_container const& ()>
{
wkt_multi_generator()
: wkt_multi_generator::base_type(wkt)
{
using boost::spirit::karma::lit;
using boost::spirit::karma::eps;
using boost::spirit::karma::_val;
using boost::spirit::karma::_1;
using boost::spirit::karma::_a;
geometry_types.add
(mapnik::Point,"Point")
(mapnik::LineString,"LineString")
(mapnik::Polygon,"Polygon")
;
wkt = eps(phoenix::at_c<1>(_a))[_a = _multi_type(_val)]
<< lit("GeometryCollection(") << geometry << lit(")")
| eps(is_multi(_val)) << lit("Multi") << geometry_types[_1 = phoenix::at_c<0>(_a)]
<< "(" << multi_geometry << ")"
| geometry
;
geometry = -(single_geometry % lit(','))
;
single_geometry = geometry_types[_1 = _type(_val)] << path
;
multi_geometry = -(path % lit(','))
;
}
// rules
karma::rule<OutputIterator, karma::locals<boost::tuple<unsigned,bool> >, geometry_container const& ()> wkt;
karma::rule<OutputIterator, geometry_container const& ()> geometry;
karma::rule<OutputIterator, geometry_type const& ()> single_geometry;
karma::rule<OutputIterator, geometry_container const& ()> multi_geometry;
wkt_generator<OutputIterator> path;
// phoenix
phoenix::function<multi_geometry_> is_multi;
phoenix::function<multi_geometry_type> _multi_type;
phoenix::function<get_type > _type;
//
karma::symbols<unsigned, char const*> geometry_types;
};
}}

View file

@ -27,6 +27,8 @@
#include <mapnik/geometry.hpp>
#include <mapnik/ctrans.hpp>
#include <mapnik/feature.hpp>
// boost
#include <boost/utility.hpp>
namespace mapnik
{
@ -49,19 +51,14 @@ enum wkbFormat
wkbSpatiaLite=3
};
class MAPNIK_DECL geometry_utils
class MAPNIK_DECL geometry_utils : private boost::noncopyable
{
public:
static void from_wkb (boost::ptr_vector<geometry_type>& paths,
const char* wkb,
unsigned size,
bool multiple_geometries = false,
wkbFormat format = wkbGeneric);
private:
geometry_utils();
geometry_utils(geometry_utils const&);
geometry_utils& operator=(const geometry_utils&);
};
}

View file

@ -98,8 +98,6 @@ geos_datasource::geos_datasource(parameters const& params, bool bind)
if (! geometry) throw datasource_exception("missing <wkt> parameter");
geometry_string_ = *geometry;
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext);
@ -270,8 +268,7 @@ featureset_ptr geos_datasource::features(query const& q) const
geometry_id_,
geometry_data_,
geometry_data_name_,
desc_.get_encoding(),
multiple_geometries_);
desc_.get_encoding());
}
featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
@ -290,6 +287,5 @@ featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
geometry_id_,
geometry_data_,
geometry_data_name_,
desc_.get_encoding(),
multiple_geometries_);
desc_.get_encoding());
}

View file

@ -56,7 +56,6 @@ private:
mutable std::string geometry_data_name_;
mutable int geometry_id_;
std::string geometry_string_;
bool multiple_geometries_;
};
#endif // GEOS_DATASOURCE_HPP

View file

@ -53,15 +53,13 @@ geos_featureset::geos_featureset(GEOSGeometry* geometry,
int identifier,
const std::string& field,
const std::string& field_name,
const std::string& encoding,
bool multiple_geometries)
const std::string& encoding)
: geometry_(geometry),
tr_(new transcoder(encoding)),
extent_(extent),
identifier_(identifier),
field_(field),
field_name_(field_name),
multiple_geometries_(multiple_geometries),
already_rendered_(false)
{
}
@ -120,9 +118,7 @@ feature_ptr geos_featureset::next()
geometry_utils::from_wkb(feature->paths(),
wkb.data(),
wkb.size(),
multiple_geometries_);
wkb.size());
if (field_ != "")
{
boost::put(*feature, field_name_, tr_->transcode(field_.c_str()));

View file

@ -44,8 +44,7 @@ public:
int identifier,
const std::string& field,
const std::string& field_name,
const std::string& encoding,
bool multiple_geometries);
const std::string& encoding);
virtual ~geos_featureset();
mapnik::feature_ptr next();

View file

@ -50,7 +50,6 @@ private:
const std::list<kismet_network_data>& knd_list_;
boost::scoped_ptr<mapnik::transcoder> tr_;
mapnik::wkbFormat format_;
bool multiple_geometries_;
int feature_id_;
std::list<kismet_network_data>::const_iterator knd_list_it;
mapnik::projection source_;

View file

@ -94,7 +94,6 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
table_ = *table;
}
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true);
use_connection_pool_ = *params_.get<mapnik::boolean>("use_connection_pool",true);
@ -560,7 +559,6 @@ featureset_ptr occi_datasource::features(query const& q) const
conn_,
s.str(),
desc_.get_encoding(),
multiple_geometries_,
use_connection_pool_,
row_prefetch_,
props.size());
@ -642,7 +640,6 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
conn_,
s.str(),
desc_.get_encoding(),
multiple_geometries_,
use_connection_pool_,
row_prefetch_,
size);

View file

@ -64,7 +64,6 @@ private:
mutable oracle::occi::StatelessConnectionPool* pool_;
mutable oracle::occi::Connection* conn_;
bool use_connection_pool_;
bool multiple_geometries_;
bool use_spatial_index_;
static const std::string METADATA_TABLE;
};

View file

@ -59,12 +59,10 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool,
Connection* conn,
std::string const& sqlstring,
std::string const& encoding,
bool multiple_geometries,
bool use_connection_pool,
unsigned prefetch_rows,
unsigned num_attrs)
: tr_(new transcoder(encoding)),
multiple_geometries_(multiple_geometries),
num_attrs_(num_attrs),
feature_id_(1)
{
@ -101,7 +99,7 @@ feature_ptr occi_featureset::next()
boost::scoped_ptr<SDOGeometry> geom(dynamic_cast<SDOGeometry*>(rs_->getObject(1)));
if (geom.get())
{
convert_geometry(geom.get(), feature, multiple_geometries_);
convert_geometry(geom.get(), feature);
}
std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData();
@ -204,7 +202,7 @@ feature_ptr occi_featureset::next()
}
void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, bool multiple_geometries)
void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature)
{
int gtype = (int)geom->getSdo_gtype();
int dimensions = gtype / 1000;
@ -248,16 +246,13 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
{
const bool is_single_geom = true;
const bool is_point_type = false;
const bool multiple_geoms = false;
convert_ordinates(feature,
mapnik::LineString,
elem_info,
ordinates,
dimensions,
is_single_geom,
is_point_type,
multiple_geoms);
is_point_type);
}
}
break;
@ -267,16 +262,13 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
{
const bool is_single_geom = true;
const bool is_point_type = false;
const bool multiple_geoms = false;
convert_ordinates(feature,
mapnik::Polygon,
elem_info,
ordinates,
dimensions,
is_single_geom,
is_point_type,
multiple_geoms);
is_point_type);
}
}
break;
@ -286,19 +278,15 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
{
const bool is_single_geom = false;
const bool is_point_type = true;
const bool multiple_geoms = true;
// Todo - force using true as multiple_geometries until we have proper multipoint handling
// http://trac.mapnik.org/ticket/458
// FIXME :http://trac.mapnik.org/ticket/458
convert_ordinates(feature,
mapnik::Point,
elem_info,
ordinates,
dimensions,
is_single_geom,
is_point_type,
multiple_geoms);
is_point_type);
}
}
break;
@ -315,8 +303,7 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
ordinates,
dimensions,
is_single_geom,
is_point_type,
multiple_geometries);
is_point_type);
}
}
break;
@ -333,8 +320,7 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
ordinates,
dimensions,
is_single_geom,
is_point_type,
multiple_geometries);
is_point_type);
}
}
@ -352,8 +338,7 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
ordinates,
dimensions,
is_single_geom,
is_point_type,
multiple_geometries);
is_point_type);
}
}
break;
@ -374,8 +359,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
const std::vector<Number>& ordinates,
const int dimensions,
const bool is_single_geom,
const bool is_point_geom,
const bool multiple_geometries)
const bool is_point_geom)
{
const int elem_size = elem_info.size();
const int ord_size = ordinates.size();
@ -388,7 +372,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
if (! is_single_geom && elem_size > SDO_ELEM_INFO_SIZE)
{
geometry_type* geom = multiple_geometries ? 0 : new geometry_type(geom_type);
geometry_type* geom = new geometry_type(geom_type);
if (geom) geom->set_capacity(ord_size);
for (int i = SDO_ELEM_INFO_SIZE; i < elem_size; i+=3)
@ -443,8 +427,6 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
}
if (is_linear_element)
{
if (multiple_geometries)
{
if (geom)
{
@ -453,7 +435,6 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
geom = new geometry_type(gtype);
geom->set_capacity((next_offset - 1) - (offset - 1 - dimensions));
}
fill_geometry_type(geom,
offset - 1,

View file

@ -42,7 +42,6 @@ public:
oracle::occi::Connection* conn,
std::string const& sqlstring,
std::string const& encoding,
bool multiple_geometries,
bool use_connection_pool,
unsigned prefetch_rows,
unsigned num_attrs);
@ -50,15 +49,14 @@ public:
mapnik::feature_ptr next();
private:
void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries);
void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature);
void convert_ordinates (mapnik::feature_ptr feature,
const mapnik::eGeomType& geom_type,
const std::vector<oracle::occi::Number>& elem_info,
const std::vector<oracle::occi::Number>& ordinates,
const int dimensions,
const bool is_single_geom,
const bool is_point_geom,
const bool multiple_geometries);
const bool is_point_geom);
void fill_geometry_type (mapnik::geometry_type* geom,
const int real_offset,
const int next_offset,
@ -70,7 +68,6 @@ private:
oracle::occi::ResultSet* rs_;
boost::scoped_ptr<mapnik::transcoder> tr_;
const char* fidcolumn_;
bool multiple_geometries_;
unsigned num_attrs_;
mutable int feature_id_;
};

View file

@ -87,8 +87,6 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
{
if (table_.empty()) throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext);
@ -517,7 +515,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
unsigned num_attr = props.size();
if (!key_field_.empty())
++num_attr;
return boost::make_shared<postgis_featureset>(rs,desc_.get_encoding(),multiple_geometries_,!key_field_.empty(),num_attr);
return boost::make_shared<postgis_featureset>(rs,desc_.get_encoding(), !key_field_.empty(),num_attr);
}
else
{
@ -585,7 +583,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
}
boost::shared_ptr<IResultSet> rs = get_resultset(conn, s.str());
return boost::make_shared<postgis_featureset>(rs,desc_.get_encoding(),multiple_geometries_,!key_field_.empty(),size);
return boost::make_shared<postgis_featureset>(rs,desc_.get_encoding(), !key_field_.empty(),size);
}
}
return featureset_ptr();

View file

@ -69,7 +69,6 @@ class postgis_datasource : public datasource
mutable mapnik::box2d<double> extent_;
mutable layer_descriptor desc_;
ConnectionCreator<Connection> creator_;
bool multiple_geometries_;
const std::string bbox_token_;
const std::string scale_denom_token_;
bool persist_connection_;

View file

@ -49,11 +49,9 @@ using mapnik::feature_factory;
postgis_featureset::postgis_featureset(boost::shared_ptr<IResultSet> const& rs,
std::string const& encoding,
bool multiple_geometries,
bool key_field=false,
unsigned num_attrs=0)
: rs_(rs),
multiple_geometries_(multiple_geometries),
num_attrs_(num_attrs),
tr_(new transcoder(encoding)),
totalGeomSize_(0),
@ -103,7 +101,7 @@ feature_ptr postgis_featureset::next()
// parse geometry
int size = rs_->getFieldLength(0);
const char *data = rs_->getValue(0);
geometry_utils::from_wkb(feature->paths(),data,size,multiple_geometries_);
geometry_utils::from_wkb(feature->paths(), data, size);
totalGeomSize_+=size;
for ( ;pos<num_attrs_+1;++pos)

View file

@ -44,7 +44,6 @@ class postgis_featureset : public mapnik::Featureset
{
private:
boost::shared_ptr<IResultSet> rs_;
bool multiple_geometries_;
unsigned num_attrs_;
boost::scoped_ptr<mapnik::transcoder> tr_;
int totalGeomSize_;
@ -53,7 +52,6 @@ private:
public:
postgis_featureset(boost::shared_ptr<IResultSet> const& rs,
std::string const& encoding,
bool multiple_geometries,
bool key_field,
unsigned num_attrs);
mapnik::feature_ptr next();

View file

@ -248,49 +248,19 @@ feature_ptr shape_featureset<filterT>::next()
}
case shape_io::shape_polyline:
{
geometry_type* line = shape_.read_polyline();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinem:
{
geometry_type* line = shape_.read_polylinem();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinez:
{
geometry_type* line = shape_.read_polylinez();
feature->add_geometry(line);
shape_.read_polyline(feature->paths());
++count_;
break;
}
case shape_io::shape_polygon:
{
geometry_type* poly = shape_.read_polygon();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonm:
{
geometry_type* poly = shape_.read_polygonm();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonz:
{
geometry_type* poly = shape_.read_polygonz();
feature->add_geometry(poly);
shape_.read_polygon(feature->paths());
++count_;
break;
}

View file

@ -193,49 +193,18 @@ feature_ptr shape_index_featureset<filterT>::next()
}
case shape_io::shape_polyline:
{
geometry_type* line = shape_.read_polyline();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinem:
{
geometry_type* line = shape_.read_polylinem();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinez:
{
geometry_type* line = shape_.read_polylinez();
feature->add_geometry(line);
shape_.read_polyline(feature->paths());
++count_;
break;
}
case shape_io::shape_polygon:
{
geometry_type* poly = shape_.read_polygon();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonm:
{
geometry_type* poly = shape_.read_polygonm();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonz:
{
geometry_type* poly = shape_.read_polygonz();
feature->add_geometry(poly);
shape_.read_polygon(feature->paths());
++count_;
break;
}

View file

@ -106,18 +106,16 @@ dbf_file& shape_io::dbf()
return dbf_;
}
geometry_type* shape_io::read_polyline()
void shape_io::read_polyline(mapnik::geometry_container & geom)
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
geometry_type* line = new geometry_type(mapnik::LineString);
line->set_capacity(num_points + num_parts);
if (num_parts == 1)
{
line->set_capacity(num_points + 1);
geometry_type* line = new geometry_type(mapnik::LineString);
record.skip(4);
double x = record.read_double();
double y = record.read_double();
@ -128,6 +126,7 @@ geometry_type* shape_io::read_polyline()
y = record.read_double();
line->line_to(x, y);
}
geom.push_back(line);
}
else
{
@ -140,6 +139,7 @@ geometry_type* shape_io::read_polyline()
int start, end;
for (int k = 0; k < num_parts; ++k)
{
geometry_type* line = new geometry_type(mapnik::LineString);
start = parts[k];
if (k == num_parts - 1)
{
@ -160,135 +160,9 @@ geometry_type* shape_io::read_polyline()
y = record.read_double();
line->line_to(x, y);
}
geom.push_back(line);
}
}
return line;
}
geometry_type* shape_io::read_polylinem()
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
geometry_type* line = new geometry_type(mapnik::LineString);
line->set_capacity(num_points + num_parts);
if (num_parts == 1)
{
record.skip(4);
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int i = 1; i < num_points; ++i)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
else
{
std::vector<int> parts(num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
int start, end;
for (int k = 0; k < num_parts; ++k)
{
start = parts[k];
if (k == num_parts - 1)
{
end = num_points;
}
else
{
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int j = start + 1; j < end; ++j)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
}
// m-range
//double m0=record.read_double();
//double m1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double m=record.read_double();
//}
return line;
}
geometry_type* shape_io::read_polylinez()
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
geometry_type* line = new geometry_type(mapnik::LineString);
line->set_capacity(num_points + num_parts);
if (num_parts == 1)
{
record.skip(4);
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int i = 1; i < num_points; ++i)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
else
{
std::vector<int> parts(num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
int start, end;
for (int k = 0; k < num_parts; ++k)
{
start = parts[k];
if (k == num_parts - 1)
{
end = num_points;
}
else
{
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int j = start + 1; j < end; ++j)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
}
// z-range
//double z0=record.read_double();
//double z1=record.read_double();
@ -306,10 +180,9 @@ geometry_type* shape_io::read_polylinez()
// double m=record.read_double();
//}
return line;
}
geometry_type* shape_io::read_polygon()
void shape_io::read_polygon(mapnik::geometry_container & geom)
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
@ -317,8 +190,7 @@ geometry_type* shape_io::read_polygon()
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
std::vector<int> parts(num_parts);
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity(num_points + num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
@ -326,6 +198,7 @@ geometry_type* shape_io::read_polygon()
for (int k = 0; k < num_parts; k++)
{
geometry_type* poly = new geometry_type(mapnik::Polygon);
int start = parts[k];
int end;
if (k == num_parts - 1)
@ -347,101 +220,8 @@ geometry_type* shape_io::read_polygon()
y = record.read_double();
poly->line_to(x, y);
}
geom.push_back(poly);
}
return poly;
}
geometry_type* shape_io::read_polygonm()
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
std::vector<int> parts(num_parts);
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity(num_points + num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
for (int k = 0; k < num_parts; k++)
{
int start = parts[k];
int end;
if (k == num_parts - 1)
{
end = num_points;
}
else
{
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
poly->move_to(x, y);
for (int j = start + 1; j < end; j++)
{
x = record.read_double();
y = record.read_double();
poly->line_to(x, y);
}
}
// m-range
//double m0=record.read_double();
//double m1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double m=record.read_double();
//}
return poly;
}
geometry_type* shape_io::read_polygonz()
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
std::vector<int> parts(num_parts);
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity(num_points + num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
for (int k = 0; k < num_parts; k++)
{
int start = parts[k];
int end;
if (k == num_parts - 1)
{
end = num_points;
}
else
{
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
poly->move_to(x, y);
for (int j = start + 1; j < end; j++)
{
x = record.read_double();
y = record.read_double();
poly->line_to(x, y);
}
}
// z-range
//double z0=record.read_double();
//double z1=record.read_double();
@ -458,6 +238,6 @@ geometry_type* shape_io::read_polygonz()
//{
// double m=record.read_double();
//}
return poly;
}

View file

@ -23,6 +23,8 @@
#ifndef SHAPE_IO_HPP
#define SHAPE_IO_HPP
// mapnik
#include <mapnik/geometry.hpp>
// boost
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
@ -56,7 +58,6 @@ public:
~shape_io();
shape_file& shp();
//shape_file& shx();
dbf_file& dbf();
inline boost::shared_ptr<shape_file>& index()
@ -72,16 +73,10 @@ public:
void move_to(int id);
int type() const;
const box2d<double>& current_extent() const;
mapnik::geometry_type* read_polyline();
mapnik::geometry_type* read_polylinem();
mapnik::geometry_type* read_polylinez();
mapnik::geometry_type* read_polygon();
mapnik::geometry_type* read_polygonm();
mapnik::geometry_type* read_polygonz();
void read_polyline(mapnik::geometry_container & geom);
void read_polygon(mapnik::geometry_container & geom);
unsigned type_;
shape_file shp_;
//shape_file shx_;
dbf_file dbf_;
boost::shared_ptr<shape_file> index_;
unsigned reclength_;
@ -89,7 +84,6 @@ public:
box2d<double> cur_extent_;
static const std::string SHP;
//static const std::string SHX;
static const std::string DBF;
static const std::string INDEX;
};

View file

@ -62,6 +62,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
key_field_(*params_.get<std::string>("key_field", "")),
row_offset_(*params_.get<int>("row_offset", 0)),
row_limit_(*params_.get<int>("row_limit", 0)),
intersects_token_("!intersects!"),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
format_(mapnik::wkbAuto)
{
@ -102,7 +103,6 @@ void sqlite_datasource::bind() const
throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist");
}
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries", false);
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index", true);
// TODO - remove this option once all datasources have an indexing api
@ -186,7 +186,8 @@ void sqlite_datasource::bind() const
if (using_subquery_)
{
std::ostringstream s;
s << "SELECT " << fields_ << " FROM (" << table_ << ") LIMIT 1";
std::string query = populate_tokens(table_);
s << "SELECT " << fields_ << " FROM (" << query << ") LIMIT 1";
found_types_via_subquery = sqlite_utils::detect_types_from_subquery(s.str(),geometry_field_,desc_,dataset_);
}
@ -225,7 +226,12 @@ void sqlite_datasource::bind() const
if (geometry_field_.empty())
{
throw datasource_exception("Sqlite Plugin: cannot detect geometry_field, please supply the name of the geometry_field to use.");
std::ostringstream s;
s << "Sqlite Plugin: unable to detect the column "
<< "containing a valid geometry on table '" << geometry_table_ << "'. "
<< "Please provide a column name by passing the 'geometry_field' option "
<< "or indicate a different spatial table to use by passing the 'geometry_table' option";
throw datasource_exception(s.str());
}
if (index_table_.empty())
@ -302,6 +308,7 @@ void sqlite_datasource::bind() const
{
// TODO - clean this up - reducing arguments
std::string query = populate_tokens(table_);
if (!sqlite_utils::detect_extent(dataset_,
has_spatial_index_,
extent_,
@ -310,7 +317,7 @@ void sqlite_datasource::bind() const
geometry_field_,
geometry_table_,
key_field_,
table_))
query))
{
std::ostringstream s;
s << "Sqlite Plugin: extent could not be determined for table '"
@ -324,6 +331,17 @@ void sqlite_datasource::bind() const
is_bound_ = true;
}
std::string sqlite_datasource::populate_tokens(const std::string& sql) const
{
std::string populated_sql = sql;
if (boost::algorithm::ifind_first(populated_sql, intersects_token_))
{
// replace with dummy comparison that is true
boost::algorithm::ireplace_first(populated_sql, intersects_token_, "1=1");
}
return populated_sql;
}
sqlite_datasource::~sqlite_datasource()
{
}
@ -461,23 +479,21 @@ featureset_ptr sqlite_datasource::features(query const& q) const
s << " FROM ";
std::string query (table_);
std::string query(table_);
if (! key_field_.empty() && has_spatial_index_)
{
std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16);
spatial_sql << " WHERE " << key_field_ << " IN (SELECT pkid FROM " << index_table_;
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
if (boost::algorithm::ifind_first(query, "WHERE"))
// TODO - debug warn if fails
sqlite_utils::apply_spatial_filter(query,
e,
table_,
key_field_,
index_table_,
geometry_table_,
intersects_token_); }
else
{
boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND ");
}
else if (boost::algorithm::ifind_first(query, geometry_table_))
{
boost::algorithm::ireplace_first(query, table_, table_ + " " + spatial_sql.str());
}
query = populate_tokens(table_);
}
s << query ;
@ -502,7 +518,6 @@ featureset_ptr sqlite_datasource::features(query const& q) const
return boost::make_shared<sqlite_featureset>(rs,
desc_.get_encoding(),
format_,
multiple_geometries_,
using_subquery_);
}
@ -541,19 +556,18 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
if (! key_field_.empty() && has_spatial_index_)
{
std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16);
spatial_sql << " WHERE " << key_field_ << " IN (SELECT pkid FROM " << index_table_;
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
if (boost::algorithm::ifind_first(query, "WHERE"))
{
boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND ");
// TODO - debug warn if fails
sqlite_utils::apply_spatial_filter(query,
e,
table_,
key_field_,
index_table_,
geometry_table_,
intersects_token_);
}
else if (boost::algorithm::ifind_first(query, geometry_table_))
else
{
boost::algorithm::ireplace_first(query, table_, table_ + " " + spatial_sql.str());
}
query = populate_tokens(table_);
}
s << query ;
@ -577,7 +591,6 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
return boost::make_shared<sqlite_featureset>(rs,
desc_.get_encoding(),
format_,
multiple_geometries_,
using_subquery_);
}

View file

@ -51,6 +51,11 @@ public:
void bind() const;
private:
// FIXME: remove mutable qualifier from data members
// by factoring out bind() logic out from
// datasource impl !!!
mutable mapnik::box2d<double> extent_;
mutable bool extent_initialized_;
int type_;
@ -65,9 +70,10 @@ private:
mutable std::string key_field_;
mutable int row_offset_;
mutable int row_limit_;
// TODO - also add to postgis.input
const std::string intersects_token_;
mutable mapnik::layer_descriptor desc_;
mutable mapnik::wkbFormat format_;
mutable bool multiple_geometries_;
mutable bool use_spatial_index_;
mutable bool has_spatial_index_;
mutable bool using_subquery_;
@ -76,6 +82,7 @@ private:
// Fill init_statements with any statements
// needed to attach auxillary databases
void parse_attachdb(std::string const& attachdb) const;
std::string populate_tokens(const std::string& sql) const;
};
#endif // MAPNIK_SQLITE_DATASOURCE_HPP

View file

@ -47,12 +47,10 @@ using mapnik::feature_factory;
sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
std::string const& encoding,
mapnik::wkbFormat format,
bool multiple_geometries,
bool using_subquery)
: rs_(rs),
tr_(new transcoder(encoding)),
format_(format),
multiple_geometries_(multiple_geometries),
using_subquery_(using_subquery)
{
}
@ -75,7 +73,7 @@ feature_ptr sqlite_featureset::next()
int feature_id = rs_->column_integer(1);
feature_ptr feature(feature_factory::create(feature_id));
geometry_utils::from_wkb(feature->paths(), data, size, multiple_geometries_, format_);
geometry_utils::from_wkb(feature->paths(), data, size, format_);
for (int i = 2; i < rs_->column_count(); ++i)
{

View file

@ -42,7 +42,6 @@ public:
sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
std::string const& encoding,
mapnik::wkbFormat format,
bool multiple_geometries,
bool using_subquery);
virtual ~sqlite_featureset();
mapnik::feature_ptr next();
@ -51,7 +50,6 @@ private:
boost::shared_ptr<sqlite_resultset> rs_;
boost::scoped_ptr<mapnik::transcoder> tr_;
mapnik::wkbFormat format_;
bool multiple_geometries_;
bool using_subquery_;
};

View file

@ -108,6 +108,42 @@ public:
//}
}
static bool apply_spatial_filter(std::string & query,
mapnik::box2d<double> const& e,
std::string const& table,
std::string const& key_field,
std::string const& index_table,
std::string const& geometry_table,
std::string const& intersects_token)
{
std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16);
spatial_sql << key_field << " IN (SELECT pkid FROM " << index_table;
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
if (boost::algorithm::ifind_first(query, intersects_token))
{
boost::algorithm::ireplace_all(query, intersects_token, spatial_sql.str());
return true;
}
// substitute first WHERE found if not using JOIN
// (because we can't know the WHERE is on the right table)
else if (boost::algorithm::ifind_first(query, "WHERE")
&& !boost::algorithm::ifind_first(query, "JOIN"))
{
std::string replace(" WHERE " + spatial_sql.str() + " AND ");
boost::algorithm::ireplace_first(query, "WHERE", replace);
return true;
}
// fallback to appending spatial filter at end of query
else if (boost::algorithm::ifind_first(query, geometry_table))
{
query = table + " WHERE " + spatial_sql.str();
return true;
}
return false;
}
static void get_tables(boost::shared_ptr<sqlite_connection> ds,
std::vector<std::string> & tables)
{
@ -151,11 +187,11 @@ public:
while (rs->is_valid() && rs->step_next())
{
int size;
const char* data = (const char*) rs->column_blob(0, size);
const char* data = static_cast<const char*>(rs->column_blob(0, size));
if (data)
{
boost::ptr_vector<mapnik::geometry_type> paths;
mapnik::geometry_utils::from_wkb(paths, data, size, false, mapnik::wkbAuto);
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto);
for (unsigned i=0; i<paths.size(); ++i)
{
mapnik::box2d<double> const& bbox = paths[i].envelope();
@ -241,12 +277,19 @@ public:
if (data)
{
boost::ptr_vector<mapnik::geometry_type> paths;
// TODO - contraint fails if multiple_geometries = true
bool multiple_geometries = false;
mapnik::geometry_utils::from_wkb(paths, data, size, multiple_geometries, mapnik::wkbAuto);
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto);
mapnik::box2d<double> bbox;
for (unsigned i=0; i<paths.size(); ++i)
{
mapnik::box2d<double> const& bbox = paths[i].envelope();
if (i==0)
{
bbox = paths[i].envelope();
}
else
{
bbox.expand_to_include(paths[i].envelope());
}
}
if (bbox.valid())
{
@ -278,7 +321,6 @@ public:
}
}
}
}
catch (mapnik::datasource_exception const& ex)
{
if (!existed)
@ -320,13 +362,11 @@ public:
while (rs->is_valid() && rs->step_next())
{
int size;
const char* data = (const char*) rs->column_blob(0, size);
const char* data = static_cast<const char*>(rs->column_blob(0, size));
if (data)
{
boost::ptr_vector<mapnik::geometry_type> paths;
// TODO - contraint fails if multiple_geometries = true
bool multiple_geometries = false;
mapnik::geometry_utils::from_wkb(paths, data, size, multiple_geometries, mapnik::wkbAuto);
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto);
for (unsigned i=0; i<paths.size(); ++i)
{
mapnik::box2d<double> const& bbox = paths[i].envelope();
@ -568,6 +608,7 @@ public:
// PRAGMA table_info is used so here we assume the column is a string
// which is a lesser evil than altogether dropping the column
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String));
break;
case SQLITE_BLOB:
if (geometry_field.empty()

View file

@ -44,7 +44,7 @@ void agg_renderer<T>::process(text_symbolizer const& sym,
if (geom.num_points() == 0) continue; // don't bother with empty geometries
if ((geom.type() == Polygon || geom.type() == MultiPolygon) && sym.get_minimum_path_length() > 0)
if ((geom.type() == Polygon) && sym.get_minimum_path_length() > 0)
{
// TODO - find less costly method than fetching full envelope
box2d<double> gbox = t_.forward(geom.envelope(),prj_trans);

View file

@ -37,8 +37,6 @@ namespace mapnik
{
layer::layer(std::string const& name, std::string const& srs)
: name_(name),
title_(""),
abstract_(""),
srs_(srs),
minZoom_(0),
maxZoom_(std::numeric_limits<double>::max()),
@ -51,8 +49,6 @@ layer::layer(std::string const& name, std::string const& srs)
layer::layer(const layer& rhs)
: name_(rhs.name_),
title_(rhs.title_),
abstract_(rhs.abstract_),
srs_(rhs.srs_),
minZoom_(rhs.minZoom_),
maxZoom_(rhs.maxZoom_),
@ -79,8 +75,6 @@ bool layer::operator==(layer const& other) const
void layer::swap(const layer& rhs)
{
name_=rhs.name_;
title_=rhs.title_;
abstract_=rhs.abstract_;
srs_ = rhs.srs_;
minZoom_=rhs.minZoom_;
maxZoom_=rhs.maxZoom_;
@ -105,26 +99,6 @@ std::string const& layer::name() const
return name_;
}
void layer::set_title( std::string const& title)
{
title_ = title;
}
std::string const& layer::title() const
{
return title_;
}
void layer::set_abstract( std::string const& abstract)
{
abstract_ = abstract;
}
std::string const& layer::abstract() const
{
return abstract_;
}
void layer::set_srs(std::string const& srs)
{
srs_ = srs;

View file

@ -577,8 +577,6 @@ void map_parser::parse_layer( Map & map, ptree const & lay )
s << "name,"
<< "srs,"
<< "status,"
<< "title,"
<< "abstract,"
<< "minzoom,"
<< "maxzoom,"
<< "queryable,"
@ -601,18 +599,6 @@ void map_parser::parse_layer( Map & map, ptree const & lay )
lyr.setActive( * status );
}
optional<std::string> title = get_opt_attr<std::string>(lay, "title");
if (title)
{
lyr.set_title( * title );
}
optional<std::string> abstract = get_opt_attr<std::string>(lay, "abstract");
if (abstract)
{
lyr.set_abstract( * abstract );
}
optional<double> minZoom = get_opt_attr<double>(lay, "minzoom");
if (minZoom)
{
@ -765,14 +751,12 @@ void map_parser::parse_layer( Map & map, ptree const & lay )
void map_parser::parse_rule( feature_type_style & style, ptree const & r )
{
ensure_attrs(r, "Rule", "name,title");
ensure_attrs(r, "Rule", "name");
std::string name;
try
{
name = get_attr( r, "name", std::string());
std::string title = get_attr( r, "title", std::string());
rule rule(name,title);
rule rule(name);
optional<std::string> filter_expr =
get_opt_child<std::string>( r, "Filter");

View file

@ -646,10 +646,6 @@ void serialize_rule( ptree & style_node, const rule & r, bool explicit_defaults)
{
set_attr(rule_node, "name", r.get_name());
}
if ( r.get_title() != dfl.get_title() )
{
set_attr(rule_node, "title", r.get_title());
}
if ( r.has_else_filter() )
{
@ -814,21 +810,12 @@ void serialize_layer( ptree & map_node, const layer & layer, bool explicit_defau
{
ptree & layer_node = map_node.push_back(
ptree::value_type("Layer", ptree()))->second;
if ( layer.name() != "" )
{
set_attr( layer_node, "name", layer.name() );
}
if ( layer.abstract() != "" )
{
set_attr( layer_node, "abstract", layer.abstract() );
}
if ( layer.title() != "" )
{
set_attr( layer_node, "title", layer.title() );
}
if ( layer.srs() != "" )
{
set_attr( layer_node, "srs", layer.srs() );

View file

@ -115,15 +115,12 @@ public:
#endif
}
~wkb_reader() {}
void read_multi(boost::ptr_vector<geometry_type> & paths)
void read(boost::ptr_vector<geometry_type> & paths)
{
int type = read_integer();
#ifdef MAPNIK_DEBUG_WKB
std::clog << "wkb_reader: read_multi "
<< wkb_geometry_type_string(type) << " " << type << std::endl;
std::clog << "wkb_reader: read " << wkb_geometry_type_string(type) << " " << type << std::endl;
#endif
switch (type)
@ -175,63 +172,6 @@ public:
}
}
void read(boost::ptr_vector<geometry_type> & paths)
{
int type = read_integer();
#ifdef MAPNIK_DEBUG_WKB
std::clog << "wkb_reader: read " << wkb_geometry_type_string(type) << " " << type << std::endl;
#endif
switch (type)
{
case wkbPoint:
read_point(paths);
break;
case wkbLineString:
read_linestring(paths);
break;
case wkbPolygon:
read_polygon(paths);
break;
case wkbMultiPoint:
read_multipoint_2(paths);
break;
case wkbMultiLineString:
read_multilinestring_2(paths);
break;
case wkbMultiPolygon:
read_multipolygon_2(paths);
break;
case wkbGeometryCollection:
read_collection_2(paths);
break;
case wkbPointZ:
read_point_xyz(paths);
break;
case wkbLineStringZ:
read_linestring_xyz(paths);
break;
case wkbPolygonZ:
read_polygon_xyz(paths);
break;
case wkbMultiPointZ:
read_multipoint_xyz_2(paths);
break;
case wkbMultiLineStringZ:
read_multilinestring_xyz_2(paths);
break;
case wkbMultiPolygonZ:
read_multipolygon_xyz_2(paths);
break;
case wkbGeometryCollectionZ:
read_collection_2(paths);
break;
default:
break;
}
}
private:
int read_integer()
@ -330,20 +270,6 @@ private:
}
}
void read_multipoint_2(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* pt = new geometry_type(MultiPoint);
int num_points = read_integer();
for (int i = 0; i < num_points; ++i)
{
pos_ += 5;
double x = read_double();
double y = read_double();
pt->move_to(x, y);
}
paths.push_back(pt);
}
void read_point_xyz(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* pt = new geometry_type(Point);
@ -364,22 +290,6 @@ private:
}
}
void read_multipoint_xyz_2(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* pt = new geometry_type(MultiPoint);
int num_points = read_integer();
for (int i = 0; i < num_points; ++i)
{
pos_ += 5;
double x = read_double();
double y = read_double();
pos_ += 8; // double z = read_double();
pt->move_to(x, y);
}
paths.push_back(pt);
}
void read_linestring(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* line = new geometry_type(LineString);
@ -405,28 +315,6 @@ private:
}
}
void read_multilinestring_2(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* line = new geometry_type(MultiLineString);
int num_lines = read_integer();
unsigned capacity = 0;
for (int i = 0; i < num_lines; ++i)
{
pos_ += 5;
int num_points = read_integer();
capacity += num_points;
CoordinateArray ar(num_points);
read_coords(ar);
line->set_capacity(capacity);
line->move_to(ar[0].x, ar[0].y);
for (int j = 1; j < num_points; ++j)
{
line->line_to(ar[j].x, ar[j].y);
}
}
paths.push_back(line);
}
void read_linestring_xyz(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* line = new geometry_type(LineString);
@ -452,28 +340,6 @@ private:
}
}
void read_multilinestring_xyz_2(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* line = new geometry_type(MultiLineString);
int num_lines = read_integer();
unsigned capacity = 0;
for (int i = 0; i < num_lines; ++i)
{
pos_ += 5;
int num_points = read_integer();
capacity += num_points;
CoordinateArray ar(num_points);
read_coords_xyz(ar);
line->set_capacity(capacity);
line->move_to(ar[0].x, ar[0].y);
for (int j = 1; j < num_points; ++j)
{
line->line_to(ar[j].x, ar[j].y);
}
}
paths.push_back(line);
}
void read_polygon(boost::ptr_vector<geometry_type> & paths)
{
@ -506,33 +372,6 @@ private:
}
}
void read_multipolygon_2(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* poly = new geometry_type(MultiPolygon);
int num_polys = read_integer();
unsigned capacity = 0;
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
int num_rings = read_integer();
for (int r = 0; r < num_rings; ++r)
{
int num_points = read_integer();
capacity += num_points;
CoordinateArray ar(num_points);
read_coords(ar);
poly->set_capacity(capacity);
poly->move_to(ar[0].x, ar[0].y);
for (int j = 1; j < num_points; ++j)
{
poly->line_to(ar[j].x, ar[j].y);
}
poly->line_to(ar[0].x, ar[0].y);
}
}
paths.push_back(poly);
}
void read_polygon_xyz(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* poly = new geometry_type(Polygon);
@ -564,34 +403,6 @@ private:
}
}
void read_multipolygon_xyz_2(boost::ptr_vector<geometry_type> & paths)
{
geometry_type* poly = new geometry_type(MultiPolygon);
int num_polys = read_integer();
unsigned capacity = 0;
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
int num_rings = read_integer();
for (int r = 0; r < num_rings; ++r)
{
int num_points = read_integer();
capacity += num_points;
CoordinateArray ar(num_points);
read_coords_xyz(ar);
poly->set_capacity(capacity);
poly->move_to(ar[0].x, ar[0].y);
for (int j = 1; j < num_points; ++j)
{
poly->line_to(ar[j].x, ar[j].y);
}
poly->line_to(ar[0].x, ar[0].y);
}
}
paths.push_back(poly);
}
void read_collection(boost::ptr_vector<geometry_type> & paths)
{
int num_geometries = read_integer();
@ -602,16 +413,6 @@ private:
}
}
void read_collection_2(boost::ptr_vector<geometry_type> & paths)
{
int num_geometries = read_integer();
for (int i = 0; i < num_geometries; ++i)
{
pos_ += 1; // skip byte order
read_multi(paths);
}
}
#ifdef MAPNIK_DEBUG_WKB
std::string wkb_geometry_type_string(int type)
{
@ -645,17 +446,10 @@ private:
void geometry_utils::from_wkb (boost::ptr_vector<geometry_type>& paths,
const char* wkb,
unsigned size,
bool multiple_geometries,
wkbFormat format)
{
wkb_reader reader(wkb, size, format);
if (multiple_geometries)
{
return reader.read_multi(paths);
}
else
{
return reader.read(paths);
}
}
}

View file

@ -1,7 +1,7 @@
<!DOCTYPE Map>
<Map background-color="white" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<MarkersSymbolizer stroke="green" stroke-width="1.3" fill="yellow"/>
<LineSymbolizer stroke-width=".2" stroke="grey"/>
</Rule>

View file

@ -2,31 +2,31 @@
<Map background-color="white" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([name]='CHILE')</Filter>
<MarkersSymbolizer fill="darkgreen" opacity=".7" width="15" height="10" stroke="green" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Australia')</Filter>
<MarkersSymbolizer fill="darkblue" opacity=".7" width="10" height="20" stroke="blue" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil')</Filter>
<MarkersSymbolizer fill="darkorange" opacity=".7" width="20" height="10" stroke="orange" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Mongolia')</Filter>
<MarkersSymbolizer fill="darkgoldenrod" opacity=".7" width="25" height="10" stroke="yellow" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Sudan')</Filter>
<MarkersSymbolizer fill="darkcyan" opacity=".7" width="15" height="10" stroke="cadetblue" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='United States')</Filter>
<MarkersSymbolizer fill="#cc3344" opacity=".7" width="15" height="10" stroke="#cc3344" stroke-width="7" stroke-opacity=".2" placement="point" marker-type="ellipse"/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<PointSymbolizer file="../svg/ellipses.svg"/>
</Rule>

View file

@ -1,17 +1,17 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([x]=0)</Filter>
<TextSymbolizer size="10" dy="-10" face-name="DejaVu Sans Book" halo-radius="1" allow-overlap="true">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([y]=0)</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="-5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>

View file

@ -1,17 +1,17 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([x]=0)</Filter>
<TextSymbolizer size="10" dy="-10" face-name="DejaVu Sans Book" halo-radius="1" allow-overlap="true">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([y]=0)</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="-5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>

View file

@ -1,17 +1,17 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([x]=0)</Filter>
<TextSymbolizer size="10" dy="-10" face-name="DejaVu Sans Book" halo-radius="1" allow-overlap="true">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([y]=0)</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="-5" face-name="DejaVu Sans Book" halo-radius="1">[label]</TextSymbolizer>
<PointSymbolizer/>

View file

@ -1,38 +1,38 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo">
<Rule>
<Filter>([name]='CHILE')</Filter>
<TextSymbolizer size="10" dy="5" face-name="DejaVu Sans Book" text-transform="lowercase" wrap-width="10" wrap-character=" " halo-radius="1">[name] + ' (default OGC pixel)'</TextSymbolizer>
<PointSymbolizer/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Australia')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (png)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.png" allow-overlap="true"/>
</Rule>
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (svg &amp; tif)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.tif" allow-overlap="true"/>
<PointSymbolizer file="../svg/ellipses.svg" allow-overlap="true"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Mongolia')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (tiff)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.tiff" allow-overlap="true"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Sudan')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (jpeg)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.jpeg"/>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='United States')</Filter>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name] + ' (jpg)'</TextSymbolizer>
<PointSymbolizer file="../images/dummy.jpg"/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="10" dy="20" face-name="DejaVu Sans Book" halo-radius="1">[name]</TextSymbolizer>
<PointSymbolizer file="../images/bogus_will_fail.png"/>

View file

@ -1,11 +1,11 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil' or [name]='Mongolia' or [name]='Sudan')</Filter>
<PointSymbolizer file="../svg/point_sm.svg" allow-overlap="true"/>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<PointSymbolizer file="../svg/point_sm.svg" ignore-placement="true"/>
<PointSymbolizer/>

View file

@ -1,26 +1,26 @@
<!DOCTYPE Map>
<Map background-color="#b5d0d0" minimum-version="0.7.2">
<Style name="test">
<Rule title="asia">
<Rule name="asia">
<Filter>([REGION]=142)</Filter>
<PointSymbolizer file="../images/dummy.png" allow-overlap="true"/>
</Rule>
<Rule title="europe">
<Rule name="europe">
<Filter>([REGION]=150)</Filter>
<!-- requires at least Mapnik 0.7.1 to work due to http://trac.mapnik.org/ticket/508 -->
<PolygonPatternSymbolizer file="../images/dummy.png"/>
</Rule>
<Rule title="americas">
<Rule name="americas">
<Filter>([REGION]=19)</Filter>
<!-- requires at least Mapnik 0.7.1 to work due to http://trac.mapnik.org/ticket/508 -->
<LinePatternSymbolizer file="../images/dummy.png"/>
</Rule>
<Rule title="Africa">
<Rule name="Africa">
<Filter>([REGION]=2)</Filter>
<ShieldSymbolizer placement="vertex" size="10" fill="#000000" file="../images/dummy.png" face-name="DejaVu Sans Bold">[NAME]</ShieldSymbolizer>
</Rule>
<Rule title="rest">
<Rule name="rest">
<ElseFilter/>
<LineSymbolizer stroke-width="1"/>
</Rule>

View file

@ -1,31 +1,31 @@
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" background-color="steelblue" minimum-version="0.7.2">
<Style name="labels">
<Rule title="foo">
<Rule>
<Filter>([name]='CHILE')</Filter>
<TextSymbolizer size="15" orientation="45" face-name="DejaVu Sans Book" halo-radius="1">'45˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Australia')</Filter>
<TextSymbolizer size="15" orientation="-45" face-name="DejaVu Sans Book" halo-radius="1">'- 45˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo1">
<Rule>
<Filter>([name]='Brazil')</Filter>
<TextSymbolizer size="15" orientation="90" face-name="DejaVu Sans Book" halo-radius="1">'90˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='Mongolia')</Filter>
<TextSymbolizer size="15" orientation="-90" face-name="DejaVu Sans Book" halo-radius="1">'- 90˚ angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='South Sudan')</Filter>
<TextSymbolizer size="15" orientation="180" face-name="DejaVu Sans Book" halo-radius="1">'180&#730; angle'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<Filter>([name]='United States')</Filter>
<TextSymbolizer size="15" face-name="DejaVu Sans Book" halo-radius="1">'no rotation of text'</TextSymbolizer>
</Rule>
<Rule title="foo">
<Rule>
<ElseFilter/>
<TextSymbolizer size="15" face-name="DejaVu Sans Book" halo-radius="1">[name]</TextSymbolizer>
</Rule>

View file

@ -213,12 +213,10 @@ def test_layer_init():
eq_(l.clear_label_cache,False)
eq_(l.cache_features,False)
eq_(l.visible(1),True)
eq_(l.abstract,'')
eq_(l.active,True)
eq_(l.datasource,None)
eq_(l.queryable,False)
eq_(l.srs,'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
eq_(l.title,'')
# Map initialization
def test_map_init():
@ -399,7 +397,6 @@ def test_rule_init():
r = mapnik.Rule()
eq_(r.name, '')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
@ -420,34 +417,30 @@ def test_rule_init():
r = mapnik.Rule("Name")
eq_(r.name, 'Name')
eq_(r.title, '')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
eq_(r.has_also(), False)
r = mapnik.Rule("Name", "Title")
r = mapnik.Rule("Name")
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, 0)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
eq_(r.has_also(), False)
r = mapnik.Rule("Name", "Title", min_scale)
r = mapnik.Rule("Name", min_scale)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, min_scale)
eq_(r.max_scale, float('inf'))
eq_(r.has_else(), False)
eq_(r.has_also(), False)
r = mapnik.Rule("Name", "Title", min_scale, max_scale)
r = mapnik.Rule("Name", min_scale, max_scale)
eq_(r.name, 'Name')
eq_(r.title, 'Title')
eq_(r.min_scale, min_scale)
eq_(r.max_scale, max_scale)
eq_(r.has_else(), False)

View file

@ -83,6 +83,9 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
table='(select * from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3 limit 100)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
fs = ds.featureset()
feature = fs.next()
eq_(feature.id(),1)
@ -126,6 +129,71 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
#import pdb;pdb.set_trace()
print 'invalid key/v %s/%s for: %s' % (k,v,feature)
def test_attachdb_with_sql_join_count():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3 limit 100)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),100)
def test_attachdb_with_sql_join_count2():
'''
sqlite3 world.sqlite
attach database 'business.sqlite' as business;
select count(*) from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),192)
def test_attachdb_with_sql_join_count3():
'''
select count(*) from (select * from world_merc where 1=1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from (select * from world_merc where !intersects!) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),192)
def test_attachdb_with_sql_join_count4():
'''
select count(*) from (select * from world_merc where 1=1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from (select * from world_merc where !intersects! limit 1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
eq_(len(ds.fields()),29)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat', 'ISO3:1', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'])
eq_(len(ds.all_features()),1)
def test_attachdb_with_sql_join_count5():
'''
select count(*) from (select * from world_merc where 1=1) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3;
'''
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select * from (select * from world_merc where !intersects! and 1=2) as world_merc INNER JOIN business on world_merc.iso3 = business.ISO3)',
attachdb='busines@business.sqlite'
)
# nothing is able to join to business so we don't pick up business schema
eq_(len(ds.fields()),12)
eq_(ds.fields(),['OGC_FID', 'fips', 'iso2', 'iso3', 'un', 'name', 'area', 'pop2005', 'region', 'subregion', 'lon', 'lat'])
eq_(ds.field_types(),['int', 'str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float'])
eq_(len(ds.all_features()),0)
def test_subqueries():
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='world_merc',
@ -179,14 +247,16 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
eq_(feature['OGC_FID'],1)
eq_(feature['fips'],u'AC')
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select GEOMETRY,rowid as aliased_id,fips from world_merc)',
key_field='aliased_id'
)
fs = ds.featureset()
feature = fs.next()
eq_(feature['aliased_id'],1)
eq_(feature['fips'],u'AC')
# same as above, except with alias like postgres requires
# TODO - should we try to make this work?
#ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
# table='(select GEOMETRY,rowid as aliased_id,fips from world_merc) as table',
# key_field='aliased_id'
# )
#fs = ds.featureset()
#feature = fs.next()
#eq_(feature['aliased_id'],1)
#eq_(feature['fips'],u'AC')
ds = mapnik.SQLite(file='../data/sqlite/world.sqlite',
table='(select GEOMETRY,OGC_FID,OGC_FID as rowid,fips from world_merc)',
@ -220,6 +290,31 @@ if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
query.add_property_name('bogus')
fs = ds.features(query)
def test_intersects_token1():
ds = mapnik.SQLite(file='../data/sqlite/empty.db',
table='(select * from empty where !intersects!)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
def test_intersects_token1():
ds = mapnik.SQLite(file='../data/sqlite/empty.db',
table='(select * from empty where "a"!="b" and !intersects!)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
def test_intersects_token1():
ds = mapnik.SQLite(file='../data/sqlite/empty.db',
table='(select * from empty where "a"!="b" and !intersects!)',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]

View file

@ -47,27 +47,6 @@
namespace mapnik {
/*
struct blob_to_hex
{
std::string operator() (const char* blob, unsigned size)
{
std::string buf;
buf.reserve(size*2);
std::ostringstream s(buf);
s.seekp(0);
char hex[3];
std::memset(hex,0,3);
for ( unsigned pos=0; pos < size; ++pos)
{
std::sprintf (hex, "%02X", int(blob[pos]) & 0xff);
s << hex;
}
return s.str();
}
};
*/
template <typename Connection>
void pgsql2sqlite(Connection conn,
std::string const& query,
@ -297,7 +276,7 @@ void pgsql2sqlite(Connection conn,
if (oid == geometry_oid)
{
mapnik::Feature feat(pkid);
geometry_utils::from_wkb(feat.paths(),buf,size,false,wkbGeneric);
geometry_utils::from_wkb(feat.paths(),buf,size,wkbGeneric);
if (feat.num_geometries() > 0)
{
geometry_type const& geom=feat.get_geometry(0);
@ -316,8 +295,6 @@ void pgsql2sqlite(Connection conn,
empty_geom = false;
}
}
//output_rec.push_back(sqlite::value_type("X'" + hex(buf,size) + "'"));
output_rec.push_back(sqlite::blob(buf,size));
}
else

View file

@ -69,7 +69,6 @@
<!ELEMENT Layer (StyleName|Datasource)*>
<!-- FIXME: queryable true/false ? -->
<!ATTLIST Layer
abstract CDATA #IMPLIED
clear_label_cache (yes|1|no|0) #IMPLIED
minzoom CDATA "0"
maxzoom CDATA #IMPLIED
@ -77,7 +76,6 @@
queryable (true|on|1|false|off|0) "0"
srs CDATA #IMPLIED
status (on|1|off|0) "1"
title CDATA ""
tolerance CDATA #IMPLIED
toleranceunits CDATA #IMPLIED
>
@ -90,7 +88,6 @@
<!-- FIXME: MapnikXMLDescription.pdf specified name is required? -->
<!ATTLIST Rule
name CDATA #IMPLIED
title CDATA #IMPLIED
>
<!ELEMENT Filter (#PCDATA)>