Skip to content

Commit

Permalink
Change interface to remove all GeoJSON stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Dec 16, 2020
1 parent b821a96 commit 3c66412
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 105 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ _These interfaces are still subject to change. Things are settling down but noth
type SpatialDatabase interface {
IndexFeature(context.Context, wof_geojson.Feature) error
PointInPolygon(context.Context, *geom.Coord, ...filter.Filter) (spr.StandardPlacesResults, error)
PointInPolygonCandidates(context.Context, *geom.Coord) (*geojson.FeatureCollection, error)
PointInPolygonWithChannels(context.Context, chan spr.StandardPlacesResult, chan error, chan bool, *geom.Coord, ...filter.Filter)
PointInPolygonCandidatesWithChannels(context.Context, *geom.Coord, chan *geojson.Feature, chan error, chan bool)
PointInPolygonWithChannels(context.Context, chan spr.StandardPlacesResult, chan error, chan bool, *geom.Coord, ...filter.Filter)
PointInPolygonCandidates(context.Context, *geom.Coord) ([]*spatial.PointInPolygonCandidate, error)
PointInPolygonCandidatesWithChannels(context.Context, *geom.Coord, chan *spatial.PointInPolygonCandidate, chan error, chan bool)
Close(context.Context) error
}
```
Expand All @@ -150,8 +150,7 @@ type SpatialDatabase interface {
```
type PropertiesReader interface {
IndexFeature(context.Context, wof_geojson.Feature) error
PropertiesResponseResultsWithStandardPlacesResults(context.Context, spr.StandardPlacesResults, []string) (*PropertiesResponseResults, error)
AppendPropertiesWithFeatureCollection(context.Context, *geojson.FeatureCollection, []string) error
PropertiesResponseResultsWithStandardPlacesResults(context.Context, spr.StandardPlacesResults, []string) (*spatial.PropertiesResponseResults, error)
Close(context.Context) error
}
```
Expand All @@ -164,4 +163,3 @@ type PropertiesReader interface {
* https://github.com/whosonfirst/go-whosonfirst-spatial-http-sqlite
* https://github.com/whosonfirst/go-whosonfirst-spatial-grpc
* https://github.com/whosonfirst/go-whosonfirst-geojson-v2
* https://github.com/paulmach/go.geojson
11 changes: 0 additions & 11 deletions cache/cache.go

This file was deleted.

42 changes: 0 additions & 42 deletions cache/spr.go

This file was deleted.

31 changes: 6 additions & 25 deletions geo/geojson.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
package geo

import (
"github.com/paulmach/go.geojson"
"github.com/skelterjohn/geom"
)

func GeoJSONFeatureContainsCoord(f *geojson.Feature, c *geom.Coord) bool {

return GeoJSONGeometryContainsCoord(f.Geometry, c)
}

func GeoJSONGeometryContainsCoord(geom *geojson.Geometry, c *geom.Coord) bool {

if geom.IsMultiPolygon() {
return GeoJSONMultiPolygonContainsCoord(geom.MultiPolygon, c)
}

if geom.IsPolygon() {
return GeoJSONPolygonContainsCoord(geom.Polygon, c)
}

return false
}

func GeoJSONMultiPolygonContainsCoord(multi [][][][]float64, c *geom.Coord) bool {
func MultiPolygonContainsCoord(multi [][][][]float64, c *geom.Coord) bool {

for _, poly := range multi {

if GeoJSONPolygonContainsCoord(poly, c) {
if PolygonContainsCoord(poly, c) {
return true
}
}

return false
}

func GeoJSONPolygonContainsCoord(poly [][][]float64, c *geom.Coord) bool {
func PolygonContainsCoord(poly [][][]float64, c *geom.Coord) bool {

count := len(poly)

Expand All @@ -47,7 +28,7 @@ func GeoJSONPolygonContainsCoord(poly [][][]float64, c *geom.Coord) bool {

exterior_ring := poly[0]

if !GeoJSONRingContainsCoord(exterior_ring, c) {
if !RingContainsCoord(exterior_ring, c) {
return false
}

Expand All @@ -57,7 +38,7 @@ func GeoJSONPolygonContainsCoord(poly [][][]float64, c *geom.Coord) bool {

for _, interior_ring := range poly {

if GeoJSONRingContainsCoord(interior_ring, c) {
if RingContainsCoord(interior_ring, c) {
return false
}
}
Expand All @@ -66,7 +47,7 @@ func GeoJSONPolygonContainsCoord(poly [][][]float64, c *geom.Coord) bool {
return true
}

func GeoJSONRingContainsCoord(ring [][]float64, c *geom.Coord) bool {
func RingContainsCoord(ring [][]float64, c *geom.Coord) bool {

polygon := geom.Polygon{}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.12

require (
github.com/aaronland/go-roster v0.0.2
github.com/paulmach/go.geojson v1.4.0
github.com/skelterjohn/geom v0.0.0-20180103142417-96f3e8a219c5
github.com/tidwall/gjson v1.6.4
github.com/tidwall/sjson v1.1.2
Expand Down
10 changes: 0 additions & 10 deletions properties/channels.go

This file was deleted.

13 changes: 3 additions & 10 deletions properties/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,17 @@ import (
"context"
"fmt"
"github.com/aaronland/go-roster"
"github.com/paulmach/go.geojson"
wof_geojson "github.com/whosonfirst/go-whosonfirst-geojson-v2"
"github.com/whosonfirst/go-whosonfirst-spr"
"github.com/whosonfirst/go-whosonfirst-spatial"
"github.com/whosonfirst/go-whosonfirst-spr"
"net/url"
"sort"
"strings"
)

type PropertiesResponse map[string]interface{}

type PropertiesResponseResults struct {
Properties []*PropertiesResponse `json:"properties"`
}

type PropertiesReader interface {
IndexFeature(context.Context, wof_geojson.Feature) error
PropertiesResponseResultsWithStandardPlacesResults(context.Context, spr.StandardPlacesResults, []string) (*PropertiesResponseResults, error)
AppendPropertiesWithFeatureCollection(context.Context, *geojson.FeatureCollection, []string) error
PropertiesResponseResultsWithStandardPlacesResults(context.Context, spr.StandardPlacesResults, []string) (*spatial.PropertiesResponseResults, error)
Close(context.Context) error
}

Expand Down
7 changes: 7 additions & 0 deletions spatial.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ type PointInPolygonCandidate struct {
AltLabel string
Bounds *geom.Rect
}

type PropertiesResponse map[string]interface{}

type PropertiesResponseResults struct {
Properties []*PropertiesResponse `json:"properties"`
}

0 comments on commit 3c66412

Please sign in to comment.