Skip to content

Commit

Permalink
provider/postgis: gracefully handle empty geometry collection
Browse files Browse the repository at this point in the history
Added back geometry collection length check to ignore
0 length geometry collections. Added associated test case.

closes #429
  • Loading branch information
ARolek committed Apr 9, 2019
1 parent ae8f530 commit 588acfd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 8 additions & 8 deletions provider/postgis/postgis.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,8 @@ func (p Provider) TileFeatures(ctx context.Context, layer string, tile provider.
continue
}

// skip row if geometry collection empty.
g, ok := geometry.(geom.Collection)
if ok && len(g.Geometries()) == 0 {
continue
}

// decode our WKB
geom, err := wkb.DecodeBytes(geobytes)
geometry, err := wkb.DecodeBytes(geobytes)
if err != nil {
switch err.(type) {
case wkb.ErrUnknownGeometryType:
Expand All @@ -598,9 +592,15 @@ func (p Provider) TileFeatures(ctx context.Context, layer string, tile provider.
}
}

// skip row if geometry collection empty.
g, ok := geometry.(geom.Collection)
if ok && len(g.Geometries()) == 0 {
continue
}

feature := provider.Feature{
ID: gid,
Geometry: geom,
Geometry: geometry,
SRID: plyr.SRID(),
Tags: tags,
}
Expand Down
12 changes: 12 additions & 0 deletions provider/postgis/postgis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,18 @@ func TestTileFeatures(t *testing.T) {
LayerName: "missing_geom_field_name",
},
},
"gracefully handle empty geometry collection": {
layerConfig: map[string]interface{}{
postgis.ConfigKeyLayerName: "empty_geometry_collection",
postgis.ConfigKeyGeomField: "geom",
postgis.ConfigKeyGeomType: "polygon", // bypass the geometry type sniff on init
postgis.ConfigKeySQL: "SELECT ST_AsBinary(ST_GeomFromText('GEOMETRYCOLLECTION EMPTY')) AS geom, !BBOX! AS bbox",
},
tile: slippy.NewTile(16, 11241, 26168, 64, tegola.WebMercator),
// the test query returns a single geometry but it's ignored so our cout is 0
expectedFeatureCount: 0,
expectedTags: []string{},
},
}

for name, tc := range tests {
Expand Down

0 comments on commit 588acfd

Please sign in to comment.