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");
}
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)

View file

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

View file

@ -117,10 +117,10 @@ feature_ptr geos_featureset::next()
{
feature_ptr feature(feature_factory::create(ctx_,identifier_));
geometry_utils::from_wkb(feature->paths(),
if (geometry_utils::from_wkb(feature->paths(),
wkb.data(),
wkb.size());
if (field_ != "")
wkb.size())
&& field_ != "")
{
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()
{
if (rs_->next())
while (rs_->next())
{
// new feature
unsigned pos = 1;
@ -107,7 +107,9 @@ 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);
if (!geometry_utils::from_wkb(feature->paths(), data, size))
continue;
totalGeomSize_ += size;
int num_attrs = ctx_->size() + 1;
@ -207,11 +209,7 @@ feature_ptr postgis_featureset::next()
}
return feature;
}
else
{
rs_->close();
return feature_ptr();
}
return feature_ptr();
}

View file

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

View file

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

View file

@ -431,13 +431,17 @@ private:
#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,
unsigned size,
wkbFormat format)
{
unsigned geom_count = paths.size();
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)
{
mapnik::Feature feat(ctx,pkid);
geometry_utils::from_wkb(feat.paths(),buf,size,wkbGeneric);
if (feat.num_geometries() > 0)
if (geometry_utils::from_wkb(feat.paths(),buf,size,wkbGeneric)
&& feat.num_geometries() > 0)
{
geometry_type const& geom=feat.get_geometry(0);
box2d<double> bbox = geom.envelope();