read geojson with z-values

master
Oliver Tonnhofer 2013-11-26 09:47:00 +01:00
parent 7e57c6047b
commit 34cf674fa0
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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)