hierarchy

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2023 License: BSD-3-Clause Imports: 20 Imported by: 6

README

go-whosonfirst-spatial-hierarchy

Opionated Who's On First (WOF) hierarchy for go-whosonfirst-spatial packages.

Documentation

Go Reference

Documentation is incomplete.

Example

import (
	_ "github.com/whosonfirst/go-whosonfirst-spatial-sqlite"
)

import (
	"github.com/whosonfirst/go-whosonfirst-spatial-hierarchy"
	hierarchy_filter "github.com/whosonfirst/go-whosonfirst-spatial-hierarchy/filter"		
	"github.com/whosonfirst/go-whosonfirst-spatial/database"
	spatial_filter "github.com/whosonfirst/go-whosonfirst-spatial/filter"
)

body := []byte(`{"type":"Feature" ...}`)

spatial_db, _ := database.NewSpatialDatabase(ctx, "sqlite://?dsn=/usr/local/data/whosonfirst.db")

resolver_opts := &hierarchy.PointInPolygonHierarchyResolverOptions{
	Database: spatial_db,
}

resolver, _ := hierarchy.NewPointInPolygonHierarchyResolver(ctx, resolver_opts)

inputs := &spatial_filter.SPRInputs{}

results_cb := hierarchy_filter.FirstButForgivingSPRResultsFunc
update_cb := hierarchy.DefaultPointInPolygonHierarchyResolverUpdateCallback()
		
new_body, _ := resolver.PointInPolygonAndUpdate(ctx, inputs, results_cb, update_cb, body)

See also

Documentation

Overview

package hierarchy provides methods for deriving hierarchies from and associated with Who's On First records.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PointInPolygonHierarchyResolver

type PointInPolygonHierarchyResolver struct {
	// Database is the `database.SpatialDatabase` instance used to perform point-in-polygon requests.
	Database database.SpatialDatabase
	// Mapshaper is an optional `mapshaper.Client` instance used to derive centroids used in point-in-polygon requests.
	Mapshaper *mapshaper.Client
	// PlacetypesDefinition is an optional `go-whosonfirst-placetypes.Definition` instance used to resolve custom or bespoke placetypes.
	PlacetypesDefinition placetypes.Definition
	// Logger is a `log.Logger` instance for logging feedback. The default logger sends all messages to `io.Discard`.
	Logger *log.Logger
	// contains filtered or unexported fields
}

PointInPolygonHierarchyResolver provides methods for constructing a hierarchy of ancestors for a given point, following rules established by the Who's On First project.

func NewPointInPolygonHierarchyResolver

func NewPointInPolygonHierarchyResolver(ctx context.Context, opts *PointInPolygonHierarchyResolverOptions) (*PointInPolygonHierarchyResolver, error)

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.

func (*PointInPolygonHierarchyResolver) PointInPolygon

func (t *PointInPolygonHierarchyResolver) PointInPolygon(ctx context.Context, inputs *filter.SPRInputs, body []byte) ([]spr.StandardPlacesResult, error)

PointInPolygon will perform a point-in-polygon (reverse geocoding) operation for 'body' using zero or more 'inputs' as query filters. This is known to not work as expected if the `wof:placetype` property is "common". There needs to be a way to a) retrieve placetypes using a custom WOFPlacetypeSpecification (go-whosonfirst-placetypes v0.6.0+) and b) specify an alternate property to retrieve placetypes from if `wof:placetype=custom`.

func (*PointInPolygonHierarchyResolver) PointInPolygonAndUpdate

PointInPolygonAndUpdate will ...

func (*PointInPolygonHierarchyResolver) PointInPolygonCentroid

func (t *PointInPolygonHierarchyResolver) PointInPolygonCentroid(ctx context.Context, body []byte) (*orb.Point, error)

PointInPolygonCentroid derives an *orb.Point (or "centroid") to use for point-in-polygon operations.

func (*PointInPolygonHierarchyResolver) SetReader added in v0.4.0

func (t *PointInPolygonHierarchyResolver) SetReader(r reader.Reader)

SetReader assigns 'r' as the internal `reader.Reader` instance used to retrieve ancestor records when resolving a hierarchy.

type PointInPolygonHierarchyResolverOptions added in v0.5.0

type PointInPolygonHierarchyResolverOptions struct {
	// Database is the `database.SpatialDatabase` instance used to perform point-in-polygon requests.
	Database database.SpatialDatabase
	// Mapshaper is an optional `mapshaper.Client` instance used to derive centroids used in point-in-polygon requests.
	Mapshaper *mapshaper.Client
	// PlacetypesDefinition is an optional `go-whosonfirst-placetypes.Definition` instance used to resolve custom or bespoke placetypes.
	PlacetypesDefinition placetypes.Definition
	// Logger is an optional `log.Logger` instance for logging feedback.
	Logger *log.Logger
	// 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. 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.
	Roles []string
}

type PointInPolygonHierarchyResolverUpdateCallback

type PointInPolygonHierarchyResolverUpdateCallback func(context.Context, reader.Reader, spr.StandardPlacesResult) (map[string]interface{}, error)

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'.

func DefaultPointInPolygonHierarchyResolverUpdateCallback

func DefaultPointInPolygonHierarchyResolverUpdateCallback() PointInPolygonHierarchyResolverUpdateCallback

DefaultPointInPolygonHierarchyResolverUpdateCallback returns a `PointInPolygonHierarchyResolverUpdateCallback` function that will return a dictionary containing the following properties: wof:parent_id, wof:country, wof:hierarchy

Directories

Path Synopsis
app
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL