Documentation ¶
Overview ¶
Package geo is a geometry/geography library in Go. Its purpose is to allow for basic point, line and path operations in the context of online mapping.
Index ¶
- Variables
- func MercatorScaleFactor(degreesLatitude float64) float64
- type Bound
- func NewBound(west, east, south, north float64) *Bound
- func NewBoundFromGeoHash(hash string) *Bound
- func NewBoundFromGeoHashInt64(hash int64, bits int) *Bound
- func NewBoundFromMapTile(x, y, z uint64) *Bound
- func NewBoundFromPoints(corner, oppositeCorner *Point) *Bound
- func NewGeoBoundAroundPoint(center *Point, distance float64) *Bound
- func (b *Bound) Bottom() float64
- func (b *Bound) Center() *Point
- func (b *Bound) Clone() *Bound
- func (b *Bound) Contains(point *Point) bool
- func (b *Bound) East() float64
- func (b *Bound) Empty() bool
- func (b *Bound) Equals(c *Bound) bool
- func (b *Bound) Extend(point *Point) *Bound
- func (b *Bound) GeoHeight() float64
- func (b *Bound) GeoPad(meters float64) *Bound
- func (b *Bound) GeoWidth(haversine ...bool) float64
- func (b *Bound) Height() float64
- func (b *Bound) Intersects(bound *Bound) bool
- func (b *Bound) Left() float64
- func (b *Bound) MarshalJSON() ([]byte, error)
- func (b *Bound) North() float64
- func (b *Bound) NorthEast() *Point
- func (b *Bound) NorthWest() *Point
- func (b *Bound) Pad(amount float64) *Bound
- func (b *Bound) Right() float64
- func (b *Bound) Set(west, east, south, north float64)
- func (b *Bound) South() float64
- func (b *Bound) SouthEast() *Point
- func (b *Bound) SouthWest() *Point
- func (b *Bound) String() string
- func (b *Bound) ToLine() *Line
- func (b *Bound) ToMysqlIntersectsCondition(column string) string
- func (b *Bound) Top() float64
- func (b *Bound) Union(other *Bound) *Bound
- func (b *Bound) UnmarshalJSON(data []byte) error
- func (b *Bound) West() float64
- func (b *Bound) Width() float64
- type GeoReducer
- type Line
- func (l *Line) A() *Point
- func (l *Line) B() *Point
- func (l *Line) Bound() *Bound
- func (l Line) Clone() *Line
- func (l *Line) Direction() float64
- func (l *Line) Distance() float64
- func (l *Line) DistanceFrom(point *Point) float64
- func (l *Line) Equals(line *Line) bool
- func (l *Line) GeoDistance(haversine ...bool) float64
- func (l *Line) GeoMidpoint() *Point
- func (l *Line) Interpolate(percent float64) *Point
- func (l *Line) Intersection(line *Line) *Point
- func (l *Line) Intersects(line *Line) bool
- func (l *Line) MarshalJSON() ([]byte, error)
- func (l *Line) Measure(point *Point) float64
- func (l *Line) Midpoint() *Point
- func (l *Line) Project(point *Point) float64
- func (l *Line) Reverse() *Line
- func (l *Line) Scan(value interface{}) error
- func (l *Line) Side(p *Point) int
- func (l *Line) SquaredDistance() float64
- func (l *Line) SquaredDistanceFrom(point *Point) float64
- func (l *Line) String() string
- func (l *Line) ToGeoJSON() *geojson.Feature
- func (l *Line) ToWKT() string
- func (l *Line) Transform(projector Projector) *Line
- func (l *Line) UnmarshalJSON(data []byte) error
- type Path
- func Decode(encoded string, factor ...int) *Path
- func NewPath() *Path
- func NewPathFromEncoding(encoded string, factor ...int) *Path
- func NewPathFromFlatXYData(data []float64) *Path
- func NewPathFromWKB(wkb []byte) *Path
- func NewPathFromXYData(data [][2]float64) *Path
- func NewPathFromXYSlice(data [][]float64) *Path
- func NewPathFromYXData(data [][2]float64) *Path
- func NewPathFromYXSlice(data [][]float64) *Path
- func NewPathPreallocate(length, capacity int) *Path
- func (p *Path) Bound() *Bound
- func (p *Path) Clone() *Path
- func (p *Path) DirectionAt(index int) float64
- func (p *Path) Distance() float64
- func (p *Path) DistanceFrom(point *Point) float64
- func (p *Path) Encode(factor ...int) string
- func (p *Path) Equals(path *Path) bool
- func (p *Path) GeoDistance(haversine ...bool) float64
- func (p *Path) GetAt(i int) *Point
- func (p *Path) InsertAt(index int, point *Point) *Path
- func (p *Path) Interpolate(percent float64) *Point
- func (p *Path) Intersection(geometry interface{}) ([]*Point, [][2]int)
- func (p *Path) IntersectionLine(line *Line) ([]*Point, [][2]int)
- func (p *Path) IntersectionPath(path *Path) ([]*Point, [][2]int)
- func (p *Path) Intersects(geometry interface{}) bool
- func (p *Path) IntersectsLine(line *Line) bool
- func (p *Path) IntersectsPath(path *Path) bool
- func (p *Path) Length() int
- func (p *Path) MarshalJSON() ([]byte, error)
- func (p *Path) Measure(point *Point) float64
- func (p *Path) Points() []Point
- func (p *Path) Pop() *Point
- func (p *Path) Project(point *Point) float64
- func (p *Path) Push(point *Point) *Path
- func (p *Path) RemoveAt(index int) *Path
- func (p *Path) Resample(totalPoints int) *Path
- func (p *Path) ResampleWithGeoInterval(meters float64) *Path
- func (p *Path) ResampleWithInterval(dist float64) *Path
- func (p *Path) Scan(value interface{}) error
- func (p *Path) SetAt(index int, point *Point) *Path
- func (p *Path) SetPoints(points []Point) *Path
- func (p *Path) SquaredDistanceFrom(point *Point) float64
- func (p *Path) String() string
- func (p *Path) ToGeoJSON() *geojson.Feature
- func (p *Path) ToWKT() string
- func (p *Path) Transform(projector Projector) *Path
- func (p *Path) UnmarshalJSON(data []byte) error
- func (p *Path) WriteOffFile(w io.Writer, rgb ...[3]int)
- type Point
- func NewPoint(x, y float64) *Point
- func NewPointFromGeoHash(hash string) *Point
- func NewPointFromGeoHashInt64(hash int64, bits int) *Point
- func NewPointFromLatLng(lat, lng float64) *Point
- func NewPointFromQuadkey(key int64, level int) *Point
- func NewPointFromQuadkeyString(key string) *Point
- func NewPointFromWKB(wkb []byte) *Point
- func (p *Point) Add(point *Point) *Point
- func (p *Point) BearingTo(point *Point) float64
- func (p Point) Clone() *Point
- func (p *Point) DistanceFrom(point *Point) float64
- func (p *Point) Dot(v *Point) float64
- func (p *Point) Equals(point *Point) bool
- func (p *Point) GeoDistanceFrom(point *Point, haversine ...bool) float64
- func (p *Point) GeoHash(chars ...int) string
- func (p *Point) GeoHashInt64(bits int) (hash int64)
- func (p *Point) Lat() float64
- func (p *Point) Lng() float64
- func (p *Point) Normalize() *Point
- func (p *Point) Point() *Point
- func (p *Point) Quadkey(level int) int64
- func (p *Point) QuadkeyString(level int) string
- func (p *Point) Scale(factor float64) *Point
- func (p *Point) Scan(value interface{}) error
- func (p *Point) SetLat(lat float64) *Point
- func (p *Point) SetLng(lng float64) *Point
- func (p *Point) SetX(x float64) *Point
- func (p *Point) SetY(y float64) *Point
- func (p *Point) SquaredDistanceFrom(point *Point) float64
- func (p Point) String() string
- func (p *Point) Subtract(point *Point) *Point
- func (p Point) ToArray() [2]float64
- func (p Point) ToGeoJSON() *geojson.Feature
- func (p Point) ToWKT() string
- func (p *Point) Transform(projector Projector) *Point
- func (p *Point) X() float64
- func (p *Point) Y() float64
- type PointSet
- func (ps PointSet) Bound() *Bound
- func (ps PointSet) Centroid() *Point
- func (ps PointSet) Clone() *PointSet
- func (ps PointSet) DistanceFrom(point *Point) (float64, int)
- func (ps PointSet) Equals(pointSet *PointSet) bool
- func (ps PointSet) First() *Point
- func (ps PointSet) GeoCentroid() *Point
- func (ps PointSet) GeoDistanceFrom(point *Point) (float64, int)
- func (ps *PointSet) GetAt(i int) *Point
- func (ps *PointSet) InsertAt(index int, point *Point) *PointSet
- func (ps PointSet) Last() *Point
- func (ps PointSet) Length() int
- func (ps *PointSet) Pop() *Point
- func (ps *PointSet) Push(point *Point) *PointSet
- func (ps *PointSet) RemoveAt(index int) *PointSet
- func (ps *PointSet) Scan(value interface{}) error
- func (ps *PointSet) SetAt(index int, point *Point) *PointSet
- func (ps *PointSet) SetPoints(points []Point) *PointSet
- func (ps PointSet) String() string
- func (ps PointSet) ToGeoJSON() *geojson.Feature
- func (ps PointSet) ToWKT() string
- type Pointer
- type Projection
- type Projector
- type Reducer
- type Surface
- func (s *Surface) Bound() *Bound
- func (s *Surface) GradientAt(point *Point) *Point
- func (s *Surface) MarshalJSON() ([]byte, error)
- func (s *Surface) PointAt(x, y int) *Point
- func (s *Surface) UnmarshalJSON(data []byte) error
- func (s *Surface) ValueAt(point *Point) float64
- func (s *Surface) WriteOffFile(w io.Writer)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedDataType is returned by Scan methods when asked to scan // non []byte data from the database. This should never happen // if the driver is acting appropriately. ErrUnsupportedDataType = errors.New("go.geo: scan value must be []byte") // ErrNotWKB is returned when unmarshalling WKB and the data is not valid. ErrNotWKB = errors.New("go.geo: invalid WKB data") // ErrIncorrectGeometry is returned when unmarshalling WKB data into the wrong type. // For example, unmarshaling linestring data into a point. ErrIncorrectGeometry = errors.New("go.geo: incorrect geometry") )
var EarthRadius = 6378137.0 // meters
EarthRadius is the radius of the earth in meters. It is used in geo distance calculations. To keep things consistent, this values matches that used in WGS84 Web Mercator (EPSG:3857).
var GeoHashPrecision = 12
GeoHashPrecision is the number of characters of a encoded GeoHash.
InfinityPoint is the point at [inf, inf]. Currently returned for the intersection of two collinear overlapping lines.
var Mercator = Projection{ Project: func(p *Point) { p.SetX(mercatorPole / 180.0 * p.Lng()) y := math.Log(math.Tan((90.0+p.Lat())*math.Pi/360.0)) / math.Pi * mercatorPole p.SetY(math.Max(-mercatorPole, math.Min(y, mercatorPole))) }, Inverse: func(p *Point) { p.SetLng(p.X() * 180.0 / mercatorPole) p.SetLat(180.0 / math.Pi * (2*math.Atan(math.Exp((p.Y()/mercatorPole)*math.Pi)) - math.Pi/2.0)) }, }
Mercator projection, performs EPSG:3857, sometimes also described as EPSG:900913.
var ScalarMercator struct { Level uint64 Project func(lng, lat float64, level ...uint64) (x, y uint64) Inverse func(x, y uint64, level ...uint64) (lng, lat float64) }
ScalarMercator converts from lng/lat float64 to x,y uint64. This is the same as Google's world coordinates.
var TransverseMercator = Projection{ Project: func(p *Point) { radLat := deg2rad(p.Lat()) radLng := deg2rad(p.Lng()) sincos := math.Sin(radLng) * math.Cos(radLat) p.SetX(0.5 * math.Log((1+sincos)/(1-sincos)) * EarthRadius) p.SetY(math.Atan(math.Tan(radLat)/math.Cos(radLng)) * EarthRadius) }, Inverse: func(p *Point) { x := p.X() / EarthRadius y := p.Y() / EarthRadius lng := math.Atan(math.Sinh(x) / math.Cos(y)) lat := math.Asin(math.Sin(y) / math.Cosh(x)) p.SetLng(rad2deg(lng)) p.SetLat(rad2deg(lat)) }, }
TransverseMercator implements a default transverse Mercator projector that will only work well +-10 degrees around longitude 0.
var UseHaversineGeoDistanceByDefault = false
UseHaversineGeoDistanceByDefault indicates if the more complicated Haversine formula should be used for geo distances.
Functions ¶
func MercatorScaleFactor ¶
MercatorScaleFactor returns the mercator scaling factor for a given degree latitude.
Types ¶
type Bound ¶
type Bound struct {
// contains filtered or unexported fields
}
A Bound represents an enclosed "box" in the 2D Euclidean or Cartesian plane. It does not know anything about the anti-meridian.
func NewBoundFromGeoHash ¶
NewBoundFromGeoHash creates a new bound for the region defined by the GeoHash.
func NewBoundFromGeoHashInt64 ¶
NewBoundFromGeoHashInt64 creates a new bound from the region defined by the GeoHesh. bits indicates the precision of the hash.
func NewBoundFromMapTile ¶
NewBoundFromMapTile creates a bound given an online map tile index. Panics if x or y is out of range for zoom level.
func NewBoundFromPoints ¶
NewBoundFromPoints creates a new bound given two opposite corners. These corners can be either sw/ne or se/nw.
func NewGeoBoundAroundPoint ¶
NewGeoBoundAroundPoint creates a new bound given a center point, and a distance from the center point in meters
func (*Bound) Contains ¶
Contains determines if the point is within the bound. Points on the boundary are considered within.
func (*Bound) Empty ¶
Empty returns true if it contains zero area or if it's in some malformed negative state where the left point is larger than the right. This can be caused by padding too much negative.
func (*Bound) GeoHeight ¶
GeoHeight returns the approximate height in meters. Only applies if the data is Lng/Lat degrees (EPSG:4326).
func (*Bound) GeoPad ¶
GeoPad expands the bound in all directions by the given amount of meters. Only applies if the data is Lng/Lat degrees.
func (*Bound) GeoWidth ¶
GeoWidth returns the approximate width in meters of the center of the bound. Only applies if the data is Lng/Lat degrees.
func (*Bound) Intersects ¶
Intersects determines if two bounds intersect. Returns true if they are touching.
func (*Bound) MarshalJSON ¶
MarshalJSON enables bounds to be encoded as JSON using the encoding/json package.
func (*Bound) Pad ¶
Pad expands the bound in all directions by the amount given. The amount must be in the units of the bounds. Technically one can pad with negative value, but no error checking is done.
func (*Bound) String ¶
String returns the string respentation of the bound in WKT format. POLYGON(west, south, west, north, east, north, east, south, west, south)
func (*Bound) ToMysqlIntersectsCondition ¶
ToMysqlIntersectsCondition returns a condition defining the intersection of the column and the bound. To be used in a MySQL query.
func (*Bound) UnmarshalJSON ¶
UnmarshalJSON enables bounds to be decoded as JSON using the encoding/json package.
type GeoReducer ¶
A GeoReducer reduces a path in EPSG:4326 (lng/lat) using any simplification algorithm. It should return a copy of the path, also in EPSG:4326, and not modify the original.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line represents the shortest path between A and B.
func NewLineFromWKB ¶
NewLineFromWKB will take raw WKB and set the data for a new line. The WKB data must of type LineString and only contain 2 points. Will return nil if invalid WKB.
func (*Line) Direction ¶
Direction computes the direction the line is pointing from A() to B(). The units are radians from the positive x-axis. Range same as math.Atan2, [-Pi, Pi]
func (*Line) Distance ¶
Distance computes the distance of the line, ie. its length, in Euclidian space.
func (*Line) DistanceFrom ¶
DistanceFrom does NOT use spherical geometry. It finds the distance from the line using standard Euclidean geometry, using the units the points are in.
func (*Line) Equals ¶
Equals returns the line equality and is irrespective of direction, i.e. true if one is the reverse of the other.
func (*Line) GeoDistance ¶
GeoDistance computes the distance of the line, ie. its length, using spherical geometry.
func (*Line) GeoMidpoint ¶
GeoMidpoint returns the half-way point along a great circle path between the two points.
func (*Line) Interpolate ¶
Interpolate performs a simple linear interpolation, from A to B. This function is the opposite of Project.
func (*Line) Intersection ¶
Intersection finds the intersection of the two lines or nil, if the lines are collinear will return NewPoint(math.Inf(1), math.Inf(1)) == InfinityPoint
func (*Line) Intersects ¶
Intersects will return true if the lines are collinear AND intersect. Based on: http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
func (*Line) MarshalJSON ¶
MarshalJSON enables lines to be encoded as JSON using the encoding/json package.
func (*Line) Measure ¶
Measure returns the distance along the line to the point nearest the given point. Treats the line as a line segment such that if the nearest point is an endpoint of the line, the function will return 0 or 1 as appropriate.
func (*Line) Project ¶
Project returns the normalized distance of the point on the line nearest the given point. Returned values may be outside of [0,1]. This function is the opposite of Interpolate.
func (*Line) Scan ¶
Scan implements the sql.Scanner interface allowing line structs to be passed into rows.Scan(...interface{}) The column must be of type LineString and contain 2 points, or an error will be returned. Data must be fetched in WKB format. Will attempt to parse MySQL's SRID+WKB format if the data is of the right size. If the column is empty (not null) an empty line [(0, 0), (0, 0)] will be returned.
func (*Line) Side ¶
Side returns 1 if the point is on the right side, -1 if on the left side, and 0 if collinear.
func (*Line) SquaredDistance ¶
SquaredDistance computes the squared distance of the line, ie. its length, in Euclidian space. This can save a sqrt computation.
func (*Line) SquaredDistanceFrom ¶
SquaredDistanceFrom does NOT use spherical geometry. It finds the squared distance from the line using standard Euclidean geometry, using the units the points are in.
func (*Line) String ¶
String returns a string representation of the line. The format is WKT, e.g. LINESTRING(30 10,10 30)
func (*Line) ToGeoJSON ¶
func (l *Line) ToGeoJSON() *geojson.Feature
ToGeoJSON creates a new geojson feature with a linestring geometry containing the two points.
func (*Line) Transform ¶
Transform applies a given projection or inverse projection to the current line. Modifies the line.
func (*Line) UnmarshalJSON ¶
UnmarshalJSON enables lines to be decoded as JSON using the encoding/json package.
type Path ¶
type Path struct {
PointSet
}
Path represents a set of points to be thought of as a polyline.
func NewPathFromEncoding ¶
NewPathFromEncoding is the inverse of path.Encode. It takes a string encoding of a lat/lng path and returns the actual path it represents. Factor defaults to 1.0e5, the same used by Google for polyline encoding.
func NewPathFromFlatXYData ¶
NewPathFromFlatXYData creates a path from a slice of float64 values representing horizontal, vertical type data. Coordinates in even positions correspond to X values. Coordinates in odd positions correspond to Y values
func NewPathFromWKB ¶
NewPathFromWKB will take raw WKB and set the data for a new path. The WKB data must be of type LineString, Polygon or MultiPoint. Will return nil if invalid WKB.
func NewPathFromXYData ¶
NewPathFromXYData creates a path from a slice of [2]float64 values representing [horizontal, vertical] type data, for example lng/lat values from geojson.
func NewPathFromXYSlice ¶
NewPathFromXYSlice creates a path from a slice of []float64 values. The first two elements are taken to be horizontal and vertical components of each point respectively. The rest of the elements of the slice are ignored. Nil slices are skipped.
func NewPathFromYXData ¶
NewPathFromYXData creates a path from a slice of [2]float64 values representing [vertical, horizontal] type data, for example typical lat/lng data.
func NewPathFromYXSlice ¶
NewPathFromYXSlice creates a path from a slice of []float64 values. The first two elements are taken to be vertical and horizontal components of each point respectively. The rest of the elements of the slice are ignored. Nil slices are skipped.
func NewPathPreallocate ¶
NewPathPreallocate creates a new path with points array of the given size.
func (*Path) DirectionAt ¶
DirectionAt computes the direction of the path at the given index. Uses the line between the two surrounding points to get the direction, or just the first two, or last two if at the start or end, respectively. Assumes the path is in a conformal projection. The units are radians from the positive x-axis. Range same as math.Atan2, [-Pi, Pi] Returns INF for single point paths.
func (*Path) DistanceFrom ¶
DistanceFrom computes an O(n) distance from the path. Loops over every subline to find the minimum distance.
func (*Path) Encode ¶
Encode converts the path to a string using the Google Maps Polyline Encoding method. Factor defaults to 1.0e5, the same used by Google for polyline encoding.
func (*Path) Equals ¶
Equals compares two paths. Returns true if lengths are the same and all points are Equal.
func (*Path) GeoDistance ¶
GeoDistance computes the total distance using spherical geometry.
func (*Path) GetAt ¶
GetAt returns the pointer to the Point in the path. This function is good for modifying values in place. Returns nil if index is out of range.
func (*Path) InsertAt ¶
InsertAt inserts a Point at i along the path. Panics if index is out of range.
func (*Path) Interpolate ¶
Interpolate performs a linear interpolation along the path
func (*Path) Intersection ¶
Intersection calls IntersectionPath or IntersectionLine depending on the type of the provided geometry. TODO: have this receive an Intersectable interface.
func (*Path) IntersectionLine ¶
IntersectionLine returns a slice of points and a slice of tuples [i, 0] where i is the segment in path that intersects with the line at the given point. Slices will be empty if there is no intersection.
func (*Path) IntersectionPath ¶
IntersectionPath returns a slice of points and a slice of tuples [i, j] where i is the segment in the parent path and j is the segment in the given path that intersect to form the given point. Slices will be empty if there is no intersection.
func (*Path) Intersects ¶
Intersects can take a line or a path to determine if there is an intersection. TODO: I would love this to accept an intersecter interface.
func (*Path) IntersectsLine ¶
IntersectsLine takes a Line and checks if it intersects with the path.
func (*Path) IntersectsPath ¶
IntersectsPath takes a Path and checks if it intersects with the path.
func (*Path) MarshalJSON ¶
MarshalJSON enables paths to be encoded as JSON using the encoding/json package.
func (*Path) Measure ¶
Measure computes the distance along this path to the point nearest the given point.
func (*Path) Points ¶
Points returns the raw points storred with the path. Note the output is an array of Points (not pointers to points).
func (*Path) Project ¶
Project computes the measure along this path closest to the given point, normalized to the length of the path.
func (*Path) RemoveAt ¶
RemoveAt removes a Point at i along the path. Panics if index is out of range.
func (*Path) Resample ¶
Resample converts the path into totalPoints-1 evenly spaced segments. Assumes euclidean geometry.
func (*Path) ResampleWithGeoInterval ¶
ResampleWithGeoInterval converts the path into about evenly spaced points of about the given distance. The total distance is computed using spherical (lng/lat) geometry and divided by the given distance. The new points are chosen by linearly interpolating between two given points. This may not make sense in some contexts, especially if the path covers a large range of latitude.
func (*Path) ResampleWithInterval ¶
ResampleWithInterval coverts the path into evenly spaced points of about the given distance. The total distance is computed using euclidean geometry and then divided by the given distance to get the number of segments.
func (*Path) Scan ¶
Scan implements the sql.Scanner interface allowing line structs to be passed into rows.Scan(...interface{}) The column must be of type LineString, Polygon or MultiPoint or an error will be returned. Data must be fetched in WKB format. Will attempt to parse MySQL's SRID+WKB format if obviously no WKB or parsing as WKB fails. If the column is empty (not null) an empty path will be returned.
func (*Path) SetPoints ¶
SetPoints allows you to set the complete pointset yourself. Note that the input is an array of Points (not pointers to points).
func (*Path) SquaredDistanceFrom ¶
SquaredDistanceFrom computes an O(n) minimum squared distance from the path. Loops over every subline to find the minimum distance.
func (*Path) String ¶
String returns a string representation of the path. The format is WKT, e.g. LINESTRING(30 10,10 30,40 40) For empty paths the result will be 'EMPTY'.
func (*Path) ToGeoJSON ¶
func (p *Path) ToGeoJSON() *geojson.Feature
ToGeoJSON creates a new geojson feature with a linestring geometry containing all the points.
func (*Path) ToWKT ¶
ToWKT returns the path in WKT format, eg. LINESTRING(30 10,10 30,40 40) For empty paths the result will be 'EMPTY'.
func (*Path) Transform ¶
Transform applies a given projection or inverse projection to all the points in the path.
func (*Path) UnmarshalJSON ¶
UnmarshalJSON enables paths to be decoded as JSON using the encoding/json package.
func (*Path) WriteOffFile ¶
WriteOffFile writes an Object File Format representation of the points of the path to the writer provided. This is for viewing in MeshLab or something like that. You should close the writer yourself after this function returns. http://segeval.cs.princeton.edu/public/off_format.html
type Point ¶
type Point [2]float64
A Point is a simple X/Y or Lng/Lat 2d point. [X, Y] or [Lng, Lat]
func NewPointFromGeoHash ¶
NewPointFromGeoHash creates a new point at the center of the geohash range.
func NewPointFromGeoHashInt64 ¶
NewPointFromGeoHashInt64 creates a new point at the center of the integer version of a geohash range. bits indicates the precision of the hash.
func NewPointFromLatLng ¶
NewPointFromLatLng creates a new point from latlng
func NewPointFromQuadkey ¶
NewPointFromQuadkey creates a new point from a quadkey. See http://msdn.microsoft.com/en-us/library/bb259689.aspx for more information about this coordinate system.
func NewPointFromQuadkeyString ¶
NewPointFromQuadkeyString creates a new point from a quadkey string.
func NewPointFromWKB ¶
NewPointFromWKB will take raw WKB and set the data for a new point. The WKB data must be of type Point. Will return nil if invalid WKB point.
func (*Point) BearingTo ¶
BearingTo computes the direction one must start traveling on earth to be heading to the given point.
func (*Point) DistanceFrom ¶
DistanceFrom returns the Euclidean distance between the points.
func (*Point) GeoDistanceFrom ¶
GeoDistanceFrom returns the geodesic distance in meters.
func (*Point) GeoHash ¶
GeoHash returns the geohash string of a point representing a lng/lat location. The resulting hash will be `GeoHashPrecision` characters long, default is 12. Optionally one can include their required number of chars precision.
func (*Point) GeoHashInt64 ¶
GeoHashInt64 returns the integer version of the geohash down to the given number of bits. The main usecase for this function is to be able to do integer based ordering of points. In that case the number of bits should be the same for all encodings.
func (*Point) Normalize ¶
Normalize treats the point as a vector and scales it such that its distance from [0,0] is 1.
func (*Point) Quadkey ¶
Quadkey returns the quad key for the given point at the provided level. See http://msdn.microsoft.com/en-us/library/bb259689.aspx for more information about this coordinate system.
func (*Point) QuadkeyString ¶
QuadkeyString returns the quad key for the given point at the provided level in string form See http://msdn.microsoft.com/en-us/library/bb259689.aspx for more information about this coordinate system.
func (*Point) Scan ¶
Scan implements the sql.Scanner interface allowing point structs to be passed into rows.Scan(...interface{}) The column must be of type Point and must be fetched in WKB format. Will attempt to parse MySQL's SRID+WKB format if the data is of the right size. If the column is empty (not null) an empty point (0, 0) will be returned.
func (*Point) SquaredDistanceFrom ¶
SquaredDistanceFrom returns the squared Euclidean distance between the points. This avoids a sqrt computation.
func (Point) String ¶
String returns a string representation of the point. The format is WKT, e.g. POINT(30.5 10.5)
func (Point) ToGeoJSON ¶
func (p Point) ToGeoJSON() *geojson.Feature
ToGeoJSON creates a new geojson feature with a point geometry.
type PointSet ¶
type PointSet []Point
A PointSet represents a set of points in the 2D Eucledian or Cartesian plane.
func NewPointSet ¶
func NewPointSet() *PointSet
NewPointSet simply creates a new point set with points array of the given size.
func NewPointSetFromWKB ¶
NewPointSetFromWKB will take raw WKB and set the data for a new point set. The WKB data must be of type LineString, Polygon or MultiPoint. Will return nil if invalid WKB.
func NewPointSetPreallocate ¶
NewPointSetPreallocate simply creates a new point set with points array of the given size.
func (PointSet) Bound ¶
Bound returns a bound around the point set. Simply uses rectangular coordinates.
func (PointSet) Centroid ¶
Centroid returns the average x and y coordinate of the point set. This can also be used for small clusters of lat/lng points.
func (PointSet) DistanceFrom ¶
DistanceFrom returns the minimum euclidean distance from the point set.
func (PointSet) Equals ¶
Equals compares two point sets. Returns true if lengths are the same and all points are Equal
func (PointSet) First ¶
First returns the first point in the point set. Will return nil if there are no points in the set.
func (PointSet) GeoCentroid ¶
GeoCentroid uses a more advanced algorithm to compute the centroid of points on the earth's surface. The points are first projected into 3D space then averaged. The result is projected back onto the sphere. This method is about 6x slower than the Centroid function, which may be adequate for some datasets. NOTE: Points with longitude outside the standard -180:180 range will be remapped to within the range. The result will always have longitude between -180 and 180 degrees.
func (PointSet) GeoDistanceFrom ¶
GeoDistanceFrom returns the minimum geo distance from the point set, along with the index of the point with minimum index.
func (*PointSet) GetAt ¶
GetAt returns the pointer to the Point in the page. This function is good for modifying values in place. Returns nil if index is out of range.
func (*PointSet) InsertAt ¶
InsertAt inserts a Point at i in the point set. Panics if index is out of range.
func (PointSet) Last ¶
Last returns the last point in the point set. Will return nil if there are no points in the set.
func (*PointSet) RemoveAt ¶
RemoveAt removes a Point at i in the point set. Panics if index is out of range.
func (*PointSet) Scan ¶
Scan implements the sql.Scanner interface allowing line structs to be passed into rows.Scan(...interface{}) The column must be of type LineString, Polygon or MultiPoint or an error will be returned. Data must be fetched in WKB format. Will attempt to parse MySQL's SRID+WKB format if obviously no WKB or parsing as WKB fails. If the column is empty (not null) an empty point set will be returned.
func (PointSet) String ¶
String returns a string representation of the path. The format is WKT, e.g. MULTIPOINT(30 10,10 30,40 40) For empty paths the result will be 'EMPTY'.
type Pointer ¶
type Pointer interface { // Point should return the "center" or other canonical point // for the object. The caller is expected to Clone // the point if changes need to be make. Point() *Point }
A Pointer is the interface for something that has a point.
type Projection ¶
A Projection is a set of projectors to map forward and backwards to the projected space.
func BuildTransverseMercator ¶
func BuildTransverseMercator(centerLng float64) Projection
BuildTransverseMercator builds a transverse Mercator projection that automatically recenters the longitude around the provided centerLng. Works correctly around the anti-meridian. http://en.wikipedia.org/wiki/Transverse_Mercator_projection
type Projector ¶
type Projector func(p *Point)
A Projector is a function that converts the given point to a different space.
type Reducer ¶
A Reducer reduces a path using any simplification algorithm. It should return a copy of the path, not modify the original.
type Surface ¶
type Surface struct {
Width, Height int
// represents the underlying data, as [x][y]
// where x in [0:Width] and y in [0:Height]
Grid [][]float64 // x,y
// contains filtered or unexported fields
}
Surface is the 2d version of path.
func NewSurface ¶
NewSurface build and allocates all the memory to create a surface defined by the bound represented by width*height discrete points. Note that surface.Grid[width-1][height-1] will be on the boundary of the bound.
func (*Surface) GradientAt ¶
GradientAt returns the surface gradient at the given point. Bilinearlly interpolates the grid cell to find the gradient.
func (*Surface) MarshalJSON ¶
MarshalJSON enables surfaces to be encoded as JSON using the encoding/json package.
func (*Surface) PointAt ¶
PointAt returns the point, in the bound, corresponding to this grid coordinate. x in [0, s.Width()-1], y in [0, s.Height()-1]
func (*Surface) UnmarshalJSON ¶
UnmarshalJSON enables surfaces to be decoded as JSON using the encoding/json package.
func (*Surface) ValueAt ¶
ValueAt returns the bi-linearly interpolated value for the given point. Returns 0 if the point is out of surface bounds TODO: cleanup and optimize this code
func (*Surface) WriteOffFile ¶
WriteOffFile writes an Object File Format representation of the surface to the writer provided. This is for viewing in MeshLab or something like that. You should close the writer yourself after this function returns. http://segeval.cs.princeton.edu/public/off_format.html
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package quadtree implements a quadtree using rectangular partitions.
|
Package quadtree implements a quadtree using rectangular partitions. |