Documentation
¶
Index ¶
- Constants
- Variables
- func CartesianDistance2d(a, b Point) float64
- func CartesianDistance3d(a, b Point) float64
- func DistanceEarth2d(p1, p2 Point) float64
- func DistanceHaversine2d(p1, p2 Point) float64
- func Length(g Geometry, dfp ...DistanceFunc) float64
- func Transform(g Geometry, tf TransformFunc)
- type Bound
- func (b Bound) Bottom() float64
- func (b Bound) Bound() Bound
- func (b Bound) Center() Point
- func (b Bound) Clone() Geometry
- func (b Bound) Contains(point Point) bool
- func (b Bound) Dimension() Dimension
- func (b Bound) Equal(g Geometry) bool
- func (b Bound) Extend(point Point) Bound
- func (b Bound) GeoJSONType() string
- func (b Bound) Intersects(bound Bound) bool
- func (b Bound) IsEmpty() bool
- func (b Bound) IsZero() bool
- func (b Bound) Left() float64
- func (b Bound) LeftTop() Point
- func (b Bound) Pad(d float64) Bound
- func (b Bound) Right() float64
- func (b Bound) RightBottom() Point
- func (b Bound) ToPolygon() Polygon
- func (b Bound) ToRing() Ring
- func (b Bound) Top() float64
- func (b Bound) Union(other Bound) Bound
- type Collection
- type Dimension
- type DistanceFunc
- type Geometry
- type LineString
- type MultiLineString
- type MultiPoint
- type MultiPolygon
- type Orientation
- type Point
- func (p Point) Bound() Bound
- func (p Point) Clone() Geometry
- func (p Point) Dimension() Dimension
- func (p Point) Equal(g Geometry) bool
- func (p Point) GeoJSONType() string
- func (p Point) Lat() float64
- func (p Point) Lon() float64
- func (p Point) M() float64
- func (p Point) Point() Point
- func (p Point) Polar() Polar
- func (p Point) X() float64
- func (p Point) Y() float64
- func (p Point) Z() float64
- type Polar
- type Polygon
- type Ring
- type Segment
- type TransformFunc
Constants ¶
const 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 value matches WGS84 Web Mercator (EPSG:3857).
Variables ¶
var AllGeometries = []Geometry{ nil, Point{}, MultiPoint{}, LineString{}, Segment{}, MultiLineString{}, Ring{}, Polygon{}, MultiPolygon{}, Bound{}, Collection{}, MultiPoint(nil), LineString(nil), MultiLineString(nil), Ring(nil), Polygon(nil), MultiPolygon(nil), Collection(nil), Collection{Collection{Point{}}}, }
AllGeometries lists all possible types and values that a geometry interface can be. It should be used only for testing to verify functions that accept a Geometry will work in all cases.
var DefaultRoundingFactor = 1e6 // 6 decimal places
DefaultRoundingFactor is the default rounding factor used by the Round func.
var EpsilonTolerance = 1e-6
Epsilon tolerance.
var Mercator = struct { ToWGS84 TransformFunc }{ ToWGS84: func(p Point) { lon := 180.0 * p.X() / earthRadiusPi lat := 180.0 / math.Pi * (2*math.Atan(math.Exp(p.Y()/EarthRadius)) - math.Pi/2.0) if p.Dimension() > 0 { p[0] = lon } if p.Dimension() > 0 { p[1] = lat } }, }
Mercator EPSG:3857 performs the Spherical Pseudo-Mercator projection used by most web maps.
var WGS84 = struct { // ToMercator projections from WGS to Mercator, used by most web maps ToMercator TransformFunc }{ ToMercator: func(p Point) { x := earthRadiusPi / 180.0 * p.Lon() y := math.Log(math.Tan((90.0+p.Lat())*math.Pi/360.0)) * EarthRadius y = math.Max(-earthRadiusPi, math.Min(y, earthRadiusPi)) if p.Dimension() > 0 { p[0] = x } if p.Dimension() > 0 { p[1] = y } }, }
WGS84 EPSG:4326 is what common uses lon/lat projection.
Functions ¶
func CartesianDistance2d ¶
Distance returns the distance between xy 2d points on the plan.
func CartesianDistance3d ¶
Distance returns the distance between xyz 32d points on the plan.
func DistanceEarth2d ¶
Distance returns the distance between two lon/lat wgs84 points on the earth.
func DistanceHaversine2d ¶
DistanceHaversine computes the distance between two lon/lat wgs84 points using the haversine formula.
func Length ¶
func Length(g Geometry, dfp ...DistanceFunc) float64
Length returns the length of the geometry.
func Transform ¶
func Transform(g Geometry, tf TransformFunc)
Transform transforms the geometry inplace.
Types ¶
type Bound ¶
type Bound struct {
Min, Max [2]float64
}
A Bound represents a closed box or rectangle. To create a bound with two points you can do something like:
orb.MultiPoint{p1, p2}.Bound()
func (Bound) Contains ¶
Contains determines if the point is within the bound. Points on the boundary are considered within.
func (Bound) GeoJSONType ¶
GeoJSONType returns the GeoJSON type for the object.
func (Bound) Intersects ¶
Intersects determines if two bounds intersect. Returns true if they are touching.
func (Bound) IsEmpty ¶
IsEmpty 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) RightBottom ¶
RightBottom return the lower right point of the bound.
type Collection ¶
type Collection []Geometry
A Collection is a collection of geometries that is also a Geometry.
func (Collection) Bound ¶
func (c Collection) Bound() Bound
Bound returns the bounding box of all the Geometries combined.
func (Collection) Clone ¶
func (c Collection) Clone() Geometry
Clone returns a deep copy of the collection.
func (Collection) Dimension ¶
func (c Collection) Dimension() Dimension
Dimension returns the max of the dimension of the collection.
func (Collection) Equal ¶
func (c Collection) Equal(g Geometry) bool
Equal compares two collections. Returns true if lengths are the same and all the sub geometries are the same and in the same order.
func (Collection) GeoJSONType ¶
func (c Collection) GeoJSONType() string
GeoJSONType returns the geometry collection type.
type Dimension ¶
type Dimension int8
Dim defines space dimension (0 = NOME, 1 = X, 2 = XY, 3 = XYZ, 4 = XYZM)
type DistanceFunc ¶
A DistanceFunc is a function that computes the distance between two points.
type Geometry ¶
type Geometry interface { GeoJSONType() string Dimension() Dimension // e.g. 0 = NONE, 1 = X, 2 = XY, 3 = XYZ, 4 = XYZM Bound() Bound Clone() Geometry Equal(Geometry) bool // contains filtered or unexported methods }
Geometry is an interface that represents the shared attributes of a geometry.
type LineString ¶
type LineString []Point
LineString represents a set of points to be thought of as a polyline.
func (LineString) Bound ¶
func (ls LineString) Bound() Bound
Bound returns a rect around the line string. Uses rectangular coordinates.
func (LineString) Dimension ¶
func (ls LineString) Dimension() Dimension
Dimension returns the max of the dimension.
func (LineString) Equal ¶
func (ls LineString) Equal(g Geometry) bool
Equal compares two line strings. Returns true if lengths are the same and all points are Equal.
func (LineString) GeoJSONType ¶
func (ls LineString) GeoJSONType() string
GeoJSONType returns the GeoJSON type for the object.
func (LineString) Reverse ¶
func (ls LineString) Reverse()
Reverse will reverse the line string. This is done inplace, ie. it modifies the original data.
type MultiLineString ¶
type MultiLineString []LineString
MultiLineString is a set of polylines.
func (MultiLineString) Bound ¶
func (mls MultiLineString) Bound() Bound
Bound returns a bound around all the line strings.
func (MultiLineString) Clone ¶
func (mls MultiLineString) Clone() Geometry
Clone performs deep clone.
func (MultiLineString) Dimension ¶
func (mls MultiLineString) Dimension() Dimension
Dimension returns the max of the dimension.
func (MultiLineString) Equal ¶
func (mls MultiLineString) Equal(g Geometry) bool
Equal compares two multi line strings. Returns true if lengths are the same and all points are Equal.
func (MultiLineString) GeoJSONType ¶
func (mls MultiLineString) GeoJSONType() string
GeoJSONType returns the GeoJSON type for the object.
type MultiPoint ¶
type MultiPoint []Point
A MultiPoint represents a set of points in the 2D Eucledian or Cartesian plane.
func (MultiPoint) Bound ¶
func (mp MultiPoint) Bound() Bound
Bound returns a bound around the points. Uses rectangular coordinates.
func (MultiPoint) Dimension ¶
func (mp MultiPoint) Dimension() Dimension
Dimension returns the max of the dimension.
func (MultiPoint) Equal ¶
func (mp MultiPoint) Equal(g Geometry) bool
Equal compares two MultiPoint objects. Returns true if lengths are the same and all points are Equal, and in the same order.
func (MultiPoint) GeoJSONType ¶
func (mp MultiPoint) GeoJSONType() string
GeoJSONType returns the GeoJSON type for the object.
type MultiPolygon ¶
type MultiPolygon []Polygon
MultiPolygon is a set of polygons.
func (MultiPolygon) Bound ¶
func (mp MultiPolygon) Bound() Bound
Bound returns a bound around the multi-polygon.
func (MultiPolygon) Dimension ¶
func (mp MultiPolygon) Dimension() Dimension
Dimension returns the max of the dimension.
func (MultiPolygon) Equal ¶
func (mp MultiPolygon) Equal(g Geometry) bool
Equal compares two multi-polygons.
func (MultiPolygon) GeoJSONType ¶
func (mp MultiPolygon) GeoJSONType() string
GeoJSONType returns the GeoJSON type for the object.
type Orientation ¶
type Orientation int8
Orientation defines the order of the points in a polygon or closed ring.
const ( // CCW stands for Counter Clock Wise CCW Orientation = 1 // CW stands for Clock Wise CW Orientation = -1 )
Constants to define orientation. They follow the right hand rule for orientation.
type Point ¶
type Point []float64
A Point represents a set of coordinate.
func (Point) GeoJSONType ¶
GeoJSONType returns the GeoJSON type for the object.
type Polar ¶
type Polar struct {
R, A float64
}
A Polar represents a point 2d defined by ray and angle.
func (Polar) GeoJSONType ¶
GeoJSONType returns the GeoJSON type for the object.
type Polygon ¶
type Polygon []Ring
Polygon is a closed area. The first LineString is the outer ring. The others are the holes. Each LineString is expected to be closed ie. the first point matches the last.
func (Polygon) Equal ¶
Equal compares two polygons. Returns true if lengths are the same and all points are Equal.
func (Polygon) GeoJSONType ¶
GeoJSONType returns the GeoJSON type for the object.
type Ring ¶
type Ring LineString
Ring represents a set of ring on the earth.
func (Ring) Closed ¶
Closed will return true if the ring is a real ring. ie. 4+ points and the first and last points match. NOTE: this will not check for self-intersection.
func (Ring) Equal ¶
Equal compares two rings. Returns true if lengths are the same and all points are Equal.
func (Ring) GeoJSONType ¶
GeoJSONType returns the GeoJSON type for the object.
func (Ring) Orientation ¶
func (r Ring) Orientation() Orientation
Orientation returns 1 if the the ring is in couter-clockwise order, return -1 if the ring is the clockwise order and 0 if the ring is degenerate and had no area.
type Segment ¶
type Segment [2]Point
A Segment represents a simple line with only 2 points .
func (Segment) Equal ¶
Equal compares two line strings. Returns true if lengths are the same and all points are Equal.
func (Segment) GeoJSONType ¶
GeoJSONType returns the GeoJSON type for the object.
func (Segment) Intersects ¶
Intersects computes 2d intersection
type TransformFunc ¶
type TransformFunc func(Point)
A TransformFunc is a function that transform the coordinates of the point inplace.