Skip to content
Open
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
11 changes: 11 additions & 0 deletions invariant/invariant.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,14 @@ func GetType(geojson interface{}) string {
}
return "invalid"
}

// GetGeom returns the Geometry from Feature or Geometry Object
func GetGeom(geojson interface{}) *geometry.Geometry {
switch gtp := geojson.(type) {
case *feature.Feature:
return &gtp.Geometry
case *geometry.Geometry:
return gtp
}
return nil
}
47 changes: 47 additions & 0 deletions invariant/invariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,3 +767,50 @@ func TestGetType(t *testing.T) {
})
}
}

// func TestGetGeom(t *testing.T) {
// type args struct {
// geojson interface{}
// }
// fp, _ := feature.FromJSON("{ \"type\": \"Feature\", \"properties\": {}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [102, 0.5] } }")
// ln, _ := geometry.FromJSON("{ \"type\": \"Feature\", \"properties\": {}, \"geometry\": { \"type\": \"LineString\", \"coordinates\": [ [-20.39062500000365, 33.72434000000235], [-3.5156249999990803, 47.51720099999992], [14.062499999996321, 16.97274100000141] ] } }")

// tests := map[string]struct {
// args args
// want *geometry.Geometry
// }{
// "error - required coords": {
// args: args{
// geojson: "",
// },
// want: nil,
// },
// "feature - point": {
// args: args{
// geojson: fp,
// },
// want: &geometry.Geometry{
// GeoJSONType: "Point",
// Coordinates: []interface{}{float64(102), float64(0.5)},
// },
// },
// "geometry - lineString": {
// args: args{
// geojson: ln,
// },
// want: &geometry.Geometry{
// GeoJSONType: "Point",
// Coordinates: []interface{}{float64(102), float64(0.5)},
// },
// },
// }
// for name, tt := range tests {
// t.Run(name, func(t *testing.T) {
// geo := GetGeom(tt.args.geojson)

// if got := geo; !reflect.DeepEqual(got, tt.want) {
// t.Errorf("TestGetCoord() = %v, want %v", got, tt.want)
// }
// })
// }
// }