# README
go-geom
Package geom
implements efficient geometry types for geospatial applications.
Key features
- OpenGeo Consortium-style geometries.
- Support for 2D and 3D geometries, measures (time and/or distance), and unlimited extra dimensions.
- Encoding and decoding of common geometry formats (GeoJSON, KML, WKB, and
others) including
sql.Scanner
anddriver.Value
interface implementations for easy database integration. - 2D and 3D topology functions.
- Efficient, cache-friendly internal representation.
- Optional protection against malicious or malformed inputs.
Examples
Detailed features
Geometry types
Encoding and decoding
Geometry functions
Protection against malicious or malformed inputs
The WKB and EWKB formats encode geometry sizes, and memory is allocated for
those geometries. If the input is malicious or malformed, the memory allocation
can be very large, leading to a memory starvation denial-of-service attack
against the server. For example, a client might send a MultiPoint
with header
indicating that it contains 2^32-1 points. This will result in the server
reading that geometry to allocate 2 × sizeof(float64)
× (2^32-1) = 64GB of
memory to store those points. By default, malicious or malformed input
protection is disabled, but can be enabled by setting positive values for
wkbcommon.MaxGeometryElements
.
Related libraries
- github.com/twpayne/go-gpx GPX encoding and decoding
- github.com/twpayne/go-kml KML encoding
- github.com/twpayne/go-polyline Google Maps Polyline encoding and decoding
- github.com/twpayne/go-vali IGC validation
License
BSD-2-Clause
# Functions
Must panics if err is not nil, otherwise it returns g.
NewBounds creates a new Bounds.
NewGeometryCollection returns a new empty GeometryCollection.
NewLinearRing returns a new LinearRing with no coordinates.
NewLinearRingFlat returns a new LinearRing with the given flat coordinates.
NewLineString returns a new LineString with layout l and no control points.
NewLineStringFlat returns a new LineString with layout l and control points flatCoords.
NewMultiLineString returns a new MultiLineString with no LineStrings.
NewMultiLineStringFlat returns a new MultiLineString with the given flat coordinates.
NewMultiPoint returns a new, empty, MultiPoint.
NewMultiPointFlat returns a new MultiPoint with the given flat coordinates.
NewMultiPointFlatOptionWithEnds allows passing ends to NewMultiPointFlat, which allows the representation of empty points.
NewMultiPolygon returns a new MultiPolygon with no Polygons.
NewMultiPolygonFlat returns a new MultiPolygon with the given flat coordinates.
NewPoint allocates a new Point with layout l and all values zero.
NewPointEmpty allocates a new Point with no coordinates.
NewPointFlat allocates a new Point with layout l and flat coordinates flatCoords.
NewPointFlatMaybeEmpty returns a new point, checking whether the point may be empty by checking wther all the points are NaN.
NewPolygon returns a new, empty, Polygon.
NewPolygonFlat returns a new Polygon with the given flat coordinates.
PointEmptyCoord is the NaN float64 representation of the empty coordinate.
SetSRID sets the SRID of an arbitrary geometry.
TransformInPlace replaces all coordinates in g using f.
# Constants
NoLayout is an unknown layout.
PointEmptyCoordHex is the hex representation of a NaN that represents an empty coord in a shape.
XY is a 2D layout (X and Y).
XYM is a 2D layout with an M value.
XYZ is 3D layout (X, Y, and Z).
XYZM is a 3D layout with an M value.
# Structs
A Bounds represents a multi-dimensional bounding box.
An ErrLayoutMismatch is returned when geometries with different layouts cannot be combined.
An ErrStrideMismatch is returned when the stride does not match the expected stride.
An ErrUnsupportedType is returned when the requested type is not supported.
A GeometryCollection is a collection of arbitrary geometries with the same SRID.
A LinearRing is a linear ring.
A LineString represents a single, unbroken line, linearly interpreted between zero or more control points.
A MultiLineString is a collection of LineStrings.
A MultiPoint is a collection of Points.
A MultiPolygon is a collection of Polygons.
A Point represents a single point.
A Polygon represents a polygon as a collection of LinearRings.
# Interfaces
T is a generic interface implemented by all geometry types.
# Type aliases
A Coord represents an N-dimensional coordinate.
An ErrUnsupportedLayout is returned when the requested layout is not supported.
A Layout describes the meaning of an N-dimensional coordinate.
NewMultiPointFlatOption represents an option that can be passed into NewMultiPointFlat.