omniscale / imposm3

Imposm imports OpenStreetMap data into PostGIS
http://imposm.org/docs/imposm3/latest/
Apache License 2.0
710 stars 156 forks source link

geojson_intersects_feature does not work with geojsons containing null geometries #236

Open pnorman opened 4 years ago

pnorman commented 4 years ago

Using the config files in #227, I get an error with this geojson

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "m49": "001",
                "wikidata": "Q2",
                "nameEn": "World",
                "aliases": [
                    "Earth",
                    "Planet"
                ],
                "level": "world"
            },
            "geometry": null
        }
    ]
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5b38aa]

goroutine 1 [running]:
github.com/omniscale/imposm3/geom/geojson.constructPolygonFeatures(0x0, 0x7, 0x986932, 0x7, 0xffffffffffffffff, 0xc420000180)
        /home/pnorman/go/src/github.com/omniscale/imposm3/geom/geojson/geojson.go:136 +0x3a
github.com/omniscale/imposm3/geom/geojson.constructPolygonFeatures(0xc4201f8a48, 0x0, 0x0, 0xe8c558, 0x0, 0x0)
        /home/pnorman/go/src/github.com/omniscale/imposm3/geom/geojson/geojson.go:148 +0x2b3
github.com/omniscale/imposm3/geom/geojson.constructPolygonFeatures(0xc4201a81e0, 0x8a4940, 0xc4201a81e0, 0x0, 0x0, 0xc4201f8b58)
        /home/pnorman/go/src/github.com/omniscale/imposm3/geom/geojson/geojson.go:161 +0x64c
github.com/omniscale/imposm3/geom/geojson.ParseGeoJSON(0x9ecfe0, 0xc4201ac0b8, 0xc4201ac0b8, 0x0, 0x0, 0xc4201ac001, 0x19)
        /home/pnorman/go/src/github.com/omniscale/imposm3/geom/geojson/geojson.go:126 +0xb4
github.com/omniscale/imposm3/mapping.loadFeatures(0xc4201a20b4, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc4201d4360, 0x1a, 0xc4201a4570, ...)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/columns_intersection.go:47 +0x1af
github.com/omniscale/imposm3/mapping.MakeIntersectsFeatureField(0xc4201a20b4, 0xc, 0x993ec4, 0x1a, 0x986349, 0x6, 0x0, 0x9acdd0, 0x0, 0x0, ...)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/columns_intersection.go:71 +0x60
github.com/omniscale/imposm3/mapping.MakeColumnType(0xc4201d0f60, 0xc4201a8140, 0x1, 0x1)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/mapping.go:230 +0x1c4
github.com/omniscale/imposm3/mapping.makeRowBuilder(0xc420206000, 0x98971c, 0xa, 0x416601)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/mapping.go:213 +0xd4
github.com/omniscale/imposm3/mapping.(*Mapping).tables(0xc4201b4820, 0x98971c, 0xa, 0xc4201a4720, 0x0, 0x0)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/mapping.go:196 +0x115
github.com/omniscale/imposm3/mapping.(*Mapping).lineStringMatcher(0xc4201b4820, 0x9ec900, 0xc4201a4660, 0x0, 0x0)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/matcher.go:29 +0xc8
github.com/omniscale/imposm3/mapping.(*Mapping).createMatcher(0xc4201b4820, 0x0, 0x0)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/mapping.go:150 +0x7d
github.com/omniscale/imposm3/mapping.New(0xc4201da000, 0x11e, 0x31e, 0x11e, 0x31e, 0x0)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/mapping.go:113 +0xac
github.com/omniscale/imposm3/mapping.FromFile(0x7ffe8366a641, 0xb, 0xc42009a120, 0xc420075268, 0x416eb8)
        /home/pnorman/go/src/github.com/omniscale/imposm3/mapping/mapping.go:98 +0x87
github.com/omniscale/imposm3/import_.Import(0x7ffe8366a659, 0x33, 0x98a34d, 0xc, 0x98a34d, 0xc, 0x7ffe8366a641, 0xb, 0xf11, 0x0, ...)
        /home/pnorman/go/src/github.com/omniscale/imposm3/import_/import.go:50 +0x182
main.Main(0x9ad550)
        /home/pnorman/go/src/github.com/omniscale/imposm3/cmd/imposm/main.go:48 +0x54b
main.main()
        /home/pnorman/go/src/github.com/omniscale/imposm3/cmd/imposm/main.go:77 +0x2d

Like #235 this isn't critical because I can drop these items, but RFC 7946 and the 2008 GeoJSON spec explicitly allow the member with name of "geometry" to be a JSON null value.