diff --git a/provider/postgis/postgis.go b/provider/postgis/postgis.go index 076be1e12..0f8016666 100644 --- a/provider/postgis/postgis.go +++ b/provider/postgis/postgis.go @@ -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: @@ -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, } diff --git a/provider/postgis/postgis_test.go b/provider/postgis/postgis_test.go index 1694cd2ab..2b3afc800 100644 --- a/provider/postgis/postgis_test.go +++ b/provider/postgis/postgis_test.go @@ -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 {