Skip to content

Commit

Permalink
fix JSON encoding for sqlite SPR; remove old code; update README
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Dec 15, 2020
1 parent 095eec6 commit a1dffec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $> ./bin/wof-sqlite-index-features \
-geometry \
-properties \
-timings \
-dsn /usr/local/ca-poly-spr.db \
-dsn /usr/local/ca-alt.db \
-mode repo:// \
/usr/local/data/whosonfirst-data-admin-ca/
Expand All @@ -49,9 +49,30 @@ And then...

```
$> ./bin/query \
-database-uri 'sqlite://?dsn=/usr/local/data/ca-poly-spr.db' \
-database-uri 'sqlite://?dsn=/usr/local/data/ca-alt.db' \
-latitude 45.572744 \
-longitude -73.586295
| jq \
| grep wof:id
2020/12/15 15:32:05 Unable to parse placetype (alt) for ID 85874359, because 'Invalid placetype' - skipping placetype filters
2020/12/15 15:32:06 Unable to parse placetype (alt) for ID 85633041, because 'Invalid placetype' - skipping placetype filters
2020/12/15 15:32:06 Unable to parse placetype (alt) for ID 136251273, because 'Invalid placetype' - skipping placetype filters
2020/12/15 15:32:06 Unable to parse placetype (alt) for ID 85633041, because 'Invalid placetype' - skipping placetype filters
2020/12/15 15:32:06 Unable to parse placetype (alt) for ID 136251273, because 'Invalid placetype' - skipping placetype filters
2020/12/15 15:32:06 Unable to parse placetype (alt) for ID 85633041, because 'Invalid placetype' - skipping placetype filters
2020/12/15 15:32:06 Time to point in polygon, 596.579126ms
"wof:id": "1108955735",
"wof:id": "85874359",
"wof:id": "85874359",
"wof:id": "890458661",
"wof:id": "85633041",
"wof:id": "136251273",
"wof:id": "85633041",
"wof:id": "85633041",
"wof:id": "136251273",
"wof:id": "85633041",
"wof:id": "136251273",
```

_TBW: Indexing tables on start-up._
Expand Down
37 changes: 3 additions & 34 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package sqlite

// https://www.sqlite.org/rtree.html

// There is a bunch of code in here that could/should
// be reconciled with go-whosonfirst-spatial/database/rtree

import (
"context"
"encoding/json"
Expand All @@ -14,9 +11,7 @@ import (
"github.com/paulmach/go.geojson"
"github.com/skelterjohn/geom"
wof_geojson "github.com/whosonfirst/go-whosonfirst-geojson-v2"
// wof_feature "github.com/whosonfirst/go-whosonfirst-geojson-v2/feature"
"github.com/whosonfirst/go-whosonfirst-log"
// "github.com/whosonfirst/go-whosonfirst-spatial/cache"
"github.com/whosonfirst/go-whosonfirst-spatial/database"
"github.com/whosonfirst/go-whosonfirst-spatial/filter"
"github.com/whosonfirst/go-whosonfirst-spatial/geo"
Expand Down Expand Up @@ -346,14 +341,6 @@ func (r *SQLiteSpatialDatabase) getIntersectsByCoord(ctx context.Context, coord

func (r *SQLiteSpatialDatabase) getIntersectsByRect(ctx context.Context, rect *geom.Rect) ([]*RTreeSpatialIndex, error) {

/*
t1 := time.Now()
defer func() {
golog.Printf("Time to get intersects by rect, %v\n", time.Since(t1))
}()
*/

conn, err := r.db.Conn()

if err != nil {
Expand Down Expand Up @@ -424,14 +411,6 @@ func (r *SQLiteSpatialDatabase) getIntersectsByRect(ctx context.Context, rect *g

func (r *SQLiteSpatialDatabase) inflateResultsWithChannels(ctx context.Context, rsp_ch chan spr.StandardPlacesResult, err_ch chan error, possible []*RTreeSpatialIndex, c *geom.Coord, filters ...filter.Filter) {

/*
t1 := time.Now()
defer func() {
golog.Printf("Time to inflate results, %v\n", time.Since(t1))
}()
*/

seen := make(map[string]bool)
mu := new(sync.RWMutex)

Expand Down Expand Up @@ -580,19 +559,9 @@ func (db *SQLiteSpatialDatabase) StandardPlacesResultsToFeatureCollection(ctx co
features = append(features, f)
}

/*
pg := geojson.Pagination{
TotalCount: len(features),
Page: 1,
PerPage: len(features),
PageCount: 1,
}
*/

collection := geojson.FeatureCollection{
Type: "FeatureCollection",
Features: features,
// Pagination: pg,
}

return &collection, nil
Expand Down Expand Up @@ -628,7 +597,7 @@ func (r *SQLiteSpatialDatabase) retrieveSPRCacheItem(ctx context.Context, uri_st
// Note to self: I actually tried chunking this out in to separate functions
// talking to the database concurrently with channels and stuff and it was
// subtly slower than just doing it this way... (20201215/thisisaaronland)

c, ok := r.gocache.Get(uri_str)

if ok {
Expand Down Expand Up @@ -721,11 +690,11 @@ func (r *SQLiteSpatialDatabase) retrieveSPRCacheItem(ctx context.Context, uri_st
}

path, err := uri.Id2RelPath(id, uri_args)

if err != nil {
return nil, err
}

s := &SQLiteStandardPlacesResult{
WOFId: spr_id,
WOFParentId: parent_id,
Expand Down
2 changes: 1 addition & 1 deletion spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type SQLiteStandardPlacesResult struct {
WOFPlacetype string `json:"wof:placetype"`
MZLatitude float64 `json:"mz:latitude"`
MZLongitude float64 `json:"mz:longitude"`
MZMinLatitude float64 `json:"spr:min_latitude"`
MZMinLatitude float64 `json:"mz:min_latitude"`
MZMinLongitude float64 `json:"mz:min_longitude"`
MZMaxLatitude float64 `json:"mz:max_latitude"`
MZMaxLongitude float64 `json:"mz:max_longitude"`
Expand Down

0 comments on commit a1dffec

Please sign in to comment.