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,12 +209,8 @@ feature_ptr postgis_featureset::next()
}
return feature;
}
else
{
rs_->close();
return feature_ptr();
}
}
postgis_featureset::~postgis_featureset()

View file

@ -522,7 +522,8 @@ 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);
if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto))
{
mapnik::util::to_ds_type(paths,result);
if (result)
{
@ -537,6 +538,7 @@ boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_
}
}
}
}
return result;
}

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,11 +190,11 @@ public:
if (data)
{
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();
if (bbox.valid())
{
if (first)
@ -211,6 +211,7 @@ public:
}
}
}
}
static bool create_spatial_index(std::string const& index_db,
std::string const& index_table,
@ -276,8 +277,9 @@ public:
if (data)
{
boost::ptr_vector<mapnik::geometry_type> paths;
mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto);
mapnik::box2d<double> bbox;
if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto))
{
for (unsigned i=0; i<paths.size(); ++i)
{
if (i==0)
@ -289,11 +291,10 @@ public:
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,13 +364,13 @@ public:
if (data)
{
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();
if (bbox.valid())
{
const int type_oid = rs->column_type(1);
if (type_oid != SQLITE_INTEGER)
{
@ -381,14 +380,11 @@ public:
<< "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
{
@ -401,8 +397,7 @@ public:
}
}
}
}
static bool create_spatial_index2(std::string const& index_db,
std::string const& index_table,

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();