Documentation ¶
Overview ¶
Package geo provides a small set of geometrical types and operations on them. This package aims to be simple and very high quality.
Index ¶
- Constants
- Variables
- type Circle
- func (c Circle) Contains(p Point) bool
- func (c Circle) ContainsEquirectangular(p Point) bool
- func (c Circle) ContainsHaversine(p Point) bool
- func (c Circle) ContainsSLC(p Point) bool
- func (c Circle) Equal(g Geometry) bool
- func (c Circle) MarshalJSON() ([]byte, error)
- func (c *Circle) Scan(src interface{}) error
- func (c Circle) String() string
- func (c *Circle) UnmarshalJSON(data []byte) error
- func (c Circle) Value() (driver.Value, error)
- type Feature
- func (f Feature) Contains(p Point) bool
- func (f Feature) Equal(g Geometry) bool
- func (f Feature) MarshalJSON() ([]byte, error)
- func (f *Feature) Scan(src interface{}) error
- func (f Feature) String() string
- func (f *Feature) UnmarshalJSON(data []byte) error
- func (f Feature) Value() (driver.Value, error)
- type FeatureCollection
- func (coll FeatureCollection) Contains(p Point) bool
- func (coll FeatureCollection) Equal(g Geometry) bool
- func (coll FeatureCollection) MarshalJSON() ([]byte, error)
- func (coll *FeatureCollection) Scan(src interface{}) error
- func (coll FeatureCollection) String() string
- func (coll *FeatureCollection) UnmarshalJSON(data []byte) error
- func (coll FeatureCollection) Value() (driver.Value, error)
- type Geometry
- type GeometryCollection
- func (gc GeometryCollection) Contains(p Point) bool
- func (gc GeometryCollection) Equal(g Geometry) bool
- func (gc GeometryCollection) MarshalJSON() ([]byte, error)
- func (gc *GeometryCollection) Scan(src interface{}) error
- func (gc GeometryCollection) String() string
- func (gc *GeometryCollection) UnmarshalJSON(data []byte) error
- func (gc GeometryCollection) Value() (driver.Value, error)
- type Line
- func (line Line) Contains(p Point) bool
- func (line Line) Equal(g Geometry) bool
- func (line Line) MarshalJSON() ([]byte, error)
- func (line *Line) Scan(src interface{}) error
- func (line Line) String() string
- func (line *Line) UnmarshalJSON(data []byte) error
- func (line Line) Value() (driver.Value, error)
- type MultiLine
- func (ml MultiLine) Contains(point Point) bool
- func (ml MultiLine) Equal(g Geometry) bool
- func (ml MultiLine) MarshalJSON() ([]byte, error)
- func (ml *MultiLine) Scan(src interface{}) error
- func (ml MultiLine) String() string
- func (ml *MultiLine) UnmarshalJSON(data []byte) error
- func (ml MultiLine) Value() (driver.Value, error)
- type MultiPoint
- func (mp MultiPoint) Contains(p Point) bool
- func (mp MultiPoint) Equal(g Geometry) bool
- func (mp MultiPoint) MarshalJSON() ([]byte, error)
- func (mp *MultiPoint) Scan(src interface{}) error
- func (mp MultiPoint) String() string
- func (mp *MultiPoint) UnmarshalJSON(data []byte) error
- func (mp MultiPoint) Value() (driver.Value, error)
- type MultiPolygon
- func (multiPolygon MultiPolygon) Contains(point Point) bool
- func (multiPolygon MultiPolygon) Equal(g Geometry) bool
- func (multiPolygon MultiPolygon) MarshalJSON() ([]byte, error)
- func (multiPolygon *MultiPolygon) Scan(src interface{}) error
- func (multiPolygon MultiPolygon) String() string
- func (multiPolygon *MultiPolygon) UnmarshalJSON(data []byte) error
- func (multiPolygon MultiPolygon) Value() (driver.Value, error)
- type Point
- func (point Point) Contains(other Point) bool
- func (point Point) DistanceFrom(other Point) float64
- func (point Point) Equal(g Geometry) bool
- func (point Point) MarshalJSON() ([]byte, error)
- func (point Point) RayhIntersects(a, b Point) bool
- func (point *Point) Scan(src interface{}) error
- func (point Point) String() string
- func (point *Point) UnmarshalJSON(data []byte) error
- func (point Point) Value() (driver.Value, error)
- type Polygon
- func (polygon Polygon) Contains(point Point) bool
- func (polygon Polygon) Equal(g Geometry) bool
- func (polygon Polygon) MarshalJSON() ([]byte, error)
- func (polygon *Polygon) Scan(src interface{}) error
- func (polygon Polygon) String() string
- func (polygon *Polygon) UnmarshalJSON(data []byte) error
- func (polygon Polygon) Value() (driver.Value, error)
Constants ¶
const ( ContainsMethodHaversine = "haversine" ContainsMethodSphericalCosines = "slc" ContainsMethodEquirectangular = "equirectangular" )
Contains methods.
const ( CircleType = "Circle" FeatureCollectionType = "FeatureCollection" FeatureType = "Feature" GeometryCollectionType = "GeometryCollection" MultiLineType = "MultiLineString" LineType = "LineString" MultiPointType = "MultiPoint" PointType = "Point" PolygonType = "Polygon" MultiPolygonType = "MultiPolygon" )
Geometry types.
Variables ¶
var ( // CircleContainsMethod provides a way to control // which algorithm is used to calculate if a point is inside a circle. CircleContainsMethod = ContainsMethodEquirectangular )
Functions ¶
This section is empty.
Types ¶
type Circle ¶
Circle is a circle in the XY plane.
func (Circle) Contains ¶
Contains determines if the circle contains the point. This assumes radius is specified in feet. This method uses the package variable
CircleContainsMethod
to choose a way to calculate if the point is in the circle. See http://www.movable-type.co.uk/scripts/latlong.html for more info. If CircleContainsMethod is not set to one of
- "haversine"
- "equirectangular"
- "slc"
then this method panics.
func (Circle) ContainsEquirectangular ¶
ContainsEquirectangular uses equirectangular projection to determine if the point is contained in the circle.
func (Circle) ContainsHaversine ¶
ContainsHaversine uses the haversine formula to determine if the point is contained in the circle.
func (Circle) ContainsSLC ¶
ContainsSLC uses the spherical law of cosines to determine if the point is contained in the circle.
func (Circle) MarshalJSON ¶
MarshalJSON marshals a circle to GeoJSON. See https://github.com/geojson/geojson-spec/wiki/Proposal---Circles-and-Ellipses-Geoms
func (*Circle) UnmarshalJSON ¶
UnmarshalJSON unmarshals the circle from GeoJSON.
type Feature ¶
type Feature struct { Geometry Geometry `json:"geometry"` Properties interface{} `json:"properties,omitempty"` }
Feature is a GeoJSON feature.
func (Feature) Equal ¶
Equal compares one feature to another. Note that this method does not compare properties.
func (Feature) MarshalJSON ¶
MarshalJSON marshals the feature to GeoJSON.
func (*Feature) UnmarshalJSON ¶
UnmarshalJSON unmarshals a feature from JSON.
type FeatureCollection ¶
type FeatureCollection []Feature
FeatureCollection represents a feature collection.
func (FeatureCollection) Contains ¶
func (coll FeatureCollection) Contains(p Point) bool
Contains returns true if every feature in the collection contains the p, and false otherwise.
func (FeatureCollection) Equal ¶
func (coll FeatureCollection) Equal(g Geometry) bool
Equal compares one feature collection to another.
func (FeatureCollection) MarshalJSON ¶
func (coll FeatureCollection) MarshalJSON() ([]byte, error)
MarshalJSON marshals the feature collection to geojson.
func (*FeatureCollection) Scan ¶
func (coll *FeatureCollection) Scan(src interface{}) error
Scan scans the feature collection from WKT. This method expects a GEOMETRYCOLLECTION. TODO: implement this.
func (FeatureCollection) String ¶
func (coll FeatureCollection) String() string
String converts the feature collection to a GEOMETRYCOLLECTION.
func (*FeatureCollection) UnmarshalJSON ¶
func (coll *FeatureCollection) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the feature collection from geojson.
type Geometry ¶
type Geometry interface { json.Marshaler json.Unmarshaler sql.Scanner driver.Valuer Equal(g Geometry) bool Contains(p Point) bool String() string }
Geometry defines the interface of every geometry type.
func ScanGeometry ¶
ScanGeometry scans a geometry from well known text.
func UnmarshalJSON ¶
UnmarshalJSON unmarshals any GeoJSON type from a JSON blob.
func WithBBox ¶
WithBBox returns a geometry that contains a "bbox" property. TODO: it might make sense to calculate the bounding box from the geometry's coordinates. TODO: validate the size of the bounding box relative to the dimensionality of the geometry. TODO: verify that all axes of the most southwesterly point are followed by all axes of the more northeasterly point (should also be done for geometries)
type GeometryCollection ¶
type GeometryCollection []Geometry
GeometryCollection is a collection of geometries.
func (GeometryCollection) Contains ¶
func (gc GeometryCollection) Contains(p Point) bool
Contains returns true if the GeometryCollection contains the point and false otherwise.
func (GeometryCollection) Equal ¶
func (gc GeometryCollection) Equal(g Geometry) bool
Equal compares the GeometryCollection to a Geometry.
func (GeometryCollection) MarshalJSON ¶
func (gc GeometryCollection) MarshalJSON() ([]byte, error)
MarshalJSON marshals the GeometryCollection to JSON.
func (*GeometryCollection) Scan ¶
func (gc *GeometryCollection) Scan(src interface{}) error
Scan scans the feature collection from WKT. This method expects a GEOMETRYCOLLECTION. TODO: implement this.
func (GeometryCollection) String ¶
func (gc GeometryCollection) String() string
String converts the feature collection to a GEOMETRYCOLLECTION.
func (*GeometryCollection) UnmarshalJSON ¶
func (gc *GeometryCollection) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the geometry collection from geojson.
type Line ¶
type Line [][3]float64
Line is a line.
func (Line) MarshalJSON ¶
MarshalJSON marshals the line to JSON.
func (*Line) UnmarshalJSON ¶
UnmarshalJSON unmarshals a line from GeoJSON.
type MultiLine ¶
type MultiLine [][][3]float64
MultiLine is an array of Line's.
func (MultiLine) Contains ¶
Contains uses the ray casting algorithm to decide if the point is contained in the MultiLine.
func (MultiLine) MarshalJSON ¶
MarshalJSON returns the GeoJSON representation of the MultiLine.
func (*MultiLine) UnmarshalJSON ¶
UnmarshalJSON unmarshals the ml from GeoJSON.
type MultiPoint ¶
type MultiPoint [][3]float64
MultiPoint is a collection of points.
func (MultiPoint) Contains ¶
func (mp MultiPoint) Contains(p Point) bool
Contains determines if the MultiPoint contains a point.
func (MultiPoint) Equal ¶
func (mp MultiPoint) Equal(g Geometry) bool
Equal compares one MultiPoint to another.
func (MultiPoint) MarshalJSON ¶
func (mp MultiPoint) MarshalJSON() ([]byte, error)
MarshalJSON marshals the MultiPoint to JSON.
func (*MultiPoint) Scan ¶
func (mp *MultiPoint) Scan(src interface{}) error
Scan scans a MultiPoint from Well Known Text.
func (MultiPoint) String ¶
func (mp MultiPoint) String() string
String converts the MultiPoint to a string.
func (*MultiPoint) UnmarshalJSON ¶
func (mp *MultiPoint) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a MultiPoint from GeoJSON.
type MultiPolygon ¶
type MultiPolygon [][][][3]float64
MultiPolygon is a GeoJSON MultiPolygon.
func (MultiPolygon) Contains ¶
func (multiPolygon MultiPolygon) Contains(point Point) bool
Contains uses the ray casting algorithm to decide if the point is contained in the polygon.
func (MultiPolygon) Equal ¶
func (multiPolygon MultiPolygon) Equal(g Geometry) bool
Equal compares one polygon to another.
func (MultiPolygon) MarshalJSON ¶
func (multiPolygon MultiPolygon) MarshalJSON() ([]byte, error)
MarshalJSON returns the GeoJSON representation of the polygon.
func (*MultiPolygon) Scan ¶
func (multiPolygon *MultiPolygon) Scan(src interface{}) error
Scan scans a polygon from Well Known Text.
func (MultiPolygon) String ¶
func (multiPolygon MultiPolygon) String() string
String converts the polygon to a string.
func (*MultiPolygon) UnmarshalJSON ¶
func (multiPolygon *MultiPolygon) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the polygon from GeoJSON.
type Point ¶
type Point [3]float64
Point defines a point.
func (Point) DistanceFrom ¶
DistanceFrom computes the distance from one point to another.
func (Point) MarshalJSON ¶
MarshalJSON returns the GeoJSON representation of the point.
func (Point) RayhIntersects ¶
RayhIntersects returns true if the horizontal ray going from point to positive infinity intersects the line that connects a and b.
func (*Point) UnmarshalJSON ¶
UnmarshalJSON unmarshals a point from GeoJSON.
type Polygon ¶
type Polygon [][][3]float64
Polygon is a GeoJSON Polygon.
func (Polygon) Contains ¶
Contains uses the ray casting algorithm to decide if the point is contained in the polygon.
func (Polygon) MarshalJSON ¶
MarshalJSON returns the GeoJSON representation of the polygon.
func (*Polygon) UnmarshalJSON ¶
UnmarshalJSON unmarshals the polygon from GeoJSON.