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
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
Expand Down
15 changes: 15 additions & 0 deletions predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ func polygonToGeometry(geofence *geom.Polygon) *geos.Geometry {

return geos.Must(geos.NewPolygon(shellGeos, holes...))
}

func polygonToGeometryExample(geofence *geom.Polygon) *geos.Geometry {
// Convert the outer shell to geos format.
shell := geofence.LinearRing(0).Coords()
shellGeos := geomToGeosCoords(shell)

// Convert each hole to geos format.
numHoles := geofence.NumLinearRings() - 1
holes := make([][]geos.Coord, numHoles)
for i := 0; i < numHoles; i++ {
holes[i] = geomToGeosCoords(geofence.LinearRing(i).Coords())
}

return geos.Must(geos.NewPolygon(shellGeos, holes...))
}
9 changes: 9 additions & 0 deletions predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ func TestPredicates(t *testing.T) {
})
}
}

func TestPolygonToGeometryExample(t *testing.T) {
geofence := readFileAsGeometry(t, "testdata/regents.geojson")

geom := polygonToGeometryExample(geofence)
perimeterLength, err := geom.Length()
require.NoError(t, err)
assert.Equal(t, geofence.Length(), perimeterLength)
}