geo

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: Apache-2.0 Imports: 6 Imported by: 7

README

geo support in blube

First, all of this geo code is a Go adaptation of the Lucene 5.3.2 sandbox geo support.

Notes

  • All of the APIs will use float64 for lon/lat values.
  • When describing a point in function arguments or return values, we always use the order lon, lat.
  • High level APIs will use TopLeft and BottomRight to describe bounding boxes. This may not map cleanly to min/max lon/lat when crossing the dateline. The lower level APIs will use min/max lon/lat and require the higher-level code to split boxes accordingly.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Centimeter = DistanceUnit{0.01, []string{"cm", "centimeters"}}
View Source
var Feet = DistanceUnit{0.3048, []string{"ft", "feet"}}
View Source
var GeoBits uint = 32

GeoBits is the number of bits used for a single geo point Currently this is 32bits for lon and 32bits for lat

View Source
var Inch = DistanceUnit{0.0254, []string{"in", "inches"}}
View Source
var Kilometer = DistanceUnit{1000, []string{"km", "kilometers"}}
View Source
var Meter = DistanceUnit{1, []string{"m", "meters"}}
View Source
var Mile = DistanceUnit{1609.344, []string{"mi", "mile"}}
View Source
var Millimeter = DistanceUnit{0.001, []string{"mm", "millimeters"}}
View Source
var NauticalMile = DistanceUnit{1852.0, []string{"nm", "nauticalmiles"}}
View Source
var Yard = DistanceUnit{0.9144, []string{"yd", "yards"}}

Functions

func BoundingBoxContains

func BoundingBoxContains(lon, lat, minLon, minLat, maxLon, maxLat float64) bool

BoundingBoxContains checks whether the lon/lat point is within the box

func BoundingRectangleForPolygon

func BoundingRectangleForPolygon(polygon []Point) (
	topLeftLon, topLeftLat, bottomRightLon, bottomRightLat float64, err error)

func Convert

func Convert(value float64, source, dest DistanceUnit) float64

func DecodeGeoHash

func DecodeGeoHash(geoHash string) (lat, lon float64)

DecodeGeoHash decodes the string geohash faster with higher precision. This api is in experimental phase.

func DegreesToRadians

func DegreesToRadians(d float64) float64

DegreesToRadians converts an angle in degrees to radians

func EncodeGeoHash

func EncodeGeoHash(lat, lon float64) string

func ExtractGeoPoint

func ExtractGeoPoint(thing interface{}) (lon, lat float64, success bool)

ExtractGeoPoint takes an arbitrary interface{} and tries it's best to interpret it is as geo point. Supported formats: Container: slice length 2 (GeoJSON)

first element lon, second element lat

string (coordinates separated by comma, or a geohash)

first element lat, second element lon

map[string]interface{}

exact keys lat and lon or lng

struct

w/exported fields case-insensitive match on lat and lon or lng

struct

satisfying Later and Loner or Lnger interfaces

in all cases values must be some sort of numeric-like thing: int/uint/float

func Haversin

func Haversin(lon1, lat1, lon2, lat2 float64) float64

Haversin computes the distance between two points. This implemenation uses the sloppy math implemenations which trade off accuracy for performance. The distance returned is in kilometers.

func MortonHash

func MortonHash(lon, lat float64) uint64

MortonHash computes the morton hash value for the provided geo point This point is ordered as lon, lat.

func MortonUnhashLat

func MortonUnhashLat(hash uint64) float64

MortonUnhashLat extracts the latitude value from the provided morton hash.

func MortonUnhashLon

func MortonUnhashLon(hash uint64) float64

MortonUnhashLon extracts the longitude value from the provided morton hash.

func ParseDistance

func ParseDistance(d string) (float64, error)

ParseDistance attempts to parse a distance string and return distance in meters. Example formats supported: "5in" "5inches" "7yd" "7yards" "9ft" "9feet" "11km" "11kilometers" "3nm" "3nauticalmiles" "13mm" "13millimeters" "15cm" "15centimeters" "17mi" "17miles" "19m" "19meters" If the unit cannot be determined, the entire string is parsed and the unit of meters is assumed. If the number portion cannot be parsed, 0 and the parse error are returned.

func ParseDistanceUnit

func ParseDistanceUnit(u string) (float64, error)

ParseDistanceUnit attempts to parse a distance unit and return the multiplier for converting this to meters. If the unit cannot be parsed then 0 and the error message is returned.

func RadiansToDegrees

func RadiansToDegrees(r float64) float64

RadiansToDegrees converts an angle in radians to degress

func RectFromPointDistance

func RectFromPointDistance(lon, lat, dist float64) (topLeftLon, topLeftLat, bottomRightLon, bottomRightLat float64, err error)

func RectIntersects

func RectIntersects(aMinX, aMinY, aMaxX, aMaxY, bMinX, bMinY, bMaxX, bMaxY float64) bool

RectIntersects checks whether rectangles a and b intersect

func RectWithin

func RectWithin(aMinX, aMinY, aMaxX, aMaxY, bMinX, bMinY, bMaxX, bMaxY float64) bool

RectWithin checks whether box a is within box b

Types

type DistanceUnit

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

type Point

type Point struct {
	Lon float64 `json:"lon"`
	Lat float64 `json:"lat"`
}

Point represents a geo point.

Jump to

Keyboard shortcuts

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