Features without ID's clobber eachother

#2 · closed · 0 comments

View on GitHub ↗

ezk84

This test fails: ```go package main import ( "testing" "github.com/paulmach/go.geojson" "github.com/rubenv/topojson" "github.com/stretchr/testify/assert" ) func TestMultiFeatures(t *testing.T) { fc := geojson.NewFeatureCollection() f1 := geojson.NewPolygonFeature([][][]float64{ {{0, 0}, {1, 1}, {2, 0}, {1, -1}, {0, 0}}, {{0.25, 0}, {0.75, -0.25}, {0.75, 0.25}, {0.25, 0}}, }) fc.AddFeature(f1) f2 := geojson.NewPolygonFeature([][][]float64{ {{0, 0}, {1, 1}, {2, 0}, {1, 2}, {0, 0}}, }) fc.AddFeature(f2) topo := topojson.NewTopology(fc, nil) assert.Len(t, topo.Objects, 2) }``` Looking at the structure of the topology, the second Polygon clobbered the first one because they both were assigned to the empty string key in `Objects`. If I had assigned an `id` property for each feature, these would have been used as the keys into `Objects`. The problem here is that valid GeoJSON does not have to have an `id` property, and we see examples in the wild without this. At the very least, it should try to generate a pseudo-ID so that we don't lose the other geometries. What the javascript library seems to do is put the multiple geometries into a GeometryCollection.

Comments