placetypes

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: BSD-3-Clause Imports: 9 Imported by: 30

README

go-whosonfirst-placetypes

Go package for working with Who's On First placetypes.

Example

Simple
import (
       "github.com/whosonfirst/go-whosonfirst-placetypes"
       "log"
)

log.Println(placetypes.IsValidPlacetype("county"))
log.Println(placetypes.IsValidPlacetype("microhood"))
log.Println(placetypes.IsValidPlacetype("accelerator"))

id := int64(102312307)
log.Println(placetypes.IsValidPlacetypeId(id))          

Yields:

true
true
false
true

Tools

$> make cli
go build -mod vendor -o bin/wof-placetype-ancestors cmd/wof-placetype-ancestors/main.go
go build -mod vendor -o bin/wof-placetype-children cmd/wof-placetype-children/main.go
go build -mod vendor -o bin/wof-placetype-descendants cmd/wof-placetype-descendants/main.go
go build -mod vendor -o bin/wof-valid-placetype cmd/wof-valid-placetype/main.go
wof-placetype-ancestors
./bin/wof-placetype-ancestors -role common -role common_optional -role optional locality
2018/08/23 17:09:53 0 localadmin
2018/08/23 17:09:53 1 county
2018/08/23 17:09:53 2 macrocounty
2018/08/23 17:09:53 3 region
2018/08/23 17:09:53 4 macroregion
2018/08/23 17:09:53 5 dependency
2018/08/23 17:09:53 6 empire
2018/08/23 17:09:53 7 country
2018/08/23 17:09:53 8 continent
2018/08/23 17:09:53 9 disputed
2018/08/23 17:09:53 10 planet

./bin/wof-placetype-ancestors -role common -role common_optional -role optional enclosure
2018/08/23 17:10:42 0 venue
2018/08/23 17:10:42 1 arcade
2018/08/23 17:10:42 2 concourse
2018/08/23 17:10:42 3 wing
2018/08/23 17:10:42 4 building
2018/08/23 17:10:42 5 address
2018/08/23 17:10:42 6 intersection
2018/08/23 17:10:42 7 campus
2018/08/23 17:10:42 8 microhood
2018/08/23 17:10:42 9 neighbourhood
2018/08/23 17:10:42 10 macrohood
2018/08/23 17:10:42 11 borough
2018/08/23 17:10:42 12 locality
2018/08/23 17:10:42 13 localadmin
2018/08/23 17:10:42 14 county
2018/08/23 17:10:42 15 macrocounty
2018/08/23 17:10:42 16 region
2018/08/23 17:10:42 17 macroregion
2018/08/23 17:10:42 18 dependency
2018/08/23 17:10:42 19 empire
2018/08/23 17:10:42 20 country
2018/08/23 17:10:42 21 continent
2018/08/23 17:10:42 22 disputed
2018/08/23 17:10:42 23 planet
wof-placetype-children
./bin/wof-placetype-children locality
2018/08/24 18:16:53 0 borough
2018/08/24 18:16:53 1 postalcode
2018/08/24 18:16:53 2 macrohood
2018/08/24 18:16:53 3 neighbourhood
2018/08/24 18:16:53 4 campus
wof-placetype-descendants
./bin/wof-placetype-descendants -role common -role common_optional -role optional country
2018/08/24 18:15:49 0 marinearea
2018/08/24 18:15:49 1 timezone
2018/08/24 18:15:49 2 disputed
2018/08/24 18:15:49 3 macroregion
2018/08/24 18:15:49 4 region
2018/08/24 18:15:49 5 macrocounty
2018/08/24 18:15:49 6 county
2018/08/24 18:15:49 7 localadmin
2018/08/24 18:15:49 8 locality
2018/08/24 18:15:49 9 postalcode
2018/08/24 18:15:49 10 campus
2018/08/24 18:15:49 11 borough
2018/08/24 18:15:49 12 macrohood
2018/08/24 18:15:49 13 neighbourhood
2018/08/24 18:15:49 14 microhood
2018/08/24 18:15:49 15 intersection
2018/08/24 18:15:49 16 address
2018/08/24 18:15:49 17 building
2018/08/24 18:15:49 18 venue
2018/08/24 18:15:49 19 wing
2018/08/24 18:15:49 20 concourse
2018/08/24 18:15:49 21 arcade
2018/08/24 18:15:49 22 installation
2018/08/24 18:15:49 23 enclosure
wof-valid-placetype
$> ./bin/wof-valid-placetype bob custom building locality
2021/02/19 17:35:05 bob	false
2021/02/19 17:35:05 custom	true
2021/02/19 17:35:05 building	true
2021/02/19 17:35:05 locality	true

See also

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AppendPlacetype added in v0.2.0

func AppendPlacetype(pt WOFPlacetype) error

func AppendPlacetypeSpecification added in v0.2.2

func AppendPlacetypeSpecification(spec *WOFPlacetypeSpecification) error

func IsAncestor added in v0.4.0

func IsAncestor(a *WOFPlacetype, b *WOFPlacetype) bool

Returns true is 'b' is an ancestor of 'a'.

func IsDescendant added in v0.4.0

func IsDescendant(a *WOFPlacetype, b *WOFPlacetype) bool

Returns true is 'b' is a descendant of 'a'.

func IsValidPlacetype

func IsValidPlacetype(name string) bool

IsValidPlacetypeId returns a boolean value indicating whether 'name' is a known and valid placetype name.

func IsValidPlacetypeId

func IsValidPlacetypeId(id int64) bool

IsValidPlacetypeId returns a boolean value indicating whether 'id' is a known and valid placetype ID.

Types

type WOFPlacetype

type WOFPlacetype struct {
	Id     int64   `json:"id"`
	Name   string  `json:"name"`
	Role   string  `json:"role"`
	Parent []int64 `json:"parent"`
}

func Ancestors

func Ancestors(pt *WOFPlacetype) []*WOFPlacetype

Ancestors returns the ancestors of role "common" for 'pt'.

func AncestorsForRoles

func AncestorsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype

AncestorsForRoles returns the ancestors matching any role in 'roles' for 'pt'.

func Children

func Children(pt *WOFPlacetype) []*WOFPlacetype

Children returns the immediate child placetype of 'pt'.

func Descendants

func Descendants(pt *WOFPlacetype) []*WOFPlacetype

Descendants returns the descendants of role "common" for 'pt'.

func DescendantsForRoles

func DescendantsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype

DescendantsForRoles returns the descendants matching any role in 'roles' for 'pt'.

func GetPlacetypeById

func GetPlacetypeById(id int64) (*WOFPlacetype, error)

func GetPlacetypeByName

func GetPlacetypeByName(name string) (*WOFPlacetype, error)

func Placetypes added in v0.1.1

func Placetypes() ([]*WOFPlacetype, error)

Placetypes returns all the known placetypes for the 'common', 'optional' and 'common_optional' roles.

func PlacetypesForRoles added in v0.1.2

func PlacetypesForRoles(roles []string) ([]*WOFPlacetype, error)

type WOFPlacetypeAltNames

type WOFPlacetypeAltNames map[string][]string

type WOFPlacetypeName

type WOFPlacetypeName struct {
	// Lang is the RFC 5646 (BCP-47) language tag for the placetype name
	Lang string `json:"language"`
	Kind string `json:"kind"`
	// Name is the name of the placetype (in the language defined by `Lang`)
	Name string `json:"name"`
}

type WOFPlacetypeSpecification

type WOFPlacetypeSpecification struct {
	// contains filtered or unexported fields
}

func DefaultWOFPlacetypeSpecification added in v0.2.1

func DefaultWOFPlacetypeSpecification() (*WOFPlacetypeSpecification, error)

func NewWOFPlacetypeSpecification added in v0.2.1

func NewWOFPlacetypeSpecification(body []byte) (*WOFPlacetypeSpecification, error)

func NewWOFPlacetypeSpecificationWithReader added in v0.2.3

func NewWOFPlacetypeSpecificationWithReader(r io.Reader) (*WOFPlacetypeSpecification, error)

func (*WOFPlacetypeSpecification) AppendPlacetype added in v0.2.0

func (spec *WOFPlacetypeSpecification) AppendPlacetype(pt WOFPlacetype) error

func (*WOFPlacetypeSpecification) AppendPlacetypeSpecification added in v0.2.2

func (spec *WOFPlacetypeSpecification) AppendPlacetypeSpecification(other_spec *WOFPlacetypeSpecification) error

func (*WOFPlacetypeSpecification) Catalog added in v0.2.0

func (spec *WOFPlacetypeSpecification) Catalog() map[string]WOFPlacetype

func (*WOFPlacetypeSpecification) GetPlacetypeById added in v0.2.0

func (spec *WOFPlacetypeSpecification) GetPlacetypeById(id int64) (*WOFPlacetype, error)

func (*WOFPlacetypeSpecification) GetPlacetypeByName added in v0.2.0

func (spec *WOFPlacetypeSpecification) GetPlacetypeByName(name string) (*WOFPlacetype, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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