Skip to content

Commit

Permalink
update to support sort and properties (no-op) request flags; update P…
Browse files Browse the repository at this point in the history
…ointInPolygon to use pip.PointInPolygonQuery
  • Loading branch information
sfomuseumbot committed Dec 8, 2022
1 parent 0af21c1 commit c492b20
Show file tree
Hide file tree
Showing 36 changed files with 169 additions and 4,674 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ require (
github.com/paulmach/orb v0.7.1
github.com/sfomuseum/go-flags v0.10.0
github.com/whosonfirst/go-whosonfirst-flags v0.4.4
github.com/whosonfirst/go-whosonfirst-spatial v0.5.2
github.com/whosonfirst/go-whosonfirst-spatial v0.5.3
github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1
github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
Expand All @@ -17,13 +16,11 @@ require (
require (
github.com/aaronland/go-json-query v0.1.3 // indirect
github.com/aaronland/go-roster v1.0.0 // indirect
github.com/dhconnelly/rtreego v1.1.0 // indirect
github.com/g8rswimmer/error-chain v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/natefinch/atomic v1.0.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/sfomuseum/go-edtf v1.1.1 // indirect
github.com/sfomuseum/go-timings v1.2.1 // indirect
github.com/sfomuseum/iso8601duration v1.1.0 // indirect
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ github.com/aaronland/go-roster v1.0.0/go.mod h1:KIsYZgrJlAsyb9LsXSCvlqvbcCBVjCSq
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dhconnelly/rtreego v1.1.0 h1:ejMaqN03N1s6Bdg6peGkNgBnYYSBHzcK8yhSPCB+rHE=
github.com/dhconnelly/rtreego v1.1.0/go.mod h1:SDozu0Fjy17XH1svEXJgdYq8Tah6Zjfa/4Q33Z80+KM=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/g8rswimmer/error-chain v1.0.0 h1:WnwnunlvqtGPHVHmBfbmUyAgrtag8Y6nNpwLWmtSYOQ=
Expand Down Expand Up @@ -43,8 +41,6 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A=
github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU=
github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
Expand Down Expand Up @@ -89,12 +85,10 @@ github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2 h1:Sye3ySdkTy5+PPdSLCaZO
github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2/go.mod h1:HjxisIp+iZOXoThM9XyvC+GCmnupynE73GD3JxhH3fY=
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.5.2 h1:ZCxiGqxbgafUKZ7Nz0wcS/+yzPsLJJNHYnaLHZd51Ns=
github.com/whosonfirst/go-whosonfirst-spatial v0.5.2/go.mod h1:Q8SCUVV0mcGZpMB3Lq9GiBXkm6ZVS/kor4GuPQGvaCA=
github.com/whosonfirst/go-whosonfirst-spatial v0.5.3 h1:QLmgDJx3O/8e2h2j/uqA+lb5NJHIhgITRm6fkx2BcKc=
github.com/whosonfirst/go-whosonfirst-spatial v0.5.3/go.mod h1:Q8SCUVV0mcGZpMB3Lq9GiBXkm6ZVS/kor4GuPQGvaCA=
github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1 h1:j2QhDx8t4z0s3RJqvm+Ll4t2zG4c195NZx2XRFRCAtY=
github.com/whosonfirst/go-whosonfirst-spatial-pip v0.3.1/go.mod h1:klRSLQeAVdFZd84f0xfKjSmVj1L8JCF8GPdGUiVOqnA=
github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4 h1:3dIRDNU1iwwn/4Xe+yD3FEs1L9x7j1ps/asiRfX+/Ho=
github.com/whosonfirst/go-whosonfirst-spatial-rtree v0.2.4/go.mod h1:yEmuF0q/mR17zRiRSD3E+9Ro9tlv8nxu8GbdpSwk5Hc=
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 h1:dc7BdkGrSKtGyIEO8jW4h6xS0DMdKANwMHFRc1+WcnM=
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3/go.mod h1:3Sym68fXOfIAcdJiRkJC+8FO+JuSGZ2NuDpRFzWMDi0=
github.com/whosonfirst/go-whosonfirst-uri v1.2.0 h1:lhmRsIhcpTr5HAo+kXKRGsSt76HTh3Ko/oTR2jpCm/o=
Expand Down
46 changes: 45 additions & 1 deletion request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,58 @@ package request

import (
"flag"
"fmt"
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/spatial"
"github.com/whosonfirst/go-whosonfirst-spatial-pip"
)

func PIPRequestFromSpatialRequest(spatial_req *spatial.PointInPolygonRequest) *pip.PointInPolygonRequest {

asInt64 := func(fl []spatial.ExistentialFlag) []int64 {

j := make([]int64, len(fl))

for idx, f := range fl {

switch f {
case spatial.ExistentialFlag_FALSE:
j[idx] = int64(0)
case spatial.ExistentialFlag_TRUE:
j[idx] = int64(1)
default:
j[idx] = int64(-1)
}
}

return j
}

pip_req := &pip.PointInPolygonRequest{
Latitude: float64(spatial_req.Latitude),
Longitude: float64(spatial_req.Longitude),
Placetypes: spatial_req.Placetypes,
Geometries: spatial_req.Geometries,
AlternateGeometries: spatial_req.AlternateGeometries,
InceptionDate: spatial_req.InceptionDate,
CessationDate: spatial_req.CessationDate,
Sort: spatial_req.Sort,
Properties: spatial_req.Properties,
IsCurrent: asInt64(spatial_req.IsCurrent),
IsCeased: asInt64(spatial_req.IsCeased),
IsDeprecated: asInt64(spatial_req.IsDeprecated),
IsSuperseded: asInt64(spatial_req.IsSuperseded),
IsSuperseding: asInt64(spatial_req.IsSuperseding),
}

return pip_req
}

func NewPointInPolygonRequestFromFlagSet(fs *flag.FlagSet) (*spatial.PointInPolygonRequest, error) {

pip_req, err := pip.NewPointInPolygonRequestFromFlagSet(fs)

if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to create request from flagset, %w", err)
}

return NewPointInPolygonRequest(pip_req)
Expand Down Expand Up @@ -43,6 +85,8 @@ func NewPointInPolygonRequest(pip_req *pip.PointInPolygonRequest) (*spatial.Poin
IsDeprecated: is_deprecated,
IsSuperseded: is_superseded,
IsSuperseding: is_superseding,
Sort: pip_req.Sort,
Properties: pip_req.Properties,
}

return req, nil
Expand Down
26 changes: 7 additions & 19 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package server

import (
"context"
"fmt"
"github.com/whosonfirst/go-whosonfirst-flags"
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/request"
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/spatial"
"github.com/whosonfirst/go-whosonfirst-spatial-pip"
"github.com/whosonfirst/go-whosonfirst-spatial/app"
"github.com/whosonfirst/go-whosonfirst-spr/v2"
_ "log"
)

type SpatialServer struct {
Expand All @@ -26,24 +27,11 @@ func NewSpatialServer(app *app.SpatialApplication) (*SpatialServer, error) {

func (s *SpatialServer) PointInPolygon(ctx context.Context, req *spatial.PointInPolygonRequest) (*spatial.StandardPlacesResults, error) {

coord, err := request.CoordsFromPointInPolygonRequest(req)

if err != nil {
return nil, err
}

f, err := request.SPRFilterFromPointInPolygonRequest(req)

if err != nil {
return nil, err
}

spatial_db := s.app.SpatialDatabase

pip_rsp, err := spatial_db.PointInPolygon(ctx, &coord, f)
pip_req := request.PIPRequestFromSpatialRequest(req)
pip_rsp, err := pip.QueryPointInPolygon(ctx, s.app, pip_req)

if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to perform point in polygon operation, %w", err)
}

results := pip_rsp.Results()
Expand All @@ -68,13 +56,13 @@ func (s *SpatialServer) PointInPolygonStream(req *spatial.PointInPolygonRequest,
coord, err := request.CoordsFromPointInPolygonRequest(req)

if err != nil {
return err
return fmt.Errorf("Failed to derive coordinate from request, %w", err)
}

f, err := request.SPRFilterFromPointInPolygonRequest(req)

if err != nil {
return err
return fmt.Errorf("Failed to derive filter from request, %w", err)
}

ctx := context.Background()
Expand Down
Loading

0 comments on commit c492b20

Please sign in to comment.