From 2c5c0becc1460f6e2a113b237b8878a96b99f097 Mon Sep 17 00:00:00 2001 From: Alexander Rolek Date: Thu, 4 Apr 2019 22:12:39 -0700 Subject: [PATCH] provider/postgis: gracefully handle empty geometry collection Added back geometry collection length check to ignore 0 length geometry collections. Added associated test case. closes #429 --- provider/postgis/postgis.go | 16 ++++++++-------- provider/postgis/postgis_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) 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 {