Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/paulmach/orb/geojson"
"github.com/paulmach/orb/maptile"
"github.com/paulmach/orb/maptile/tilecover"
"github.com/paulmach/orb/planar"
"image"
"image/png"
"io"
Expand Down Expand Up @@ -308,6 +309,10 @@ func parseInput(body io.Reader) (orb.Geometry, string, string, json.RawMessage,
return nil, "", "", nil, errors.New("invalid input RegionType")
}

if planar.Area(geom) == 0.0 {
return nil, "", "", nil, errors.New("Input has 0 area")
}

return geom, input.Name, input.RegionType, sanitizedData, nil
}

Expand Down
10 changes: 10 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func TestInvalidGeoJSON(t *testing.T) {
assert.NotNil(t, err)
}

func TestZeroAreaGeoJSON(t *testing.T) {
_, _, _, _, err := parseInput(strings.NewReader(`{"Name":"a_name", "RegionType":"geojson", "RegionData":{"type":"Polygon","coordinates":[[[0,0],[1,1],[1,1],[0,0]]]}}`))
assert.NotNil(t, err)
}

func TestZeroAreaBbox(t *testing.T) {
_, _, _, _, err := parseInput(strings.NewReader(`{"Name":"a_name", "RegionType":"bbox", "RegionData":[0,0,0,0]}`))
assert.NotNil(t, err)
}

func TestMalformedGeoJSON(t *testing.T) {
_, _, _, _, err := parseInput(strings.NewReader(`{"Name":"a_name", "RegionType":"geojson", "RegionData":[}`))
assert.NotNil(t, err)
Expand Down
Loading