Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: skip nil geometries (#42)
Browse files Browse the repository at this point in the history
* fix: skip nil geomatries

* test: add test case for nil geometry
  • Loading branch information
mimoham24 committed Sep 2, 2021
1 parent 02b17f1 commit 90c3279
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/layer/decoding/geojson.go
Expand Up @@ -31,9 +31,12 @@ func NewGeoJSONDecoder(r io.Reader, s id.SceneID) *GeoJSONDecoder {
}
}

func disassembleMultipolygon(fc []*geojson.Feature) []*geojson.Feature {
func validateFeatures(fc []*geojson.Feature) []*geojson.Feature {
var res []*geojson.Feature
for _, f := range fc {
if f.Geometry == nil {
continue
}
if f.Geometry.Type == geojson.GeometryMultiPolygon {
for _, p := range f.Geometry.MultiPolygon {
nf := geojson.NewPolygonFeature(p)
Expand Down Expand Up @@ -65,7 +68,7 @@ func (d *GeoJSONDecoder) Decode() (Result, error) {
if err != nil {
return Result{}, errors.New("unable to parse file content")
}
fl := disassembleMultipolygon(fc.Features)
fl := validateFeatures(fc.Features)
// if feature collection > append it to features list, else try to decode a single feature (layer)
if len(fc.Features) > 0 {
d.features = fl
Expand Down
11 changes: 11 additions & 0 deletions pkg/layer/decoding/geojson_test.go
Expand Up @@ -100,6 +100,17 @@ const geojsonmock = `{
}
}
},
{
"type": "Feature",
"geometry": null,
"properties": {
"N03_001": "愛知県",
"N03_002": null,
"N03_003": null,
"N03_004": "豊橋市",
"N03_007": "23201"
}
},
{
"type": "Feature",
"geometry": {
Expand Down

0 comments on commit 90c3279

Please sign in to comment.