nangoturf

package module
v0.0.0-...-1752d5f Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 6 Imported by: 0

README

NangoTurf - TurfJS like library for golang

nangoturf is a (partial) port of the popular TurfJS library to golang.

It's build upon go.geojson (be sure to check out orb) and just offers convenience functions with the semantics of TurfJS.

(partially) implemented packages

  • circle
  • bbox
  • random
  • meta

Run tests

go test -coverprofile cover.out
go tool cover -html=cover.out -o testcoverage.html

Open the file testcoverage.html in your browser

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StringUnitFactors = make(map[string]Unit)

StringUnitFactors ...

View Source
var UnitFactors = make(map[Unit]float64)

UnitFactors Unit of measurement factors using a spherical (non-ellipsoid) earth radius in radiant

Functions

func CoordEach

func CoordEach(thing interface{}, callback CoordinateCallback) bool

CoordEach visits all Coordinates in a geojson strtuct

func Deg

func Deg(r float64) float64

Deg takes rad and returns degree

func LengthToRadians

func LengthToRadians(distance float64, unit Unit) (float64, error)

LengthToRadians takes a given

func NewCircle

func NewCircle(center *Coordinate, radius float64, unit Unit) (*geojson.Geometry, error)

NewCircle Takes a point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers;

func NewRandomPoints

func NewRandomPoints(count uint, bbox *Bbox) *geojson.FeatureCollection

NewRandomPoints generates random points as a GeoJSON feature oragnized in a collection. If a bbox is given the points will be generated inside this bbox.

func Rad

func Rad(d float64) float64

Rad takes degree and returns rad

Types

type Bbox

type Bbox struct {
	LonMin float64
	LatMin float64
	LonMax float64
	LatMax float64
}

Bbox is a boundingbox

func NewBboxFromGeoJSON

func NewBboxFromGeoJSON(thing interface{}) *Bbox

NewBboxFromGeoJSON returns the bbox of all features

func (*Bbox) AsPolygon

func (bbox *Bbox) AsPolygon() (*geojson.Geometry, error)

AsPolygon expresses the bbox as polygon

func (*Bbox) AsTuple

func (bbox *Bbox) AsTuple() []float64

AsTuple returns the bbox as (ordered) tuple

type Coordinate

type Coordinate struct {
	Lon   float64
	Lat   float64
	IsRad bool
}

Coordinate is a 1D point

func Destination

func Destination(originDeg *Coordinate, distance float64, unit Unit, bearingDeg float64) (*Coordinate, error)

Destination Takes a point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.

func NewCoordinateFromTuple

func NewCoordinateFromTuple(coords []float64) *Coordinate

NewCoordinateFromTuple takes a tuple [lon, lat] and wraps it in a Coordinate

func NewRandomCoordinate

func NewRandomCoordinate(bbox *Bbox) *Coordinate

NewRandomCoordinate generates a random coordinate. If a bbox is given the coordinate will be inside this bbox.

func (*Coordinate) AsFeature

func (c *Coordinate) AsFeature() *geojson.Feature

AsFeature returns the coordinate as geojson feature

func (*Coordinate) AsTuple

func (c *Coordinate) AsTuple() []float64

AsTuple encodes lon/lat as list in the order 1) lon 2) lat

func (*Coordinate) Rad

func (c *Coordinate) Rad() *Coordinate

Rad Converts a coordinate to rad if encoded as deg

type CoordinateCallback

type CoordinateCallback func(coordinate *Coordinate, coordIndex, featureIndex, multiFeatureIndex, geometryIndex int) bool

CoordinateCallback is used for walking all coordinates

type Unit

type Unit string

Unit represents the available units

const (

	// EarthRadiusInMeters of earth in meters
	EarthRadiusInMeters = 6371008.8

	// UnitMeters SI unit meters
	UnitMeters Unit = "meters"
	// UnitKilometers SI unit kilometers
	UnitKilometers Unit = "kilometers"
	// UnitMiles imperial unit miles
	UnitMiles Unit = "miles"
	// UnitCentimeters SI unit centimeters
	UnitCentimeters Unit = "centimeters"
	// UnitInches imperial unit inches
	UnitInches Unit = "inches"
	// UnitFeet imperial unit feet
	UnitFeet Unit = "feet"
	// UnitYards imperial unit yards
	UnitYards Unit = "yards"
	// UnitMillimeters SI unit millimeters
	UnitMillimeters Unit = "millimeters"
	// UnitNauticalMiles nautical miles
	UnitNauticalMiles Unit = "nauticalmiles"
	// UnitDegrees imperial unit degrees
	UnitDegrees Unit = "degrees"
	// UnitRadians unit rad
	UnitRadians Unit = "radians"
)

Jump to

Keyboard shortcuts

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