Documentation ¶
Overview ¶
Package geom holds geometry objects and functions to operate on them. They can be encoded and decoded by other packages in this repository.
Index ¶
- type Bounds
- func (b *Bounds) Area() float64
- func (b *Bounds) Bounds() *Bounds
- func (b *Bounds) Centroid() Point
- func (b *Bounds) Copy() *Bounds
- func (b *Bounds) Difference(p Polygonal) Polygonal
- func (b *Bounds) Empty() bool
- func (b *Bounds) Extend(b2 *Bounds)
- func (b *Bounds) Intersection(p Polygonal) Polygonal
- func (b *Bounds) Len() int
- func (b *Bounds) Overlaps(b2 *Bounds) bool
- func (b *Bounds) Points() func() Point
- func (b *Bounds) Polygons() []Polygon
- func (b *Bounds) Similar(g Geom, tolerance float64) bool
- func (b *Bounds) Simplify(tolerance float64) Geom
- func (b *Bounds) Transform(t proj.Transformer) (Geom, error)
- func (b *Bounds) Union(p Polygonal) Polygonal
- func (b *Bounds) Within(poly Polygonal) WithinStatus
- func (b *Bounds) XOr(p Polygonal) Polygonal
- type Geom
- type GeometryCollection
- type LineString
- func (l LineString) Bounds() *Bounds
- func (l LineString) Clip(p Polygonal) Linear
- func (l LineString) Distance(p Point) float64
- func (l LineString) Len() int
- func (l LineString) Length() float64
- func (l LineString) Points() func() Point
- func (l LineString) Similar(g Geom, tolerance float64) bool
- func (l LineString) Simplify(tolerance float64) Geom
- func (l LineString) Transform(t proj.Transformer) (Geom, error)
- func (l LineString) Within(p Polygonal) WithinStatus
- type Linear
- type MultiLineString
- func (ml MultiLineString) Bounds() *Bounds
- func (ml MultiLineString) Clip(p Polygonal) Linear
- func (ml MultiLineString) Distance(p Point) float64
- func (ml MultiLineString) Len() int
- func (ml MultiLineString) Length() float64
- func (ml MultiLineString) Points() func() Point
- func (ml MultiLineString) Similar(g Geom, tolerance float64) bool
- func (ml MultiLineString) Simplify(tolerance float64) Geom
- func (ml MultiLineString) Transform(t proj.Transformer) (Geom, error)
- func (ml MultiLineString) Within(p Polygonal) WithinStatus
- type MultiPoint
- type MultiPolygon
- func (mp MultiPolygon) Area() float64
- func (mp MultiPolygon) Bounds() *Bounds
- func (mp MultiPolygon) Centroid() Point
- func (mp MultiPolygon) Difference(p2 Polygonal) Polygonal
- func (mp MultiPolygon) Intersection(p2 Polygonal) Polygonal
- func (mp MultiPolygon) Len() int
- func (mp MultiPolygon) Points() func() Point
- func (mp MultiPolygon) Polygons() []Polygon
- func (mp MultiPolygon) Similar(g Geom, tolerance float64) bool
- func (mp MultiPolygon) Simplify(tolerance float64) Geom
- func (mp MultiPolygon) Transform(t proj.Transformer) (Geom, error)
- func (mp MultiPolygon) Union(p2 Polygonal) Polygonal
- func (mp MultiPolygon) XOr(p2 Polygonal) Polygonal
- type Path
- type Point
- func (p Point) Bounds() *Bounds
- func (p Point) Buffer(radius float64, segments int) Polygon
- func (p Point) Equals(p2 Point) bool
- func (p Point) Len() int
- func (p Point) Points() func() Point
- func (p Point) Similar(g Geom, tolerance float64) bool
- func (p Point) Transform(t proj.Transformer) (Geom, error)
- func (p Point) Within(poly Polygonal) WithinStatus
- type PointLike
- type Polygon
- func (p Polygon) Area() float64
- func (p Polygon) Bounds() *Bounds
- func (p Polygon) Centroid() Point
- func (p Polygon) Difference(p2 Polygonal) Polygonal
- func (p Polygon) Intersection(p2 Polygonal) Polygonal
- func (p Polygon) Len() int
- func (p Polygon) Points() func() Point
- func (p Polygon) Polygons() []Polygon
- func (p Polygon) Similar(g Geom, tolerance float64) bool
- func (p Polygon) Simplify(tolerance float64) Geom
- func (p Polygon) Transform(t proj.Transformer) (Geom, error)
- func (p Polygon) Union(p2 Polygonal) Polygonal
- func (p Polygon) Within(poly Polygonal) WithinStatus
- func (p Polygon) XOr(p2 Polygonal) Polygonal
- type Polygonal
- type Simplifier
- type WithinStatus
- type Withiner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bounds ¶
type Bounds struct {
Min, Max Point
}
Bounds holds the spatial extent of a geometry.
func NewBoundsPoint ¶
NewBoundsPoint creates a bounds object from a point.
func (*Bounds) Difference ¶ added in v0.2.0
Difference subtracts p from b.
func (*Bounds) Intersection ¶ added in v0.2.0
Intersection returns the Intersection of the receiver with p.
func (*Bounds) Polygons ¶ added in v0.2.0
Polygons returns a rectangle polygon to fulfill the Polygonal interface.
func (*Bounds) Simplify ¶ added in v0.2.0
Simplify returns the receiver to fulfill the Polygonal interface.
func (*Bounds) Transform ¶
func (b *Bounds) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of b according to t. If t is not nil, this function returns a Polygon instead of a *Bounds because the transformed polygon may not match the transformed bounding rectangle.
func (*Bounds) Within ¶
func (b *Bounds) Within(poly Polygonal) WithinStatus
Within calculates whether b is within poly.
type Geom ¶
type Geom interface { Bounds() *Bounds Similar(Geom, float64) bool Transform(proj.Transformer) (Geom, error) // Len returns the total number of points in the geometry Len() int // Points returns an iterator that returns the points in the // geometry. Points() func() Point }
Geom is an interface for generic geometry types.
type GeometryCollection ¶
type GeometryCollection []Geom
GeometryCollection is a holder for multiple related geometry objects of arbitrary type.
func (GeometryCollection) Bounds ¶
func (gc GeometryCollection) Bounds() *Bounds
Bounds gives the rectangular extents of the GeometryCollection.
func (GeometryCollection) Len ¶
func (gc GeometryCollection) Len() int
Len returns the number of points in the receiver.
func (GeometryCollection) Points ¶
func (gc GeometryCollection) Points() func() Point
Points returns an iterator for the points in the receiver.
func (GeometryCollection) Similar ¶
func (gc GeometryCollection) Similar(g Geom, tolerance float64) bool
Similar determines whether two geometries collections are similar within tolerance. If gc and g have the same geometries but in a different order, it will return true.
func (GeometryCollection) Transform ¶
func (gc GeometryCollection) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of gc according to t.
type LineString ¶
type LineString Path
LineString is a number of points that make up a path or line.
func (LineString) Bounds ¶
func (l LineString) Bounds() *Bounds
Bounds gives the rectangular extents of the LineString.
func (LineString) Clip ¶
func (l LineString) Clip(p Polygonal) Linear
Clip returns the part of the receiver that falls within the given polygon.
func (LineString) Distance ¶
func (l LineString) Distance(p Point) float64
Distance calculates the shortest distance from p to the LineString.
func (LineString) Len ¶
func (l LineString) Len() int
Len returns the number of points in the receiver.
func (LineString) Points ¶
func (l LineString) Points() func() Point
Points returns an iterator for the points in the receiver.
func (LineString) Similar ¶
func (l LineString) Similar(g Geom, tolerance float64) bool
Similar determines whether two geometries are similar within tolerance. If two lines contain the same points but in different directions it will return false.
func (LineString) Simplify ¶
func (l LineString) Simplify(tolerance float64) Geom
Simplify simplifies l by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting).
It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).
func (LineString) Transform ¶
func (l LineString) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of l according to t.
func (LineString) Within ¶
func (l LineString) Within(p Polygonal) WithinStatus
Within calculates whether l is completely within p or touching its edge.
type Linear ¶
type Linear interface { Geom Length() float64 // Clip returns the part of the line that falls within the given polygon. Clip(Polygonal) Linear Simplify(tolerance float64) Geom // Within determines whether this geometry is within the Polygonal geometry. // Points that lie on the edge of the polygon are considered within. Within(Polygonal) WithinStatus // Distance calculates the shortest distance to the given Point. Distance(Point) float64 }
Linear is an interface for types that are linear in nature.
type MultiLineString ¶
type MultiLineString []LineString
MultiLineString is a holder for multiple related LineStrings.
func (MultiLineString) Bounds ¶
func (ml MultiLineString) Bounds() *Bounds
Bounds gives the rectangular extents of the MultiLineString.
func (MultiLineString) Clip ¶
func (ml MultiLineString) Clip(p Polygonal) Linear
Clip returns the part of the receiver that falls within the given polygon.
func (MultiLineString) Distance ¶
func (ml MultiLineString) Distance(p Point) float64
Distance calculates the shortest distance from p to the MultiLineString.
func (MultiLineString) Len ¶
func (ml MultiLineString) Len() int
Len returns the number of points in the receiver.
func (MultiLineString) Length ¶
func (ml MultiLineString) Length() float64
Length calculates the combined length of the linestrings in ml.
func (MultiLineString) Points ¶
func (ml MultiLineString) Points() func() Point
Points returns an iterator for the points in the receiver.
func (MultiLineString) Similar ¶
func (ml MultiLineString) Similar(g Geom, tolerance float64) bool
Similar determines whether two geometries are similar within tolerance. If ml and g have the similar linestrings but in a different order, it will return true.
func (MultiLineString) Simplify ¶
func (ml MultiLineString) Simplify(tolerance float64) Geom
Simplify simplifies ml by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting).
It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).
func (MultiLineString) Transform ¶
func (ml MultiLineString) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of ml according to t.
func (MultiLineString) Within ¶
func (ml MultiLineString) Within(p Polygonal) WithinStatus
Within calculates whether ml is completely within p or on its edge.
type MultiPoint ¶
type MultiPoint []Point
MultiPoint is a holder for multiple related points.
func (MultiPoint) Bounds ¶
func (mp MultiPoint) Bounds() *Bounds
Bounds gives the rectangular extents of the MultiPoint.
func (MultiPoint) Len ¶
func (mp MultiPoint) Len() int
Len returns the number of points in the receiver.
func (MultiPoint) Points ¶
func (mp MultiPoint) Points() func() Point
Points returns an iterator for the points in the receiver.
func (MultiPoint) Similar ¶
func (mp MultiPoint) Similar(g Geom, tolerance float64) bool
Similar determines whether two geometries are similar within tolerance.
func (MultiPoint) Transform ¶
func (mp MultiPoint) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of mp according to t.
func (MultiPoint) Within ¶
func (mp MultiPoint) Within(poly Polygonal) WithinStatus
Within calculates whether all of the points in mp are within poly or touching its edge.
type MultiPolygon ¶
type MultiPolygon []Polygon
MultiPolygon is a holder for multiple related polygons.
func (MultiPolygon) Area ¶
func (mp MultiPolygon) Area() float64
Area returns the combined area of the polygons in p. The function works correctly for polygons with holes, regardless of the winding order of the holes, but may give the wrong result for self-intersecting polygons, or polygons in mp that overlap each other.
func (MultiPolygon) Bounds ¶
func (mp MultiPolygon) Bounds() *Bounds
Bounds gives the rectangular extents of the MultiPolygon.
func (MultiPolygon) Centroid ¶
func (mp MultiPolygon) Centroid() Point
Centroid calculates the centroid of mp, from wikipedia: http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon. The polygon can have holes, but each ring must be closed (i.e., p[0] == p[n-1], where the ring has n points) and must not be self-intersecting. The algorithm will not check to make sure the holes are actually inside the outer rings.
func (MultiPolygon) Difference ¶
func (mp MultiPolygon) Difference(p2 Polygonal) Polygonal
Difference subtracts p2 from mp.
func (MultiPolygon) Intersection ¶
func (mp MultiPolygon) Intersection(p2 Polygonal) Polygonal
Intersection returns the area(s) shared by mp and p2.
func (MultiPolygon) Len ¶
func (mp MultiPolygon) Len() int
Len returns the number of points in the receiver.
func (MultiPolygon) Points ¶
func (mp MultiPolygon) Points() func() Point
Points returns an iterator for the points in the receiver.
func (MultiPolygon) Polygons ¶
func (mp MultiPolygon) Polygons() []Polygon
Polygons returns the polygons that make up mp.
func (MultiPolygon) Similar ¶
func (mp MultiPolygon) Similar(g Geom, tolerance float64) bool
Similar determines whether two geometries are similar within tolerance. If ml and g have the similar polygons but in a different order, it will return true.
func (MultiPolygon) Simplify ¶
func (mp MultiPolygon) Simplify(tolerance float64) Geom
Simplify simplifies mp by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting). Self-intersecting polygons may cause the algorithm to fall into an infinite loop.
It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).
func (MultiPolygon) Transform ¶
func (mp MultiPolygon) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of mp according to t.
func (MultiPolygon) Union ¶
func (mp MultiPolygon) Union(p2 Polygonal) Polygonal
Union returns the combination of mp and p2.
func (MultiPolygon) XOr ¶
func (mp MultiPolygon) XOr(p2 Polygonal) Polygonal
XOr returns the area(s) occupied by either mp or p2 but not both.
type Point ¶
type Point struct {
X, Y float64
}
Point is a holder for 2D coordinates X and Y.
func (Point) Buffer ¶
Buffer returns a circle with the specified radius centered at the receiver location. The circle is represented as a polygon with the specified number of segments.
func (Point) Points ¶
Points returns an iterator for the points in the receiver (there will only be one point).
func (Point) Transform ¶
func (p Point) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of p according to t.
func (Point) Within ¶
func (p Point) Within(poly Polygonal) WithinStatus
Within calculates whether p is within poly.
type PointLike ¶
type PointLike interface { Geom // Within determines whether this geometry is within the Polygonal geometry. Within(Polygonal) WithinStatus }
PointLike is an interface for types that are pointlike in nature.
type Polygon ¶
type Polygon []Path
A Polygon is a series of closed rings. The inner rings should be nested inside of the outer ring.
func (Polygon) Area ¶
Area returns the area of p. The function works correctly for polygons with holes, regardless of the winding order of the holes, but will give the wrong result for self-intersecting polygons.
func (Polygon) Centroid ¶
Centroid calculates the centroid of p, from wikipedia: http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon. The polygon can have holes, but each ring must be closed (i.e., p[0] == p[n-1], where the ring has n points) and must not be self-intersecting. The algorithm will not check to make sure the holes are actually inside the outer rings. This has not been thoroughly tested.
func (Polygon) Difference ¶
Difference subtracts p2 from p.
func (Polygon) Intersection ¶
Intersection returns the area(s) shared by p and p2.
func (Polygon) Similar ¶
Similar determines whether two geometries are similar within tolerance. If p and g have the same points with the same winding direction, but a different starting point, it will return true. If they have the same rings but in a different order, it will return true. If the rings have the same points but different winding directions, it will return false.
func (Polygon) Simplify ¶
Simplify simplifies p by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting). Self-intersecting polygons may cause the algorithm to fall into an infinite loop.
It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).
func (Polygon) Transform ¶
func (p Polygon) Transform(t proj.Transformer) (Geom, error)
Transform shifts the coordinates of p according to t.
func (Polygon) Within ¶ added in v0.2.9
func (p Polygon) Within(poly Polygonal) WithinStatus
Within calculates whether p is within poly.
type Polygonal ¶
type Polygonal interface { Geom Polygons() []Polygon Intersection(Polygonal) Polygonal Union(Polygonal) Polygonal XOr(Polygonal) Polygonal Difference(Polygonal) Polygonal Area() float64 Simplify(tolerance float64) Geom Centroid() Point }
Polygonal is an interface for types that are polygonal in nature.
type Simplifier ¶
Simplifier is an interface for types that can be simplified.
type WithinStatus ¶
type WithinStatus int
WithinStatus gives the status of a point relative to a polygon: whether it is inside, outside, or on the edge.
const ( Outside WithinStatus = iota Inside OnEdge )
WithinStatus gives the status of a point relative to a polygon: whether it is inside, outside, or on the edge.
type Withiner ¶ added in v0.2.9
type Withiner interface {
Within(Polygonal) WithinStatus
}
Withiner is an interface for types that can be determined to be within a polygon or not.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package carto is a Go language map drawing library
|
Package carto is a Go language map drawing library |
encoding
|
|
osm
Package osm extracts and manipulates OpenStreetMap (OSM) data.
|
Package osm extracts and manipulates OpenStreetMap (OSM) data. |
shp
Package shp decodes and encodes shapefiles to and from geometry objects.
|
Package shp decodes and encodes shapefiles to and from geometry objects. |
index
|
|
rtree
A library for efficiently storing and querying spatial data.
|
A library for efficiently storing and querying spatial data. |
Package op provides implementation of algorithms for geometry operations.
|
Package op provides implementation of algorithms for geometry operations. |
Package route finds the shortest route between two points along a geometrical network (e.g., a road network).
|
Package route finds the shortest route between two points along a geometrical network (e.g., a road network). |