diff --git a/main.go b/main.go index 6518b19..4ff90d1 100644 --- a/main.go +++ b/main.go @@ -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" @@ -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 } diff --git a/main_test.go b/main_test.go index 8169fb0..a07fab9 100644 --- a/main_test.go +++ b/main_test.go @@ -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)