placekey

package module
v0.0.0-...-fe4ca90 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

placekey-go

A Go library for working with Placekeys. This is an unofficial port of the Python library placekey-py and is not affiliated with the Placekey project.

Status

This library port is mostly complete. A client interface to the Placekeys API is also included. Some geospatial features are currently under development, namely getting a Placekey from a Polygon, WKT or GeoJSON.

Usage

Prerequisites

This library depends on uber/h3-go and inherits the same prerequisites. It requires CGO (CGO_ENABLED=1) in order to be built.

If you see errors/warnings like "build constraints exclude all Go files...", then the cgo build constraint is likely disabled; try setting CGO_ENABLED=1 environment variable for your build step.

Installation
golang/cmd/go
go get github.com/engelsjk/placekey-go
Quickstart
import "github.com/engelsjk/placekey-go"

func ExampleFromGeo() {
    placekey.FromGeo(37.23712, -115.80187)
    // Output:
    // @5ys-rsx-4jv
}

func ExampleToH3() {
    placekey.ToH3("@5yv-j8h-3nq")
    // Output:
    // 8a2986b843b7fff
}

func ExampleDistance() {
    placekey.Distance("@5ys-rsx-4jv", "@5yv-j8h-3nq")
    // Output:
    // 138681.552855
}

func ExampleGeoJSON() {
    placekey.ToGeoJSON("@5yv-j8h-3nq")
    // Output:
    // {"type":"Feature","geometry":{"type":"Polygon","coordinates":[...]},"properties":null}
}

func ExampleDistance() {
    placekey.ToWKT("@5yv-j8h-3nq")
    // Output:
    // POLYGON(...)
}

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(placekey1, placekey2 string) float64

Distance returns the distance in meters between the centers of two Placekeys.

func FormatIsValid

func FormatIsValid(placekey string) bool

FormatIsValid returns a boolean for whether or not the format of a Placekey is valid, including checks for valid encoding of location.

func FromGeo

func FromGeo(lat, lon float64) string

FromGeo converts a (latitude, longitude) into a Placekey.

func FromH3

func FromH3(h3String string) string

FromH3 converts an H3 hexadecimal string into a Placekey string.

func FromH3Int

func FromH3Int(h3Int uint64) string

H3IntToPlacekey converts an H3 integer into a Placekey.

func GetPrefixDistanceMap

func GetPrefixDistanceMap() map[int]float64

GetPrefixDistanceMap returns a map of the length of a shared Placekey prefix to the maximal distance in meters between two Placekeys sharing a prefix of that length.

func ToGeo

func ToGeo(placekey string) (float64, float64)

ToGeo converts a Placekey into a (latitude, longitude).

func ToGeoJSON

func ToGeoJSON(placekey string) string

ToGeoJSON returns the Polygon boundary of a Placekey as a GeoJSON Feature string.

func ToH3

func ToH3(placekey string) string

ToH3 converts a Placekey string into an H3 string.

func ToH3Int

func ToH3Int(placekey string) uint64

ToH3Int converts a Placekey to an H3 integer.

func ToHexBoundary

func ToHexBoundary(placekey string) [][]float64

ToHexBoundary returns the Polygon boundary of a Placekey as a slice of (latitude, longitude) coordinates.

func ToPolygon

func ToPolygon(placekey string) orb.Polygon

ToPolygon returns the Polygon boundary of a Placekey as an orb.Polygon.

func ToWKT

func ToWKT(placekey string) string

ToWKT returns the Polygon boundary of a Placekey as a Well-Known Text (WKT) string.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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