diff --git a/go.mod b/go.mod index a5aa1bc5..b821ce82 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/whosonfirst/go-ioutil v1.0.2 github.com/whosonfirst/go-reader v1.0.2 - github.com/whosonfirst/go-whosonfirst-spatial v0.9.1 + github.com/whosonfirst/go-whosonfirst-spatial v0.9.0 github.com/whosonfirst/go-whosonfirst-spatial-www v0.2.0 github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.7 github.com/whosonfirst/go-whosonfirst-sqlite-features/v2 v2.0.3 diff --git a/go.sum b/go.sum index d48e6b25..98dda2da 100644 --- a/go.sum +++ b/go.sum @@ -340,8 +340,8 @@ github.com/whosonfirst/go-whosonfirst-reader v1.0.2 h1:yLsDd6GJOsfMVJz63noH5Haoo github.com/whosonfirst/go-whosonfirst-reader v1.0.2/go.mod h1:1M6osxb9qXB3+ARINW4vuEaCTIN55abLRBGbBtfpGJ0= 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.9.1 h1:MJNp5mUICQ6uVBnN2NcvodylL+B8RYfTBvGvo6RqH2w= -github.com/whosonfirst/go-whosonfirst-spatial v0.9.1/go.mod h1:ZYUHliaEMtm3R43ZBTgdRVGhnF92LbrBehUSmR2T7go= +github.com/whosonfirst/go-whosonfirst-spatial v0.9.0 h1:uDIqg36IKvGF1XIIQnhQX/8w21dcWH3P1WPjKlzt+bk= +github.com/whosonfirst/go-whosonfirst-spatial v0.9.0/go.mod h1:ZZDfswfjQliuqqNCrpLHW2LVwR7S7QaVMtFiTdvEQH0= github.com/whosonfirst/go-whosonfirst-spatial-www v0.2.0 h1:LpjuvmBznHQnYbYquo0YPYSJy0dab2sBRP5t6I5A9HU= github.com/whosonfirst/go-whosonfirst-spatial-www v0.2.0/go.mod h1:yoPKlKjXg0fdRnMuZhcuurn2mBKnN3dMli/4w8TYGas= github.com/whosonfirst/go-whosonfirst-spr-geojson v0.0.8 h1:K0rCaKo0xvOtuS/x9r62bEfIK3OTdZqbDmgG+A3xDSs= diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md index d749c17c..3de42b87 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md @@ -12,8 +12,9 @@ The goal of the `go-whosonfirst-spatial` package is to de-couple the various com It is the "base" package that defines provider-agnostic, but WOF-specific, interfaces for a limited set of spatial queries and reading properties. -These interfaces are then implemented in full or in part by provider-specific classes. For example, an in-memory RTree index (which is part of this package) or a SQLite database or even a Protomaps database: +These interfaces are then implemented in full or in part by provider-specific classes. For example, an in-memory RTree index or a SQLite database or even a Protomaps database: +* https://github.com/whosonfirst/go-whosonfirst-spatial-rtree * https://github.com/whosonfirst/go-whosonfirst-spatial-sqlite * https://github.com/whosonfirst/go-whosonfirst-spatial-pmtiles @@ -96,23 +97,19 @@ type Filter interface { _Where `flags.*` refers to the [whosonfirst/go-whosonfirst-flags](https://github.com/whosonfirst/go-whosonfirst-flags) package._ -## Database Implementations - -### SQLite +## Implementations +* https://github.com/whosonfirst/go-whosonfirst-spatial-rtree * https://github.com/whosonfirst/go-whosonfirst-spatial-sqlite - -### PMTiles - * https://github.com/whosonfirst/go-whosonfirst-spatial-pmtiles ## Servers and clients -### Web (HTTP) +### WWW * https://github.com/whosonfirst/go-whosonfirst-spatial-www - -_Remember, this package implements the guts of a web application but does not support any particular database by default. It is meant to be imported by a database-specific implementation (see above) and exposed as a `cmd/server` application (for example) by that package._ +* https://github.com/whosonfirst/go-whosonfirst-spatial-www-sqlite +* https://github.com/whosonfirst/go-whosonfirst-spatial-www-pmtiles ### gRPC @@ -120,7 +117,11 @@ _Remember, this package implements the guts of a web application but does not su * https://github.com/whosonfirst/go-whosonfirst-spatial-grpc-sqlite * https://github.com/whosonfirst/go-whosonfirst-spatial-grpc-pmtiles -_Note, the gRPC code has not been updated in a while and needs to be refactored to follow the model of the `go-whosonfirst-spatial-www` pacakge._ +## Services and Operations + +* https://github.com/whosonfirst/go-whosonfirst-spatial-pip +* https://github.com/whosonfirst/go-whosonfirst-spatial-hierarchy + ## See also * https://github.com/whosonfirst/go-whosonfirst-spr diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/pip/options.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/pip/options.go index 0278757e..625cfdb4 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/pip/options.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/app/pip/options.go @@ -17,20 +17,20 @@ type RunOptions struct { EnableCustomPlacetypes bool `json:"enable_custom_placetypes"` CustomPlacetypes string `json:"custom_placetypes"` IsWhosOnFirst bool `json:"is_whosonfirst"` - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - Placetypes []string `json:"placetypes,omitempty"` - Geometries string `json:"geometries,omitempty"` - AlternateGeometries []string `json:"alternate_geometries,omitempty"` - IsCurrent []int64 `json:"is_current,omitempty"` - IsCeased []int64 `json:"is_ceased,omitempty"` - IsDeprecated []int64 `json:"is_deprecated,omitempty"` - IsSuperseded []int64 `json:"is_superseded,omitempty"` - IsSuperseding []int64 `json:"is_superseding,omitempty"` - InceptionDate string `json:"inception_date,omitempty"` - CessationDate string `json:"cessation_date,omitempty"` - Properties []string `json:"properties,omitempty"` - Sort []string `json:"sort,omitempty"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Placetypes []string `json:"placetypes,omitempty"` + Geometries string `json:"geometries,omitempty"` + AlternateGeometries []string `json:"alternate_geometries,omitempty"` + IsCurrent []int64 `json:"is_current,omitempty"` + IsCeased []int64 `json:"is_ceased,omitempty"` + IsDeprecated []int64 `json:"is_deprecated,omitempty"` + IsSuperseded []int64 `json:"is_superseded,omitempty"` + IsSuperseding []int64 `json:"is_superseding,omitempty"` + InceptionDate string `json:"inception_date,omitempty"` + CessationDate string `json:"cessation_date,omitempty"` + Properties []string `json:"properties,omitempty"` + Sort []string `json:"sort,omitempty"` } func RunOptionsFromFlagSet(ctx context.Context, fs *flag.FlagSet) (*RunOptions, error) { diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/filter/filter.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/filter/filter.go index 2ca7ea43..5a05c4a8 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/filter/filter.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/filter/filter.go @@ -16,8 +16,6 @@ func FilterSPR(filters spatial.Filter, s spr.StandardPlacesResult) error { var ok bool - slog.Debug("Create placetype flag for SPR filtering", "placetype", s.Placetype()) - pf, err := placetypes.NewPlacetypeFlag(s.Placetype()) if err != nil { diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/README.md b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/README.md deleted file mode 100644 index 072a958b..00000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/README.md +++ /dev/null @@ -1,166 +0,0 @@ -# Point-in-polygon "hierarchy resolvers" - -At a high-level a point-in-polygon "hierarchy resolver" consists of (4) parts: - -* Given a GeoJSON Feature use its geometry to derive the most appropriate centroid for performing a point-in-polygon query -* Perform a point-in-polygon query for a centroid, excluding results using criteria defined by zero or more filters. -* Convert the list of candidate results (derived from the point-in-polygon query) in to a single result using a callback function. -* Apply updates derived from the final result to the original GeoJSON Feature using a callback function. - -These functionalities are implemented by the `hierarchy.PointInPolygonHierarchyResolver` package. In addition to wrapping all those moving pieces the `hierachy` package also exports a handful of predefined callback functions to use for filtering results and applying updates. - -## Example - -The following examples describe how to use the `hierarchy.PointInPolygonHierarchyResolver` package in abbreviated (incomplete) and annotated code. - -_Note: For the sake of brevity all error-handling has been removed from these examples._ - -### Basic - -This example demonstrates how to use the `hierarchy.PointInPolygonHierarchyResolver` package with a set of "core" Who's On First documents. - -``` -import ( - "context" - - "github.com/sfomuseum/go-sfomuseum-mapshaper" - "github.com/whosonfirst/go-whosonfirst-spatial/database" - _ "github.com/whosonfirst/go-whosonfirst-spatial-sqlite" - "github.com/whosonfirst/go-whosonfirst-spatial/filter" - "github.com/whosonfirst/go-whosonfirst-spatial/hierarchy" - hierarchy_filter "github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/filter" -) - -func main() { - - ctx := context.Background() - - // The Mapshaper "client" (and its associated "server") is not required by a point-in-polygon - // hierarchy resolver but is included in this example for the sake of thoroughness. If present - // it will be used to derive the centroid for a GeoJSON Feature using the Mapshape "inner point" - // command. Both the "client" and "server" components are part of the [sfomuseum/go-sfomuseum-mapshaper](#) - // package but setting up and running the "server" component is out of scope for this document. - // Basically Mapshaper's "inner point" functonality can't be ported to Go fast enough. - // - // If the mapshaper client is `nil` then there are a variety of other heuristics that will be - // used, based on the content of the input GeoJSON Feature, to derive a candidate centroid to - // be used for point-in-polygon operations. - mapshaper_cl, _ := mapshaper.NewClient(ctx, "http://localhost:8080") - - // Create a new spatial database instance. For the sake of this example it - // is assumed that the database has already been populated with records. - spatial_db, _ := database.NewSpatialDatabase(ctx, "sqlite://?dsn=modernc://cwd/example.db") - - // Create configuration options for hierarchy resolver - resolver_opts := &hierarchy.PointInPolygonHierarchyResolverOptions{ - Database: spatial_db, - Mapshaper: mapshaper_cl, - } - - // Create the hierarchy resolver itself - resolver, _ := hierarchy.NewPointInPolygonHierarchyResolver(ctx, resolver_opts) - - // Create zero or more filters to prune point-in-polygon results with, in this case - // only return records whose `mz:is_current` property is "1". - pip_inputs := &filter.SPRInputs{ - IsCurrent: []int64{1}, - } - - // Instantiate a predefined results callback function that returns the first result in a list - // of candidates but does not trigger an error if that list is empty. - results_cb := hierarchy_filter.FirstButForgivingSPRResultsFunc - - // Instantiate a predefined update callback that will return a dictionary populated with the - // following properties from the final point-in-polygon result (derived from `results_cb`): - // wof:parent_id, wof:hierarchy, wof:country - update_cb := hierarchy.DefaultPointInPolygonHierarchyResolverUpdateCallback() - - // Where body is assumed to be a valid Who's On First style GeoJSON Feature - var body []byte - - // Invoke the hierarchy resolver's `PointInPolygonAndUpdate` method using `body` as the input - // parameter. - updates, _ := resolver.PointInPolygonAndUpdate(ctx, pip_inputs, results_cb, update_cb, body) - - // Apply updates to body here -} -``` - -### Custom placetypes - -This example demonstrates how to the `hierarchy.PointInPolygonHierarchyResolver` package with a set of Who's On First style documents that contain custom placetypes (defined in a separate property from the default `wof:placetype` property). - -``` -import ( - "context" - - "github.com/sfomuseum/go-sfomuseum-mapshaper" - _ "github.com/sfomuseum/go-sfomuseum-placetypes" - "github.com/whosonfirst/go-whosonfirst-placetypes" - "github.com/whosonfirst/go-whosonfirst-spatial/database" - _ "github.com/whosonfirst/go-whosonfirst-spatial-sqlite" - "github.com/whosonfirst/go-whosonfirst-spatial/filter" - "github.com/whosonfirst/go-whosonfirst-spatial/hierarchy" - hierarchy_filter "github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/filter" -) - -func main() { - - mapshaper_cl, _ := mapshaper.NewClient(ctx, "http://localhost:8080") - - spatial_db, _ := database.NewSpatialDatabase(ctx, "sqlite://?dsn=modernc://cwd/example.db") - - // Create a new custom placetypes definition. In this case the standard Who's On First places - // definition supplemented with custom placetypes used by SFO Museum. This is used to derive - // the list of (custom) ancestors associated with any given (custom) placetype. - pt_def, _ := placetypes.NewDefinition(ctx, "sfomuseum://") - - // Append the custom placetypes definition to the hierarchy resolver options AND explicitly - // disable placetype filtering (removing candidates that are not ancestors of the placetype - // of the Who's On First GeoJSON Feature being PIP-ed. - // - // If you don't disable default placetype filtering you will need to ensure that the `wof:placetype` - // property of the features in the spatial database are manually reassigned to take the form - // of "PLACETYPE" + "#" + "PLACETYPE_DEFINITION_URI", for example: "airport#sfomuseum://" - // - // More accurately though the requirement is less that you need to alter the values in the underlying - // database so much as ensure that the value returned by the `Placetype` method of each `StandardPlacesResult` - // (SPR) candidate result produced during a point-in-polygon operation is formatted that way. There is - // more than one way to do this but as a practical matter it's probably easiest to store that (formatted) - // value in the database IF the database itself is transient. There can be no guarantees thought that - // a change like this won't have downstream effects on the rest of your code. - // - // If you're curious the "PLACETYPE" + "#" + "PLACETYPE_DEFINITION_URI" syntax is parsed by the - // code used to create placetype filter flags in the `whosonfirst/go-whosonfirst-flags` package and - // used to load custom definitions on the fly to satisfy tests. - // - // Basically, custom placetypes make things more complicated because they are... well, custom. At a - // certain point it may simply be easier to disable default placetype checks in your own custom results - // filtering callback function. - resolver_opts := &hierarchy.PointInPolygonHierarchyResolverOptions{ - Database: spatial_db, - Mapshaper: mapshaper_cl, - PlacetypesDefinition: pt_def, - SkipPlacetypeFilter: true, - } - - resolver, _ := hierarchy.NewPointInPolygonHierarchyResolver(ctx, resolver_opts) - - pip_inputs := &filter.SPRInputs{ - IsCurrent: []int64{1}, - } - - // In the case of SFO Museum related records here is a custom results callback that implements its - // own placetype and floor level checking. - results_cb := sfom_hierarchy.ChoosePointInPolygonCandidateStrict - - update_cb := hierarchy.DefaultPointInPolygonHierarchyResolverUpdateCallback() - - var body []byte - - updates, _ := resolver.PointInPolygonAndUpdate(ctx, pip_inputs, results_cb, update_cb, body) - - // Apply updates to body here - -} -``` \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver.go index cb463045..06e5de4d 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "strconv" "github.com/paulmach/orb" "github.com/paulmach/orb/geojson" @@ -11,7 +12,9 @@ import ( "github.com/tidwall/gjson" "github.com/whosonfirst/go-reader" "github.com/whosonfirst/go-whosonfirst-export/v2" + "github.com/whosonfirst/go-whosonfirst-feature/properties" "github.com/whosonfirst/go-whosonfirst-placetypes" + wof_reader "github.com/whosonfirst/go-whosonfirst-reader" "github.com/whosonfirst/go-whosonfirst-spatial/database" "github.com/whosonfirst/go-whosonfirst-spatial/filter" "github.com/whosonfirst/go-whosonfirst-spatial/geo" @@ -27,12 +30,7 @@ type PointInPolygonHierarchyResolverOptions struct { // PlacetypesDefinition is an optional `go-whosonfirst-placetypes.Definition` instance used to resolve custom or bespoke placetypes. PlacetypesDefinition placetypes.Definition // SkipPlacetypeFilter is an optional boolean flag to signal whether or not point-in-polygon operations should be performed using - // the list of known ancestors for a given placetype. If you are using a custom placetypes defintion (see whosonfirst/go-whosonfirst-placetypes) - // and do not enable this flag you will need to manually re-assign the `wof:placetype` property of each record being ingested in to your spatial - // database to take the form of "{CUSTOM_PLACETYPE}#{CUSTOM_PLACETYPE_DEFINITION_URI}". This is necessary because by the time placetype filtering - // occurs the code is working with `whosonfirst/go-whosonfirst-spr.StandardPlacesResult` instances which only have access to a generic `Placetype` - // method. There is no guarantee that changing the default value of the `wof:placetype` property will not have unintended consequences so it might - // be easiest just to enable this flag and deal with placetype filtering in a custom `FilterSPRResultsFunc` callback. Default is false. + // the list of known ancestors for a given placetype. Default is false. SkipPlacetypeFilter bool // Roles is an optional list of Who's On First placetype roles used to derive ancestors during point-in-polygon operations. // If missing (or zero length) then all possible roles will be assumed. @@ -59,6 +57,54 @@ type PointInPolygonHierarchyResolver struct { roles []string } +// PointInPolygonHierarchyResolverUpdateCallback is a function definition for a custom callback to convert 'spr' in to a dictionary of properties +// containining hierarchy information. Records in 'spr' are expected to be able to be read from 'r'. +type PointInPolygonHierarchyResolverUpdateCallback func(context.Context, reader.Reader, spr.StandardPlacesResult) (map[string]interface{}, error) + +// DefaultPointInPolygonHierarchyResolverUpdateCallback returns a `PointInPolygonHierarchyResolverUpdateCallback` function that will return a dictionary +// containing the following properties: wof:parent_id, wof:country, wof:hierarchy +func DefaultPointInPolygonHierarchyResolverUpdateCallback() PointInPolygonHierarchyResolverUpdateCallback { + + fn := func(ctx context.Context, r reader.Reader, parent_spr spr.StandardPlacesResult) (map[string]interface{}, error) { + + to_update := make(map[string]interface{}) + + if parent_spr == nil { + + to_update = map[string]interface{}{ + "properties.wof:parent_id": -1, + } + + } else { + + parent_id, err := strconv.ParseInt(parent_spr.Id(), 10, 64) + + if err != nil { + return nil, fmt.Errorf("Failed to parse ID (%s), %w", parent_spr.Id(), err) + } + + parent_f, err := wof_reader.LoadBytes(ctx, r, parent_id) + + if err != nil { + return nil, fmt.Errorf("Failed to load body for %d, %w", parent_id, err) + } + + parent_hierarchy := properties.Hierarchies(parent_f) + parent_country := properties.Country(parent_f) + + to_update = map[string]interface{}{ + "properties.wof:parent_id": parent_id, + "properties.wof:country": parent_country, + "properties.wof:hierarchy": parent_hierarchy, + } + } + + return to_update, nil + } + + return fn +} + // NewPointInPolygonHierarchyResolver returns a `PointInPolygonHierarchyResolver` instance for 'spatial_db' and 'ms_client'. // The former is used to perform point in polygon operations and the latter is used to determine a "reverse geocoding" centroid // to use for point-in-polygon operations. @@ -144,15 +190,6 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygonAndUpdate(ctx context.Co // from if `wof:placetype=custom`. func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, inputs *filter.SPRInputs, body []byte) ([]spr.StandardPlacesResult, error) { - id_rsp := gjson.GetBytes(body, "properties.wof:id") - name_rsp := gjson.GetBytes(body, "properties.wof:name") - id := id_rsp.String() - name := name_rsp.String() - - logger := slog.Default() - logger = logger.With("id", id) - logger = logger.With("name", name) - centroid, err := t.PointInPolygonCentroid(ctx, body) if err != nil { @@ -162,9 +199,6 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, in lon := centroid.X() lat := centroid.Y() - logger = logger.With("latitude", lat) - logger = logger.With("longitude", lon) - coord, err := geo.NewCoordinate(lon, lat) if err != nil { @@ -179,7 +213,7 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, in return nil, fmt.Errorf("Failed to create SPR filter from input, %v", err) } - logger.Debug("Perform point in polygon with no placetype filter") + slog.Debug("Perform point in polygon with no placetype filter", "lat", lat, "lon", lon) rsp, err := t.Database.PointInPolygon(ctx, coord, spr_filter) @@ -190,13 +224,10 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, in // This should never happen... if rsp == nil { - logger.Warn("Failed to point in polygon with empty response, returning nil") return nil, fmt.Errorf("Failed to point in polygon for %v, null response", coord) } possible := rsp.Results() - - logger.Debug("Return unfiltered-by-placetype results", "count", len(possible)) return possible, nil } @@ -225,12 +256,8 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, in return nil, fmt.Errorf("Failed to create new placetype for '%s', %v", pt_str, err) } - logger = logger.With("placetype", pt_str) - ancestors := pt_spec.AncestorsForRoles(pt, t.roles) - // logger.Debug("Ancestors", "roles", t.roles, "ancestors", ancestors) - for _, a := range ancestors { pt_name := fmt.Sprintf("%s#%s", a.Name, pt_uri) @@ -243,7 +270,7 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, in return nil, fmt.Errorf("Failed to create SPR filter from input, %v", err) } - logger.Debug("Perform point in polygon with placetype filter", "placetype", pt_name) + slog.Debug("Perform point in polygon", "lat", lat, "lon", lon, "placetype", pt_name) rsp, err := t.Database.PointInPolygon(ctx, coord, spr_filter) @@ -260,20 +287,16 @@ func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, in results := rsp.Results() count := len(results) - logger.Debug("Point in polygon results after input filtering", "placetype", pt_name, "count", count) + slog.Debug("Point in polygon results", "lat", lat, "lon", lon, "placetype", pt_name, "count", count) if count == 0 { continue } possible = results - - // Something something something filter here something something something - break } - logger.Debug("Return possible candidates", "count", len(possible)) return possible, nil } diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver_update.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver_update.go deleted file mode 100644 index 57424e1e..00000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/hierarchy/resolver_update.go +++ /dev/null @@ -1,60 +0,0 @@ -package hierarchy - -import ( - "context" - "fmt" - "strconv" - - "github.com/whosonfirst/go-reader" - "github.com/whosonfirst/go-whosonfirst-feature/properties" - wof_reader "github.com/whosonfirst/go-whosonfirst-reader" - "github.com/whosonfirst/go-whosonfirst-spr/v2" -) - -// PointInPolygonHierarchyResolverUpdateCallback is a function definition for a custom callback to convert 'spr' in to a dictionary of properties -// containining hierarchy information. Records in 'spr' are expected to be able to be read from 'r'. -type PointInPolygonHierarchyResolverUpdateCallback func(context.Context, reader.Reader, spr.StandardPlacesResult) (map[string]interface{}, error) - -// DefaultPointInPolygonHierarchyResolverUpdateCallback returns a `PointInPolygonHierarchyResolverUpdateCallback` function that will return a dictionary -// containing the following properties: wof:parent_id, wof:country, wof:hierarchy -func DefaultPointInPolygonHierarchyResolverUpdateCallback() PointInPolygonHierarchyResolverUpdateCallback { - - fn := func(ctx context.Context, r reader.Reader, parent_spr spr.StandardPlacesResult) (map[string]interface{}, error) { - - to_update := make(map[string]interface{}) - - if parent_spr == nil { - - to_update = map[string]interface{}{ - "properties.wof:parent_id": -1, - } - - } else { - - parent_id, err := strconv.ParseInt(parent_spr.Id(), 10, 64) - - if err != nil { - return nil, fmt.Errorf("Failed to parse ID (%s), %w", parent_spr.Id(), err) - } - - parent_f, err := wof_reader.LoadBytes(ctx, r, parent_id) - - if err != nil { - return nil, fmt.Errorf("Failed to load body for %d, %w", parent_id, err) - } - - parent_hierarchy := properties.Hierarchies(parent_f) - parent_country := properties.Country(parent_f) - - to_update = map[string]interface{}{ - "properties.wof:parent_id": parent_id, - "properties.wof:country": parent_country, - "properties.wof:hierarchy": parent_hierarchy, - } - } - - return to_update, nil - } - - return fn -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 208616b2..e4cf8e56 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -500,7 +500,7 @@ github.com/whosonfirst/go-whosonfirst-reader ## explicit; go 1.12 github.com/whosonfirst/go-whosonfirst-sources github.com/whosonfirst/go-whosonfirst-sources/sources -# github.com/whosonfirst/go-whosonfirst-spatial v0.9.1 +# github.com/whosonfirst/go-whosonfirst-spatial v0.9.0 ## explicit; go 1.22.2 github.com/whosonfirst/go-whosonfirst-spatial github.com/whosonfirst/go-whosonfirst-spatial/app/hierarchy/update