Compare commits

...

2 commits

Author SHA1 Message Date
Dane Springmeyer
0219a54726 Merge branch 'master' of github.com:mapnik/mapnik into optional-extent 2013-07-24 13:26:43 -04:00
Dane Springmeyer
517bd42f28 work in progress branch on moving datasource->extent to boost::optional 2013-02-21 19:51:48 -08:00
18 changed files with 72 additions and 54 deletions

View file

@ -284,7 +284,7 @@ void export_geometry()
using mapnik::geometry_type;
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("type",&geometry_type::type)
.def("to_wkb",&to_wkb)

View file

@ -111,7 +111,7 @@ public:
virtual datasource_t type() 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 box2d<double> envelope() const = 0;
virtual boost::optional<box2d<double> > envelope() const = 0;
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
virtual layer_descriptor get_descriptor() const = 0;
virtual ~datasource() {}

View file

@ -254,7 +254,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
buffered_query_ext.clip(*maximum_extent);
}
box2d<double> layer_ext = lay.envelope();
box2d<double> layer_ext = *lay.envelope();
bool fw_success = 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);
}
box2d<double> layer_ext2 = lay.envelope();
box2d<double> layer_ext2 = *lay.envelope();
if (fw_success)
{
if (prj_trans.forward(query_ext, PROJ_ENVELOPE_POINTS))

View file

@ -53,16 +53,19 @@ private:
container_type cont_;
eGeomType type_;
mutable unsigned itr_;
mutable box2d<double> extent_;
public:
geometry()
: type_(Unknown),
itr_(0)
itr_(0),
extent_()
{}
explicit geometry(eGeomType type)
: type_(type),
itr_(0)
itr_(0),
extent_()
{}
eGeomType type() const
@ -85,9 +88,17 @@ public:
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 y = 0;
rewind(0);
@ -97,14 +108,14 @@ public:
if (cmd == SEG_CLOSE) continue;
if (i == 0)
{
result.init(x,y,x,y);
extent_.init(x,y,x,y);
}
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)

View file

@ -189,7 +189,7 @@ public:
/*!
* @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);
boost::optional<box2d<double> > const& maximum_extent() const;

View file

@ -27,6 +27,9 @@
#include <mapnik/datasource.hpp>
#include <mapnik/feature_layer_desc.hpp>
// boost
#include <boost/optional.hpp>
// stl
#include <deque>
@ -43,7 +46,7 @@ public:
featureset_ptr features(query const& q) const;
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
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;
layer_descriptor get_descriptor() const;
size_t size() const;

View file

@ -882,9 +882,9 @@ datasource::datasource_t csv_datasource::type() const
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

View file

@ -50,7 +50,7 @@ public:
static const char * name();
mapnik::featureset_ptr features(mapnik::query const& q) 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;
mapnik::layer_descriptor get_descriptor() const;

View file

@ -783,11 +783,13 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double t
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_)
{
return extent_;
ext.reset(extent_);
return ext;
}
shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
@ -798,12 +800,10 @@ box2d<double> postgis_datasource::envelope() const
if (conn->isOK())
{
std::ostringstream s;
if (geometryColumn_.empty())
{
std::ostringstream s_error;
s_error << "PostGIS: unable to query the layer extent of table '";
if (! schema_.empty())
{
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)"
<< " FROM (SELECT ST_Estimated_Extent('";
if (! schema_.empty())
{
s << mapnik::sql_utils::unquote_double(schema_) << "','";
}
s << mapnik::sql_utils::unquote_double(geometry_table_) << "','"
<< 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)"
<< " FROM (SELECT ST_Extent(" <<geometryColumn_<< ") as ext from ";
if (extent_from_subquery_)
{
// 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_initialized_ = true;
ext.reset(extent_);
}
else
{
@ -873,8 +871,7 @@ box2d<double> postgis_datasource::envelope() const
rs->close();
}
}
return extent_;
return ext;
}
boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry_type() const

View file

@ -66,7 +66,7 @@ public:
static const char * name();
featureset_ptr features(const query& q) 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;
layer_descriptor get_descriptor() const;

View file

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

View file

@ -59,7 +59,7 @@ public:
static const char * name();
featureset_ptr features(const query& q) 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;
layer_descriptor get_descriptor() const;

View file

@ -42,9 +42,9 @@ mapnik::datasource::datasource_t hello_datasource::type() const
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

View file

@ -43,7 +43,7 @@ public:
// mandatory: return the box2d of the datasource
// 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
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;

View file

@ -209,11 +209,14 @@ void layer::reset_buffer_size()
buffer_size_.reset();
}
box2d<double> layer::envelope() const
boost::optional<box2d<double> > layer::envelope() const
{
if (ds_) return ds_->envelope();
return box2d<double>();
boost::optional<box2d<double> > ext;
if (ds_)
{
return ds_->envelope();
}
return ext;
}
void layer::set_clear_label_cache(bool clear)

View file

@ -374,11 +374,14 @@ void Map::zoom_all()
while (itr != end)
{
if (itr->active())
{
boost::optional<box2d<double> > layer_envelope = itr->envelope();
if (layer_envelope)
{
std::string const& layer_srs = itr->srs();
projection proj1(layer_srs);
proj_transform prj_trans(proj0,proj1);
box2d<double> layer_ext = itr->envelope();
box2d<double> layer_ext = *layer_envelope;
if (prj_trans.backward(layer_ext, PROJ_ENVELOPE_POINTS))
{
success = true;
@ -395,6 +398,7 @@ void Map::zoom_all()
}
}
}
}
++itr;
}
if (success)

View file

@ -100,14 +100,14 @@ void memory_datasource::set_envelope(box2d<double> const& box)
extent_ = box;
}
box2d<double> memory_datasource::envelope() const
boost::optional<box2d<double> > memory_datasource::envelope() const
{
if (!extent_.valid())
{
accumulate_extent func(extent_);
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

View file

@ -10,7 +10,7 @@ def test_layer_init():
l = mapnik.Layer('test')
eq_(l.name,'test')
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.cache_features,False)
eq_(l.visible(1),True)