Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
update to use whosonfirst/go-whosonfirst-spatial v0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sfomuseumbot committed Nov 4, 2023
1 parent 427a975 commit 973bd81
Show file tree
Hide file tree
Showing 9 changed files with 68,307 additions and 46 deletions.
69 changes: 69 additions & 0 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"testing"

"github.com/whosonfirst/go-whosonfirst-spatial-rtree/fixtures"
"github.com/whosonfirst/go-whosonfirst-spatial-rtree/fixtures/microhoods"
"github.com/whosonfirst/go-whosonfirst-spatial/database"
"github.com/whosonfirst/go-whosonfirst-spatial/filter"
Expand Down Expand Up @@ -240,3 +241,71 @@ func TestSpatialDatabaseWithFS(t *testing.T) {
}
}
}

func TestSpatialDatabaseWithFeatureCollection(t *testing.T) {

ctx := context.Background()

database_uri := "rtree://?dsn=:memory:"

tests := map[int64]Criteria{
1108712253: Criteria{Longitude: -71.120168, Latitude: 42.376015, IsCurrent: 1}, // Old Cambridge
420561633: Criteria{Longitude: -122.395268, Latitude: 37.794893, IsCurrent: 0}, // Superbowl City
420780729: Criteria{Longitude: -122.421529, Latitude: 37.743168, IsCurrent: -1}, // Liminal Zone of Deliciousness
}

db, err := database.NewSpatialDatabase(ctx, database_uri)

if err != nil {
t.Fatalf("Failed to create new spatial database, %v", err)
}

err = database.IndexDatabaseWithFS(ctx, db, fixtures.FS)

if err != nil {
t.Fatalf("Failed to index spatial database, %v", err)
}

for expected, criteria := range tests {

c, err := geo.NewCoordinate(criteria.Longitude, criteria.Latitude)

if err != nil {
t.Fatalf("Failed to create new coordinate, %v", err)
}

i, err := filter.NewSPRInputs()

if err != nil {
t.Fatalf("Failed to create SPR inputs, %v", err)
}

i.IsCurrent = []int64{criteria.IsCurrent}
// i.Placetypes = []string{"microhood"}

f, err := filter.NewSPRFilterFromInputs(i)

if err != nil {
t.Fatalf("Failed to create SPR filter from inputs, %v", err)
}

spr, err := db.PointInPolygon(ctx, c, f)

if err != nil {
t.Fatalf("Failed to perform point in polygon query, %v", err)
}

results := spr.Results()
count := len(results)

if count != 1 {
t.Fatalf("Expected 1 result but got %d for '%d'", count, expected)
}

first := results[0]

if first.Id() != strconv.FormatInt(expected, 10) {
t.Fatalf("Expected %d but got %s", expected, first.Id())
}
}
}
8 changes: 8 additions & 0 deletions fixtures/fixtures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fixtures

import (
"embed"
)

//go:embed *.geojson
var FS embed.FS
68,152 changes: 68,152 additions & 0 deletions fixtures/microhoods.geojson

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/sfomuseum/go-flags v0.10.0
github.com/whosonfirst/go-ioutil v1.0.2
github.com/whosonfirst/go-whosonfirst-feature v0.0.26
github.com/whosonfirst/go-whosonfirst-spatial v0.6.0
github.com/whosonfirst/go-whosonfirst-spatial v0.7.1
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.6
github.com/whosonfirst/go-whosonfirst-uri v1.3.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ github.com/whosonfirst/go-whosonfirst-placetypes v0.7.0 h1:hm1dySC23ZZYHDleAE201
github.com/whosonfirst/go-whosonfirst-placetypes v0.7.0/go.mod h1:d7S4er4OFfFsgzMOnHH8mX8q+iPhXWB+merbrMDx/rk=
github.com/whosonfirst/go-whosonfirst-sources v0.1.0 h1:JuKLa6KWke22jBfJ1pM9WQHoz1/3pbDv2C+aR+THPPQ=
github.com/whosonfirst/go-whosonfirst-sources v0.1.0/go.mod h1:EUMHyGzUmqPPxlMmOp+28BFeoBdxxE0HCKRd67lkqGM=
github.com/whosonfirst/go-whosonfirst-spatial v0.6.0 h1:F0SLJ0faNQ8/yvwGbKuQwlkc/LA0QAP+tunbotd6A2g=
github.com/whosonfirst/go-whosonfirst-spatial v0.6.0/go.mod h1:BqV6M4Un6zgVOW++wk+xZ6SgstvcrIh+WnmEOhhtgLY=
github.com/whosonfirst/go-whosonfirst-spatial v0.7.1 h1:DQC+iyDCW11wolpHeWu5PQQX7stmczmKbw+smIF2ZKM=
github.com/whosonfirst/go-whosonfirst-spatial v0.7.1/go.mod h1:BqV6M4Un6zgVOW++wk+xZ6SgstvcrIh+WnmEOhhtgLY=
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.6 h1:0C1MVb2c/j81SmsDkvzhXiQ6VjBpzCNYFs8XJ6do/jQ=
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.6/go.mod h1:pZqrrLV+z6JXSBdDNqKAmTeC1mYtWyn/REQFOC4Z1zA=
github.com/whosonfirst/go-whosonfirst-uri v1.3.0 h1:LYOVLqP9rWQxauYVkdw65j5LZxEi8OK0GHh/qCEpX4g=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ github.com/whosonfirst/go-whosonfirst-placetypes
## explicit; go 1.12
github.com/whosonfirst/go-whosonfirst-sources
github.com/whosonfirst/go-whosonfirst-sources/sources
# github.com/whosonfirst/go-whosonfirst-spatial v0.6.0
# github.com/whosonfirst/go-whosonfirst-spatial v0.7.1
## explicit; go 1.18
github.com/whosonfirst/go-whosonfirst-spatial
github.com/whosonfirst/go-whosonfirst-spatial/database
Expand Down

0 comments on commit 973bd81

Please sign in to comment.