From 34cf674fa08cfa8f11ec1722627693f474911a7b Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Tue, 26 Nov 2013 09:47:00 +0100 Subject: [PATCH] read geojson with z-values --- geom/geojson/geojson.go | 4 ++-- geom/geojson/geojson_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/geom/geojson/geojson.go b/geom/geojson/geojson.go index 6c01298..5518cb2 100644 --- a/geom/geojson/geojson.go +++ b/geom/geojson/geojson.go @@ -27,8 +27,8 @@ type point struct { func newPointFromCoords(coords []interface{}) (point, error) { p := point{} - if len(coords) != 2 { - return p, errors.New("point list length not 2") + if len(coords) != 2 && len(coords) != 3 { + return p, errors.New("point list length not 2 or 3") } var ok bool p.long, ok = coords[0].(float64) diff --git a/geom/geojson/geojson_test.go b/geom/geojson/geojson_test.go index 30f09f1..6b972c2 100644 --- a/geom/geojson/geojson_test.go +++ b/geom/geojson/geojson_test.go @@ -22,6 +22,22 @@ func TestParsePolygon(t *testing.T) { t.Fatal(geoms[0].Area()) } + // ignore z values + r = bytes.NewBufferString(`{"type": "Polygon", "coordinates": [[[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0], [0, 0, 0]]]}`) + geoms, err = ParseGeoJson(r) + + if err != nil { + t.Fatal(err) + } + + if len(geoms) != 1 { + t.Fatal(geoms) + } + + if math.Abs(geoms[0].Area()-100) > 0.00001 { + t.Fatal(geoms[0].Area()) + } + r = bytes.NewBufferString(`{"type": "Polygon", "coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]], [[5, 5], [6, 5], [6, 6], [5, 6], [5, 5]]]}`) geoms, err = ParseGeoJson(r)