change geometry_utils::from_wkb to return a bool that signifies if at least one wkb path was parsed - refs #1333 and #1305

This commit is contained in:
Dane Springmeyer 2012-07-20 15:09:01 -07:00
parent b0cb5b04de
commit e36081a5c0
9 changed files with 77 additions and 77 deletions

View file

@ -60,9 +60,9 @@ void add_wkt_impl(path_type& p, std::string const& wkt)
if (!result) throw std::runtime_error("Failed to parse WKT"); if (!result) throw std::runtime_error("Failed to parse WKT");
} }
void add_wkb_impl(path_type& p, std::string const& wkb) bool add_wkb_impl(path_type& p, std::string const& wkb)
{ {
mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size()); return mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size());
} }
boost::shared_ptr<path_type> from_wkt_impl(std::string const& wkt) boost::shared_ptr<path_type> from_wkt_impl(std::string const& wkt)

View file

@ -55,7 +55,7 @@ class MAPNIK_DECL geometry_utils : private boost::noncopyable
{ {
public: public:
static void from_wkb (boost::ptr_vector<geometry_type>& paths, static bool from_wkb (boost::ptr_vector<geometry_type>& paths,
const char* wkb, const char* wkb,
unsigned size, unsigned size,
wkbFormat format = wkbGeneric); wkbFormat format = wkbGeneric);

View file

@ -117,10 +117,10 @@ feature_ptr geos_featureset::next()
{ {
feature_ptr feature(feature_factory::create(ctx_,identifier_)); feature_ptr feature(feature_factory::create(ctx_,identifier_));
geometry_utils::from_wkb(feature->paths(), if (geometry_utils::from_wkb(feature->paths(),
wkb.data(), wkb.data(),
wkb.size()); wkb.size())
if (field_ != "") && field_ != "")
{ {
feature->put(field_name_, tr_->transcode(field_.c_str())); feature->put(field_name_, tr_->transcode(field_.c_str()));
} }

View file

@ -62,7 +62,7 @@ postgis_featureset::postgis_featureset(boost::shared_ptr<IResultSet> const& rs,
feature_ptr postgis_featureset::next() feature_ptr postgis_featureset::next()
{ {
if (rs_->next()) while (rs_->next())
{ {
// new feature // new feature
unsigned pos = 1; unsigned pos = 1;
@ -107,7 +107,9 @@ feature_ptr postgis_featureset::next()
// parse geometry // parse geometry
int size = rs_->getFieldLength(0); int size = rs_->getFieldLength(0);
const char *data = rs_->getValue(0); const char *data = rs_->getValue(0);
geometry_utils::from_wkb(feature->paths(), data, size); if (!geometry_utils::from_wkb(feature->paths(), data, size))
continue;
totalGeomSize_ += size; totalGeomSize_ += size;
int num_attrs = ctx_->size() + 1; int num_attrs = ctx_->size() + 1;
@ -207,11 +209,7 @@ feature_ptr postgis_featureset::next()
} }
return feature; return feature;
} }
else return feature_ptr();
{
rs_->close();
return feature_ptr();
}
} }

View file

@ -522,17 +522,19 @@ boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_
if (data) if (data)
{ {
boost::ptr_vector<mapnik::geometry_type> paths; boost::ptr_vector<mapnik::geometry_type> paths;
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto); if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto))
mapnik::util::to_ds_type(paths,result);
if (result)
{ {
int type = static_cast<int>(*result); mapnik::util::to_ds_type(paths,result);
if (multi_type > 0 && multi_type != type) if (result)
{ {
result.reset(mapnik::datasource::Collection); int type = static_cast<int>(*result);
return result; if (multi_type > 0 && multi_type != type)
{
result.reset(mapnik::datasource::Collection);
return result;
}
multi_type = type;
} }
multi_type = type;
} }
} }
} }

View file

@ -75,7 +75,8 @@ feature_ptr sqlite_featureset::next()
} }
feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer(1)); feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer(1));
geometry_utils::from_wkb(feature->paths(), data, size, format_); if (!geometry_utils::from_wkb(feature->paths(), data, size, format_))
continue;
if (!spatial_index_) if (!spatial_index_)
{ {

View file

@ -190,21 +190,22 @@ public:
if (data) if (data)
{ {
boost::ptr_vector<mapnik::geometry_type> paths; boost::ptr_vector<mapnik::geometry_type> paths;
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto); if (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(); for (unsigned i=0; i<paths.size(); ++i)
if (bbox.valid())
{ {
if (first) mapnik::box2d<double> const& bbox = paths[i].envelope();
if (bbox.valid())
{ {
first = false; if (first)
extent = bbox; {
} first = false;
else extent = bbox;
{ }
extent.expand_to_include(bbox); else
{
extent.expand_to_include(bbox);
}
} }
} }
} }
@ -276,24 +277,24 @@ public:
if (data) if (data)
{ {
boost::ptr_vector<mapnik::geometry_type> paths; boost::ptr_vector<mapnik::geometry_type> paths;
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto);
mapnik::box2d<double> bbox; mapnik::box2d<double> bbox;
for (unsigned i=0; i<paths.size(); ++i) if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto))
{ {
if (i==0) for (unsigned i=0; i<paths.size(); ++i)
{ {
bbox = paths[i].envelope(); if (i==0)
} {
else bbox = paths[i].envelope();
{ }
bbox.expand_to_include(paths[i].envelope()); else
{
bbox.expand_to_include(paths[i].envelope());
}
} }
} }
if (bbox.valid()) if (bbox.valid())
{ {
ps.bind(bbox); ps.bind(bbox);
const int type_oid = rs->column_type(1); const int type_oid = rs->column_type(1);
if (type_oid != SQLITE_INTEGER) if (type_oid != SQLITE_INTEGER)
{ {
@ -303,7 +304,6 @@ public:
<< "' type was: " << type_oid << ""; << "' type was: " << type_oid << "";
throw mapnik::datasource_exception(error_msg.str()); throw mapnik::datasource_exception(error_msg.str());
} }
const sqlite_int64 pkid = rs->column_integer64(1); const sqlite_int64 pkid = rs->column_integer64(1);
ps.bind(pkid); ps.bind(pkid);
} }
@ -314,7 +314,6 @@ public:
<< rs->column_name(1) << "' == " << rs->column_integer64(1); << rs->column_name(1) << "' == " << rs->column_integer64(1);
throw mapnik::datasource_exception(error_msg.str()); throw mapnik::datasource_exception(error_msg.str());
} }
ps.step_next(); ps.step_next();
one_success = true; one_success = true;
} }
@ -365,45 +364,41 @@ public:
if (data) if (data)
{ {
boost::ptr_vector<mapnik::geometry_type> paths; boost::ptr_vector<mapnik::geometry_type> paths;
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto); if (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(); for (unsigned i=0; i<paths.size(); ++i)
if (bbox.valid())
{ {
mapnik::box2d<double> const& bbox = paths[i].envelope();
const int type_oid = rs->column_type(1); if (bbox.valid())
if (type_oid != SQLITE_INTEGER) {
const int type_oid = rs->column_type(1);
if (type_oid != SQLITE_INTEGER)
{
std::ostringstream error_msg;
error_msg << "Sqlite Plugin: invalid type for key field '"
<< rs->column_name(1) << "' when creating index "
<< "type was: " << type_oid << "";
throw mapnik::datasource_exception(error_msg.str());
}
const sqlite_int64 pkid = rs->column_integer64(1);
rtree_type entry = rtree_type();
entry.pkid = pkid;
entry.bbox = bbox;
rtree_list.push_back(entry);
}
else
{ {
std::ostringstream error_msg; std::ostringstream error_msg;
error_msg << "Sqlite Plugin: invalid type for key field '" error_msg << "SQLite Plugin: encountered invalid bbox at '"
<< rs->column_name(1) << "' when creating index " << rs->column_name(1) << "' == " << rs->column_integer64(1);
<< "type was: " << type_oid << "";
throw mapnik::datasource_exception(error_msg.str()); throw mapnik::datasource_exception(error_msg.str());
} }
const sqlite_int64 pkid = rs->column_integer64(1);
rtree_type entry = rtree_type();
entry.pkid = pkid;
entry.bbox = bbox;
rtree_list.push_back(entry);
}
else
{
std::ostringstream error_msg;
error_msg << "SQLite Plugin: encountered invalid bbox at '"
<< rs->column_name(1) << "' == " << rs->column_integer64(1);
throw mapnik::datasource_exception(error_msg.str());
} }
} }
} }
} }
} }
static bool create_spatial_index2(std::string const& index_db, static bool create_spatial_index2(std::string const& index_db,
std::string const& index_table, std::string const& index_table,
std::vector<rtree_type> const& rtree_list) std::vector<rtree_type> const& rtree_list)

View file

@ -431,13 +431,17 @@ private:
#endif #endif
}; };
void geometry_utils::from_wkb (boost::ptr_vector<geometry_type>& paths, bool geometry_utils::from_wkb(boost::ptr_vector<geometry_type>& paths,
const char* wkb, const char* wkb,
unsigned size, unsigned size,
wkbFormat format) wkbFormat format)
{ {
unsigned geom_count = paths.size();
wkb_reader reader(wkb, size, format); wkb_reader reader(wkb, size, format);
return reader.read(paths); reader.read(paths);
if (paths.size() > geom_count)
return true;
return false;
} }
} }

View file

@ -281,8 +281,8 @@ void pgsql2sqlite(Connection conn,
if (oid == geometry_oid) if (oid == geometry_oid)
{ {
mapnik::Feature feat(ctx,pkid); mapnik::Feature feat(ctx,pkid);
geometry_utils::from_wkb(feat.paths(),buf,size,wkbGeneric); if (geometry_utils::from_wkb(feat.paths(),buf,size,wkbGeneric)
if (feat.num_geometries() > 0) && feat.num_geometries() > 0)
{ {
geometry_type const& geom=feat.get_geometry(0); geometry_type const& geom=feat.get_geometry(0);
box2d<double> bbox = geom.envelope(); box2d<double> bbox = geom.envelope();