Compare commits
2 commits
master
...
optional-e
Author | SHA1 | Date | |
---|---|---|---|
|
0219a54726 | ||
|
517bd42f28 |
18 changed files with 72 additions and 54 deletions
|
@ -284,7 +284,7 @@ void export_geometry()
|
||||||
|
|
||||||
using mapnik::geometry_type;
|
using mapnik::geometry_type;
|
||||||
class_<geometry_type, std::auto_ptr<geometry_type>, boost::noncopyable>("Geometry2d",no_init)
|
class_<geometry_type, std::auto_ptr<geometry_type>, boost::noncopyable>("Geometry2d",no_init)
|
||||||
.def("envelope",&geometry_type::envelope)
|
//.def("envelope",&geometry_type::envelope)
|
||||||
// .def("__str__",&geometry_type::to_string)
|
// .def("__str__",&geometry_type::to_string)
|
||||||
.def("type",&geometry_type::type)
|
.def("type",&geometry_type::type)
|
||||||
.def("to_wkb",&to_wkb)
|
.def("to_wkb",&to_wkb)
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
virtual datasource_t type() const = 0;
|
virtual datasource_t type() const = 0;
|
||||||
virtual featureset_ptr features(query const& q) const = 0;
|
virtual featureset_ptr features(query const& q) const = 0;
|
||||||
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
|
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
|
||||||
virtual box2d<double> envelope() const = 0;
|
virtual boost::optional<box2d<double> > envelope() const = 0;
|
||||||
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
|
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
|
||||||
virtual layer_descriptor get_descriptor() const = 0;
|
virtual layer_descriptor get_descriptor() const = 0;
|
||||||
virtual ~datasource() {}
|
virtual ~datasource() {}
|
||||||
|
|
|
@ -254,7 +254,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
|
||||||
buffered_query_ext.clip(*maximum_extent);
|
buffered_query_ext.clip(*maximum_extent);
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> layer_ext = lay.envelope();
|
box2d<double> layer_ext = *lay.envelope();
|
||||||
bool fw_success = false;
|
bool fw_success = false;
|
||||||
bool early_return = false;
|
bool early_return = false;
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
|
||||||
query_ext.clip(*maximum_extent);
|
query_ext.clip(*maximum_extent);
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> layer_ext2 = lay.envelope();
|
box2d<double> layer_ext2 = *lay.envelope();
|
||||||
if (fw_success)
|
if (fw_success)
|
||||||
{
|
{
|
||||||
if (prj_trans.forward(query_ext, PROJ_ENVELOPE_POINTS))
|
if (prj_trans.forward(query_ext, PROJ_ENVELOPE_POINTS))
|
||||||
|
|
|
@ -53,16 +53,19 @@ private:
|
||||||
container_type cont_;
|
container_type cont_;
|
||||||
eGeomType type_;
|
eGeomType type_;
|
||||||
mutable unsigned itr_;
|
mutable unsigned itr_;
|
||||||
|
mutable box2d<double> extent_;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
geometry()
|
geometry()
|
||||||
: type_(Unknown),
|
: type_(Unknown),
|
||||||
itr_(0)
|
itr_(0),
|
||||||
|
extent_()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
explicit geometry(eGeomType type)
|
explicit geometry(eGeomType type)
|
||||||
: type_(type),
|
: type_(type),
|
||||||
itr_(0)
|
itr_(0),
|
||||||
|
extent_()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
eGeomType type() const
|
eGeomType type() const
|
||||||
|
@ -85,9 +88,17 @@ public:
|
||||||
return cont_.size();
|
return cont_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> envelope() const
|
void set_extent(box2d<double> const& box)
|
||||||
{
|
{
|
||||||
box2d<double> result;
|
return extent_ = box;
|
||||||
|
}
|
||||||
|
|
||||||
|
box2d<double> const& envelope() const
|
||||||
|
{
|
||||||
|
if (extent_.valid())
|
||||||
|
{
|
||||||
|
return extent_;
|
||||||
|
}
|
||||||
double x = 0;
|
double x = 0;
|
||||||
double y = 0;
|
double y = 0;
|
||||||
rewind(0);
|
rewind(0);
|
||||||
|
@ -97,14 +108,14 @@ public:
|
||||||
if (cmd == SEG_CLOSE) continue;
|
if (cmd == SEG_CLOSE) continue;
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
result.init(x,y,x,y);
|
extent_.init(x,y,x,y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.expand_to_include(x,y);
|
extent_.expand_to_include(x,y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return extent_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_vertex(coord_type x, coord_type y, CommandType c)
|
void push_vertex(coord_type x, coord_type y, CommandType c)
|
||||||
|
|
|
@ -189,7 +189,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
* @return the geographic envelope/bounding box of the data in the layer.
|
* @return the geographic envelope/bounding box of the data in the layer.
|
||||||
*/
|
*/
|
||||||
box2d<double> envelope() const;
|
boost::optional<box2d<double> > envelope() const;
|
||||||
|
|
||||||
void set_maximum_extent(box2d<double> const& box);
|
void set_maximum_extent(box2d<double> const& box);
|
||||||
boost::optional<box2d<double> > const& maximum_extent() const;
|
boost::optional<box2d<double> > const& maximum_extent() const;
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
#include <mapnik/datasource.hpp>
|
#include <mapnik/datasource.hpp>
|
||||||
#include <mapnik/feature_layer_desc.hpp>
|
#include <mapnik/feature_layer_desc.hpp>
|
||||||
|
|
||||||
|
// boost
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
|
@ -43,7 +46,7 @@ public:
|
||||||
featureset_ptr features(query const& q) const;
|
featureset_ptr features(query const& q) const;
|
||||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||||
void set_envelope(box2d<double> const& box);
|
void set_envelope(box2d<double> const& box);
|
||||||
box2d<double> envelope() const;
|
boost::optional<box2d<double> > envelope() const;
|
||||||
boost::optional<geometry_t> get_geometry_type() const;
|
boost::optional<geometry_t> get_geometry_type() const;
|
||||||
layer_descriptor get_descriptor() const;
|
layer_descriptor get_descriptor() const;
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
|
|
|
@ -882,9 +882,9 @@ datasource::datasource_t csv_datasource::type() const
|
||||||
return datasource::Vector;
|
return datasource::Vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapnik::box2d<double> csv_datasource::envelope() const
|
boost::optional<mapnik::box2d<double> > csv_datasource::envelope() const
|
||||||
{
|
{
|
||||||
return extent_;
|
return boost::optional<mapnik::box2d<double> >(extent_);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_type() const
|
boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_type() const
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
static const char * name();
|
static const char * name();
|
||||||
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, double tol = 0) const;
|
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||||
mapnik::box2d<double> envelope() const;
|
boost::optional<mapnik::box2d<double> > envelope() const;
|
||||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||||
mapnik::layer_descriptor get_descriptor() const;
|
mapnik::layer_descriptor get_descriptor() const;
|
||||||
|
|
||||||
|
|
|
@ -783,11 +783,13 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double t
|
||||||
return featureset_ptr();
|
return featureset_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> postgis_datasource::envelope() const
|
boost::optional<box2d<double> > postgis_datasource::envelope() const
|
||||||
{
|
{
|
||||||
|
boost::optional<box2d<double> > ext;
|
||||||
if (extent_initialized_)
|
if (extent_initialized_)
|
||||||
{
|
{
|
||||||
return extent_;
|
ext.reset(extent_);
|
||||||
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
|
shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
|
||||||
|
@ -798,12 +800,10 @@ box2d<double> postgis_datasource::envelope() const
|
||||||
if (conn->isOK())
|
if (conn->isOK())
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
|
||||||
if (geometryColumn_.empty())
|
if (geometryColumn_.empty())
|
||||||
{
|
{
|
||||||
std::ostringstream s_error;
|
std::ostringstream s_error;
|
||||||
s_error << "PostGIS: unable to query the layer extent of table '";
|
s_error << "PostGIS: unable to query the layer extent of table '";
|
||||||
|
|
||||||
if (! schema_.empty())
|
if (! schema_.empty())
|
||||||
{
|
{
|
||||||
s_error << schema_ << ".";
|
s_error << schema_ << ".";
|
||||||
|
@ -820,12 +820,10 @@ box2d<double> postgis_datasource::envelope() const
|
||||||
{
|
{
|
||||||
s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)"
|
s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)"
|
||||||
<< " FROM (SELECT ST_Estimated_Extent('";
|
<< " FROM (SELECT ST_Estimated_Extent('";
|
||||||
|
|
||||||
if (! schema_.empty())
|
if (! schema_.empty())
|
||||||
{
|
{
|
||||||
s << mapnik::sql_utils::unquote_double(schema_) << "','";
|
s << mapnik::sql_utils::unquote_double(schema_) << "','";
|
||||||
}
|
}
|
||||||
|
|
||||||
s << mapnik::sql_utils::unquote_double(geometry_table_) << "','"
|
s << mapnik::sql_utils::unquote_double(geometry_table_) << "','"
|
||||||
<< mapnik::sql_utils::unquote_double(geometryColumn_) << "') as ext) as tmp";
|
<< mapnik::sql_utils::unquote_double(geometryColumn_) << "') as ext) as tmp";
|
||||||
}
|
}
|
||||||
|
@ -833,7 +831,6 @@ box2d<double> postgis_datasource::envelope() const
|
||||||
{
|
{
|
||||||
s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)"
|
s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)"
|
||||||
<< " FROM (SELECT ST_Extent(" <<geometryColumn_<< ") as ext from ";
|
<< " FROM (SELECT ST_Extent(" <<geometryColumn_<< ") as ext from ";
|
||||||
|
|
||||||
if (extent_from_subquery_)
|
if (extent_from_subquery_)
|
||||||
{
|
{
|
||||||
// if a subselect limits records then calculating the extent upon the
|
// if a subselect limits records then calculating the extent upon the
|
||||||
|
@ -864,6 +861,7 @@ box2d<double> postgis_datasource::envelope() const
|
||||||
{
|
{
|
||||||
extent_.init(lox, loy, hix, hiy);
|
extent_.init(lox, loy, hix, hiy);
|
||||||
extent_initialized_ = true;
|
extent_initialized_ = true;
|
||||||
|
ext.reset(extent_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -873,8 +871,7 @@ box2d<double> postgis_datasource::envelope() const
|
||||||
rs->close();
|
rs->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ext;
|
||||||
return extent_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry_type() const
|
boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry_type() const
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
static const char * name();
|
static const char * name();
|
||||||
featureset_ptr features(const query& q) const;
|
featureset_ptr features(const query& q) const;
|
||||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||||
mapnik::box2d<double> envelope() const;
|
boost::optional<box2d<double> > envelope() const;
|
||||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||||
layer_descriptor get_descriptor() const;
|
layer_descriptor get_descriptor() const;
|
||||||
|
|
||||||
|
|
|
@ -297,9 +297,9 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> shape_datasource::envelope() const
|
boost::optional<box2d<double> > shape_datasource::envelope() const
|
||||||
{
|
{
|
||||||
return extent_;
|
return boost::optional<box2d<double> >(extent_);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<mapnik::datasource::geometry_t> shape_datasource::get_geometry_type() const
|
boost::optional<mapnik::datasource::geometry_t> shape_datasource::get_geometry_type() const
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
static const char * name();
|
static const char * name();
|
||||||
featureset_ptr features(const query& q) const;
|
featureset_ptr features(const query& q) const;
|
||||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||||
box2d<double> envelope() const;
|
boost::optional<box2d<double> > envelope() const;
|
||||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||||
layer_descriptor get_descriptor() const;
|
layer_descriptor get_descriptor() const;
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,9 @@ mapnik::datasource::datasource_t hello_datasource::type() const
|
||||||
return datasource::Vector;
|
return datasource::Vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapnik::box2d<double> hello_datasource::envelope() const
|
boost::optional<mapnik::box2d<double> > hello_datasource::envelope() const
|
||||||
{
|
{
|
||||||
return extent_;
|
return boost::optional<mapnik::box2d<double> >(extent_);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<mapnik::datasource::geometry_t> hello_datasource::get_geometry_type() const
|
boost::optional<mapnik::datasource::geometry_t> hello_datasource::get_geometry_type() const
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
|
|
||||||
// mandatory: return the box2d of the datasource
|
// mandatory: return the box2d of the datasource
|
||||||
// called during rendering to determine if the layer should be processed
|
// called during rendering to determine if the layer should be processed
|
||||||
mapnik::box2d<double> envelope() const;
|
boost::optional<mapnik::box2d<double> > envelope() const;
|
||||||
|
|
||||||
// mandatory: optionally return the overal geometry type of the datasource
|
// mandatory: optionally return the overal geometry type of the datasource
|
||||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||||
|
|
|
@ -209,11 +209,14 @@ void layer::reset_buffer_size()
|
||||||
buffer_size_.reset();
|
buffer_size_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::optional<box2d<double> > layer::envelope() const
|
||||||
box2d<double> layer::envelope() const
|
|
||||||
{
|
{
|
||||||
if (ds_) return ds_->envelope();
|
boost::optional<box2d<double> > ext;
|
||||||
return box2d<double>();
|
if (ds_)
|
||||||
|
{
|
||||||
|
return ds_->envelope();
|
||||||
|
}
|
||||||
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void layer::set_clear_label_cache(bool clear)
|
void layer::set_clear_label_cache(bool clear)
|
||||||
|
|
34
src/map.cpp
34
src/map.cpp
|
@ -375,23 +375,27 @@ void Map::zoom_all()
|
||||||
{
|
{
|
||||||
if (itr->active())
|
if (itr->active())
|
||||||
{
|
{
|
||||||
std::string const& layer_srs = itr->srs();
|
boost::optional<box2d<double> > layer_envelope = itr->envelope();
|
||||||
projection proj1(layer_srs);
|
if (layer_envelope)
|
||||||
proj_transform prj_trans(proj0,proj1);
|
|
||||||
box2d<double> layer_ext = itr->envelope();
|
|
||||||
if (prj_trans.backward(layer_ext, PROJ_ENVELOPE_POINTS))
|
|
||||||
{
|
{
|
||||||
success = true;
|
std::string const& layer_srs = itr->srs();
|
||||||
MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " original ext=" << itr->envelope();
|
projection proj1(layer_srs);
|
||||||
MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " transformed to map srs=" << layer_ext;
|
proj_transform prj_trans(proj0,proj1);
|
||||||
if (first)
|
box2d<double> layer_ext = *layer_envelope;
|
||||||
|
if (prj_trans.backward(layer_ext, PROJ_ENVELOPE_POINTS))
|
||||||
{
|
{
|
||||||
ext = layer_ext;
|
success = true;
|
||||||
first = false;
|
MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " original ext=" << itr->envelope();
|
||||||
}
|
MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " transformed to map srs=" << layer_ext;
|
||||||
else
|
if (first)
|
||||||
{
|
{
|
||||||
ext.expand_to_include(layer_ext);
|
ext = layer_ext;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ext.expand_to_include(layer_ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,14 +100,14 @@ void memory_datasource::set_envelope(box2d<double> const& box)
|
||||||
extent_ = box;
|
extent_ = box;
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> memory_datasource::envelope() const
|
boost::optional<box2d<double> > memory_datasource::envelope() const
|
||||||
{
|
{
|
||||||
if (!extent_.valid())
|
if (!extent_.valid())
|
||||||
{
|
{
|
||||||
accumulate_extent func(extent_);
|
accumulate_extent func(extent_);
|
||||||
std::for_each(features_.begin(),features_.end(),func);
|
std::for_each(features_.begin(),features_.end(),func);
|
||||||
}
|
}
|
||||||
return extent_;
|
return boost::optional<box2d<double> >(extent_);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<datasource::geometry_t> memory_datasource::get_geometry_type() const
|
boost::optional<datasource::geometry_t> memory_datasource::get_geometry_type() const
|
||||||
|
|
|
@ -10,7 +10,7 @@ def test_layer_init():
|
||||||
l = mapnik.Layer('test')
|
l = mapnik.Layer('test')
|
||||||
eq_(l.name,'test')
|
eq_(l.name,'test')
|
||||||
eq_(l.srs,'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
|
eq_(l.srs,'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
|
||||||
eq_(l.envelope(),mapnik.Box2d())
|
eq_(l.envelope(),None)
|
||||||
eq_(l.clear_label_cache,False)
|
eq_(l.clear_label_cache,False)
|
||||||
eq_(l.cache_features,False)
|
eq_(l.cache_features,False)
|
||||||
eq_(l.visible(1),True)
|
eq_(l.visible(1),True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue