Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change geometry_utils::from_wkb to return a bool that signifies if at…

… least one wkb path was parsed - refs #1333 and #1305
  • Loading branch information...
commit e36081a5c08f67620afcde2cdf57d4742115546c 1 parent b0cb5b0
@springmeyer springmeyer authored
View
4 bindings/python/mapnik_geometry.cpp
@@ -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
2  include/mapnik/wkb.hpp
@@ -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
6 plugins/input/geos/geos_featureset.cpp
@@ -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
12 plugins/input/postgis/postgis_featureset.cpp
@@ -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
18 plugins/input/sqlite/sqlite_datasource.cpp
@@ -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
3  plugins/input/sqlite/sqlite_featureset.cpp
@@ -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
97 plugins/input/sqlite/sqlite_utils.hpp
@@ -190,21 +190,22 @@ class sqlite_utils
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 @@ class sqlite_utils
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)
- {
- bbox = paths[i].envelope();
- }
- else
+ for (unsigned i=0; i<paths.size(); ++i)
{
- 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 @@ class sqlite_utils
<< "' 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 @@ class sqlite_utils
<< 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 @@ class sqlite_utils
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
8 src/wkb.cpp
@@ -431,13 +431,17 @@ struct wkb_reader : boost::noncopyable
#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
4 utils/pgsql2sqlite/pgsql2sqlite.hpp
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.