geomap

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

geomap-utils

Utils for working with maps, polylines and other geospatial data in Go

Please note that this library is a humble and improved port of https://github.com/googlemaps/android-maps-utils

Installation

go get github.com/sidwebworks/geomap-utils

Documentation

Index

Constants

View Source
const DEFAULT_EARTH_RADIUS = float64(6378137)

Variables

This section is empty.

Functions

This section is empty.

Types

type LatLng

type LatLng struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type MathUtil

type MathUtil struct {
	EarthRadius float64
}

MathUtil contains utility functions used by both PolyUtil and SphericalUtil

func NewMathUtil

func NewMathUtil(earthRadius float64) *MathUtil

NewMathUtil creates a new MathUtil instance with the specified earth radius

func (*MathUtil) ArcHav

func (mu *MathUtil) ArcHav(x float64) float64

ArcHav computes inverse haversine

func (*MathUtil) Clamp

func (mu *MathUtil) Clamp(x, low, high float64) float64

Clamp restricts x to the range [low, high]

func (*MathUtil) FloatEqual

func (mu *MathUtil) FloatEqual(a, b float64) bool

func (*MathUtil) Hav

func (mu *MathUtil) Hav(x float64) float64

Hav returns haversine(angle-in-radians)

func (*MathUtil) HavDistance

func (mu *MathUtil) HavDistance(lat1, lat2, dLng float64) float64

HavDistance returns hav() of distance from (lat1, lng1) to (lat2, lng2) on the unit sphere

func (*MathUtil) HavFromSin

func (mu *MathUtil) HavFromSin(x float64) float64

HavFromSin returns hav(asin(x))

func (*MathUtil) InverseMercator

func (mu *MathUtil) InverseMercator(y float64) float64

InverseMercator returns latitude from mercator Y

func (*MathUtil) Mercator

func (mu *MathUtil) Mercator(lat float64) float64

Mercator returns mercator Y corresponding to latitude

func (*MathUtil) Mod

func (mu *MathUtil) Mod(x, m float64) float64

Mod returns the non-negative remainder of x / m

func (*MathUtil) SinFromHav

func (mu *MathUtil) SinFromHav(h float64) float64

SinFromHav given h==hav(x), returns sin(abs(x))

func (*MathUtil) SinSumFromHav

func (mu *MathUtil) SinSumFromHav(x, y float64) float64

SinSumFromHav returns sin(arcHav(x) + arcHav(y))

func (*MathUtil) Wrap

func (mu *MathUtil) Wrap(n, min, max float64) float64

Wrap wraps the given value into the inclusive-exclusive interval between min and max

type PolyUtil

type PolyUtil struct {
	EarthRadius float64
	Math        *MathUtil
	Spherical   *SphericalUtil
}

func NewPolyUtil

func NewPolyUtil(earthRadius float64) *PolyUtil

NewPolyUtil creates a new PolyUtil instance with the specified earth radius

func (*PolyUtil) ContainsLocation

func (pu *PolyUtil) ContainsLocation(latitude, longitude float64, polygon []LatLng, geodesic bool) bool

ContainsLocation computes whether the given point lies inside the specified polygon

func (*PolyUtil) Decode

func (pu *PolyUtil) Decode(encodedPath string) []LatLng

Decode decodes an encoded path string into a sequence of LatLngs

func (*PolyUtil) DistanceBetweenPoints

func (pu *PolyUtil) DistanceBetweenPoints(from, to LatLng) float64

func (*PolyUtil) DistanceToLine

func (pu *PolyUtil) DistanceToLine(p, start, end LatLng) float64

DistanceToLine computes the distance on the sphere between the point p and the line segment start to end

func (*PolyUtil) Encode

func (pu *PolyUtil) Encode(path []LatLng) string

Encode encodes a sequence of LatLngs into an encoded path string

func (*PolyUtil) Intersects

func (pu *PolyUtil) Intersects(lat1, lat2, lng2, lat3, lng3 float64, geodesic bool) bool

Intersects computes whether the vertical segment (lat3, lng3) to South Pole intersects the segment (lat1, lng1) to (lat2, lng2)

func (*PolyUtil) IsLocationOnEdge

func (pu *PolyUtil) IsLocationOnEdge(point LatLng, polygon []LatLng, geodesic bool, tolerance float64) bool

IsLocationOnEdge computes whether the given point lies on or near the edge of a polygon, within a specified tolerance in meters

func (*PolyUtil) IsLocationOnEdgeWithDefaultTolerance

func (pu *PolyUtil) IsLocationOnEdgeWithDefaultTolerance(point LatLng, polygon []LatLng, geodesic bool) bool

IsLocationOnEdgeWithDefaultTolerance is the same as IsLocationOnEdge with a default tolerance of 0.1 meters

func (*PolyUtil) IsLocationOnPath

func (pu *PolyUtil) IsLocationOnPath(point LatLng, polyline []LatLng, geodesic bool, tolerance float64) bool

IsLocationOnPath computes whether the given point lies on or near a polyline, within a specified tolerance in meters

func (*PolyUtil) IsLocationOnPathWithDefaultTolerance

func (pu *PolyUtil) IsLocationOnPathWithDefaultTolerance(point LatLng, polyline []LatLng, geodesic bool) bool

IsLocationOnPathWithDefaultTolerance is the same as IsLocationOnPath with a default tolerance of 0.1 meters

func (*PolyUtil) MercatorLatRhumb

func (pu *PolyUtil) MercatorLatRhumb(lat1, lat2, lng2, lng3 float64) float64

MercatorLatRhumb returns mercator(latitude-at-lng3) on the Rhumb line (lat1, lng1) to (lat2, lng2)

func (*PolyUtil) Simplify

func (pu *PolyUtil) Simplify(poly []LatLng, tolerance float64) []LatLng

Simplify simplifies the given poly (polyline or polygon) using the Douglas-Peucker decimation algorithm

func (*PolyUtil) TanLatGC

func (pu *PolyUtil) TanLatGC(lat1, lat2, lng2, lng3 float64) float64

TanLatGC returns tan(latitude-at-lng3) on the great circle (lat1, lng1) to (lat2, lng2)

type SphericalUtil

type SphericalUtil struct {
	EarthRadius float64
}

SphericalUtil contains utility functions for spherical calculations

func NewSphericalUtil

func NewSphericalUtil(earthRadius float64) *SphericalUtil

NewSphericalUtil creates a new SphericalUtil instance with the specified earth radius

func (*SphericalUtil) ComputeArea

func (su *SphericalUtil) ComputeArea(path []LatLng) float64

ComputeArea returns the area of a closed path on Earth

func (*SphericalUtil) ComputeDistanceBetween

func (su *SphericalUtil) ComputeDistanceBetween(from, to LatLng) float64

ComputeDistanceBetween returns the distance between two LatLngs, in meters

func (*SphericalUtil) ComputeHeading

func (su *SphericalUtil) ComputeHeading(from, to LatLng) float64

ComputeHeading returns the heading from one LatLng to another LatLng

func (*SphericalUtil) ComputeLength

func (su *SphericalUtil) ComputeLength(path []LatLng) float64

ComputeLength returns the length of the given path, in meters, on Earth

func (*SphericalUtil) ComputeOffset

func (su *SphericalUtil) ComputeOffset(from LatLng, distance, heading float64) LatLng

ComputeOffset returns the LatLng resulting from moving a distance from an origin in the specified heading

func (*SphericalUtil) ComputeOffsetOrigin

func (su *SphericalUtil) ComputeOffsetOrigin(to LatLng, distance, heading float64) *LatLng

ComputeOffsetOrigin returns the location of origin when provided with a LatLng destination, meters travelled and original heading

func (*SphericalUtil) ComputeSignedArea

func (su *SphericalUtil) ComputeSignedArea(path []LatLng) float64

ComputeSignedArea returns the signed area of a closed path on Earth

func (*SphericalUtil) Interpolate

func (su *SphericalUtil) Interpolate(from, to LatLng, fraction float64) LatLng

Interpolate returns the LatLng which lies the given fraction of the way between the origin LatLng and the destination LatLng

Jump to

Keyboard shortcuts

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