turfgo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 5 Imported by: 0

README

turfgo

Go Report Card GoDoc CircleCi Build codecov

A geospatial library written in golang intended to be used in golang, android and ios. This project is inspired by turfjs

It's a work in progress.

Documentation

Overview

Package turfgo provides geospatial calculation methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BboxToCorners

func BboxToCorners(box *BoundingBox) (*Point, *Point)

BboxToCorners return the corner points SouthWest and NorthEast from bbox

func Bearing

func Bearing(point1, point2 *Point) float64

Bearing takes two points and finds the geographic bearing between them.

func BearingToAngle

func BearingToAngle(bearing float64) float64

BearingToAngle converts any bearing angle from the north line direction (positive clockwise) and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line

func ConvertArea

func ConvertArea(area float64, originalUnit Unit, finalUnit Unit) (float64, error)

ConvertArea converts an area to the requested unit. Allowed units are Kilometers, Meters, Centimeters, Miles, Yards, Feet, Inches

func ConvertDistance

func ConvertDistance(distance float64, originalUnit Unit, finalUnit Unit) float64

ConvertDistance converts a distance to the requested unit.

func DecodeFeatureCollection

func DecodeFeatureCollection(gj []byte) (*geojson.FeatureCollection, error)

func DegreeToRads

func DegreeToRads(degree float64) float64

DegreeToRads convert degrees (assuming a spherical Earth) into radians

func DegreesToRads

func DegreesToRads(first float64, second float64) (float64, float64)

DegreesToRads convert a pair of floats (assuming a spherical Earth) into a pair of radians

func Distance

func Distance(point1 *Point, point2 *Point, unit Unit) float64

Distance calculates the distance between two points in degress, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.

func DistanceToDegrees

func DistanceToDegrees(distance float64, unit Unit) float64

DistanceToDegrees convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees

func DistanceToRads

func DistanceToRads(distance float64, unit Unit) float64

DistanceToRads convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians

func DoesBboxOverlap

func DoesBboxOverlap(b1 *BoundingBox, b2 *BoundingBox) (bool, error)

DoesBboxOverlap takes two bounding box and returns true if there is an overlap. The order of values in array is WSEN(west, south , east, north)

func EncodePolyline

func EncodePolyline(coordinates []*Point, dim int) string

EncodePolyline encodes given coordinates into a polyline for the given dimension

func Inside

func Inside(point *Point, polygon PolygonI) bool

Inside takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.

func IsPointOnLine

func IsPointOnLine(point Point, lineString *LineString, ignoreEnds bool) bool

IsPointOnLine returns true if a point is on a line. Accepts a parameter to ignore the start and end vertices of the linestring.

func LineDiffPercentage

func LineDiffPercentage(firstLine *LineString, secondLine *LineString) float64

LineDiffPercentage take two lines and give the percentage of difference between first and second line with respect to first line. Single coordinate overlaps are ignored. Line should not have duplicate values.

func RadsToDegree

func RadsToDegree(rad float64) float64

RadsToDegree convert a radians (assuming a spherical Earth) into degrees

func RadsToDistance

func RadsToDistance(radians float64, unit Unit) float64

RadsToDistance convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.

Types

type Boundary

type Boundary int

Boundary type

const (
	BoundaryStart Boundary = iota
	BoundaryEnd
	BoundaryBoth
	BoundaryNone
)

Boundary constants

type BoundingBox

type BoundingBox struct {
	West  float64
	South float64
	East  float64
	North float64
}

BoundingBox represent a bbox

func Bbox

func Bbox(shapes ...Geometry) *BoundingBox

Bbox is an alias for Extent

func Expand

func Expand(distance float64, unit Unit, geometries ...Geometry) *BoundingBox

Expand Takes a set of features, calculates a collective bounding box around the features and expand it by the given distance in all directions. It returns a bounding box.

func Extent

func Extent(geometries ...Geometry) *BoundingBox

Extent Takes a set of features, calculates the extent of all input features, and returns a bounding box.

func NewBBox

func NewBBox(w float64, s float64, e float64, n float64) *BoundingBox

NewBBox creates bounding box with given corners

func NewInfiniteBBox

func NewInfiniteBBox() *BoundingBox

NewInfiniteBBox creates a bounding box with corners really far away

type Geometry

type Geometry interface {
	GetPoints() []*Point
}

Geometry is geoJson geometry

type LineString

type LineString struct {
	Points []*Point
}

LineString geojson type

func DecodeLineStringFromFeatureJSON

func DecodeLineStringFromFeatureJSON(gj []byte) (*LineString, error)

DecodeLineStringFromFeatureJSON decode geojson feature type lineString into *LineString

func LineDiff

func LineDiff(firstLine *LineString, secondLine *LineString) []*LineString

LineDiff take two lines and gives an array of lines by subracting second from first. Single coordinate overlaps are ignored. Line should not have duplicate values.

func NewLineString

func NewLineString(points []*Point) *LineString

NewLineString creates a new lineString for given points

func (*LineString) GetPoints

func (p *LineString) GetPoints() []*Point

type MultiLineString

type MultiLineString struct {
	LineStrings []*LineString
}

MultiLineString geojson type

func NewMultiLineString

func NewMultiLineString(lineStrings []*LineString) *MultiLineString

NewMultiLineString creates a new multiLineString for given lineStrings

func (*MultiLineString) GetPoints

func (p *MultiLineString) GetPoints() []*Point

type MultiPoint

type MultiPoint struct {
	Points []*Point
}

MultiPoint geojson type

func NewMultiPoint

func NewMultiPoint(points []*Point) *MultiPoint

NewMultiPoint creates a new multiPoint for given points

func (*MultiPoint) GetPoints

func (p *MultiPoint) GetPoints() []*Point

type MultiPolygon

type MultiPolygon struct {
	Polygons []*Polygon
}

MultiPolygon geojson type

func NewMultiPolygon

func NewMultiPolygon(polygons []*Polygon) *MultiPolygon

NewMultiPolygon creates a new multiPolygon for given polygons

func (*MultiPolygon) GetPoints

func (p *MultiPolygon) GetPoints() []*Point

func (*MultiPolygon) GetPolygons

func (p *MultiPolygon) GetPolygons() []*Polygon

type Point

type Point struct {
	Lat float64
	Lng float64
}

A Point on earth

func Along

func Along(lineString *LineString, distance float64, unit Unit) *Point

Along takes a line and returns a point at a specified distance along the line. Returns the last point if distance is more than the span of the line.

func Center

func Center(shapes ...Geometry) *Point

Center takes an array of points and returns the absolute center point of all points.

func DecodePolyline

func DecodePolyline(line string, dim int) ([]*Point, error)

DecodePolyline decodes given polyline for given dimension and return coordinates

func Destination

func Destination(start *Point, distance float64, bearing float64, unit Unit) *Point

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 to account for global curvature.

func Nearest

func Nearest(reference *Point, points []*Point) *Point

Nearest takes a reference point and a set of points and returns the point from the set closest to the reference.

func NewPoint

func NewPoint(lat float64, lon float64) *Point

NewPoint creates a new point for given lat, lng

func PointOnLine

func PointOnLine(point *Point, lineString *LineString, unit Unit) (*Point, float64, int, error)

PointOnLine takes a Point and a LineString and calculates the closest Point on the LineString.

func TriangularProjection

func TriangularProjection(point *Point, previousPoint *Point, lineString *LineString, unit Unit) (*Point, float64, int, error)

TriangularProjection calculate the projection of given point on the lineString, base angles for projection should be acute. If bearing should also be considered, pass in a previous point, otherwise it should be nil

func Within

func Within(points []*Point, polygons []PolygonI) []*Point

Within takes a set of points and a set of polygons and returns the points that fall within the polygons.

func (*Point) GetPoints

func (p *Point) GetPoints() []*Point

type Polygon

type Polygon struct {
	LineStrings []*LineString
}

Polygon geojson type

func NewPolygon

func NewPolygon(lineStrings []*LineString) *Polygon

NewPolygon creates a new polygon for given lineStrings

func (*Polygon) GetPoints

func (p *Polygon) GetPoints() []*Point

func (*Polygon) GetPolygons

func (p *Polygon) GetPolygons() []*Polygon

type PolygonI

type PolygonI interface {
	GetPolygons() []*Polygon
}

PolygonI is geoJson polygon

type Unit

type Unit int

Unit for distance

const (
	Kilometers Unit = iota
	Miles
	Meters
	Centimeters
	Degrees
	Radians
	NauticalMiles
	Inches
	Yards
	Feet
)

Unit constants

Jump to

Keyboard shortcuts

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