Skip to content

Commit 2eac636

Browse files
committed
WKB parser: Empty multi* geometries are okay by the spec
Return NULL geometries in that case because we don't want to handle empty multi* geometries internally.
1 parent c33342f commit 2eac636

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/wkb.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ class make_ewkb_visitor
292292

293293
}; // class make_ewkb_visitor
294294

295+
/**
296+
* Parser for (E)WKB.
297+
*
298+
* Empty Multi* geometries and Geometry Collections will return a NULL
299+
* geometry object.
300+
*
301+
* Call next() to get a pointer to the next character that is not part of the
302+
* geometry any more. If this is not the same as the end pointer given to
303+
* the constructor, this means that there is extra data available in the
304+
* input data.
305+
*
306+
* Can only parse (E)WKB in native byte order.
307+
*/
295308
class ewkb_parser_t
296309
{
297310
public:
@@ -457,8 +470,8 @@ class ewkb_parser_t
457470
auto &multipoint = geom->set<geom::multipoint_t>();
458471
auto const num_geoms = parse_length();
459472
if (num_geoms == 0) {
460-
throw std::runtime_error{
461-
"Invalid WKB geometry: Multipoint without points"};
473+
geom->reset();
474+
return;
462475
}
463476

464477
multipoint.reserve(num_geoms);
@@ -479,8 +492,8 @@ class ewkb_parser_t
479492
auto &multilinestring = geom->set<geom::multilinestring_t>();
480493
auto const num_geoms = parse_length();
481494
if (num_geoms == 0) {
482-
throw std::runtime_error{
483-
"Invalid WKB geometry: Multilinestring without linestrings"};
495+
geom->reset();
496+
return;
484497
}
485498

486499
multilinestring.reserve(num_geoms);
@@ -501,8 +514,8 @@ class ewkb_parser_t
501514
auto &multipolygon = geom->set<geom::multipolygon_t>();
502515
auto const num_geoms = parse_length();
503516
if (num_geoms == 0) {
504-
throw std::runtime_error{
505-
"Invalid WKB geometry: Multipolygon without polygons"};
517+
geom->reset();
518+
return;
506519
}
507520

508521
multipolygon.reserve(num_geoms);
@@ -523,8 +536,8 @@ class ewkb_parser_t
523536
auto &collection = geom->set<geom::collection_t>();
524537
auto const num_geoms = parse_length();
525538
if (num_geoms == 0) {
526-
throw std::runtime_error{
527-
"Invalid WKB geometry: Geometry collection without geometries"};
539+
geom->reset();
540+
return;
528541
}
529542

530543
collection.reserve(num_geoms);

0 commit comments

Comments
 (0)