geom

package
v0.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 14 Imported by: 18

Documentation

Overview

Package geom implements the OpenGIS Simple Feature Access specification. The specification describes an access and storage model for 2-dimensional geometries.

The package serves three primary purposes:

1. Access: It provides a type for each of the different geometry types described by the standard: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, and GeometryCollection. It also contains supporting types such as Geometry, Envelope, Sequence, and XY. Methods on these types allow access the internal parts of each geometry. For example, there is a method that will obtain the first Point in a LineString.

2. Analysis: There are methods on the types that perform spatial analysis on the geometries. For example, to check if a geometry is simple or to calculate its smallest bounding box.

3. Storage: The types implement various methods that allow conversion to and from various storage and encoding formats. WKT (Well Known Text), WKB (Well Known Binary), and GeoJSON are supported.

Index

Constants

This section is empty.

Variables

View Source
var IgnoreOrder = ExactEqualsOption(
	func(c exactEqualsComparator) exactEqualsComparator {
		c.ignoreOrder = true
		return c
	},
)

IgnoreOrder modifies the behaviour of the ExactEquals method by ignoring ordering that doesn't have a material impact on geometries.

For Points, there is no ordering, so this option does nothing.

For LineStrings, the direction of the curve (start to end or end to start) is ignored. If the LineStrings are rings, (i.e. are simple and closed), the location of the start and end point of the ring is also ignored.

For polygons the ordering between any interior rings is ignored, as is the ordering inside the rings themselves.

For collections (MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection), the ordering of constituent elements in the collection are ignored.

Functions

func DisableAllValidations

func DisableAllValidations(o *ctorOptionSet)

DisableAllValidations causes geometry constructors to skip all validations. This allows invalid geometries to be loaded, but also has several implications for using the resultant geometries:

1. If the geometry is invalid, then any geometric calculations resulting from the geometry may be invalid.

2. If the geometry is invalid, then invoking geometric calculations may cause a panic or infinite loop.

This option should be used with caution. It is most useful when invalid geometries need to be loaded, but no geometric calculations will be performed.

func Distance added in v0.21.0

func Distance(g1, g2 Geometry) (float64, bool)

Distance calculates the shortest distance (using the Euclidean metric) between two geometries. If either geometry is empty, then false is returned and the distance is not calculated.

func ExactEquals added in v0.24.0

func ExactEquals(g1, g2 Geometry, opts ...ExactEqualsOption) bool

ExactEquals checks if two geometries are equal from a structural pointwise equality perspective. Geometries that are structurally equal are defined by exactly same control points in the same order. Note that even if two geometries are spatially equal (i.e. represent the same point set), they may not be defined by exactly the same way. Ordering differences and numeric tolerances can be accounted for using options.

func Intersects added in v0.24.0

func Intersects(g1, g2 Geometry) bool

Intersects return true if and only the two geometries intersect with each other, i.e. the point sets that the geometries represent have at least one common point.

func OmitInvalid added in v0.20.0

func OmitInvalid(o *ctorOptionSet)

OmitInvalid causes geometry constructors to omit any geometries or sub-geometries that are invalid.

The behaviour for each geometry type is:

* Point and MultiPoint: no effect (because Point and MultiPoint don't have geometry constraints).

* LineString: if the LineString is invalid (e.g. doesn't contain at least 2 distinct points), then it is replaced with an empty LineString.

* MultiLineString: if a child LineString is invalid, then it is replaced with an empty LineString within the MultiLineString.

* Polygon: if the Polygon is invalid (e.g. self intersecting rings or rings that intersect in an invalid way), then it is replaced with an empty Polygon.

* MultiPolygon: if a child Polygon is invalid, then it is replaced with an empty Polygon within the MultiPolygon. If two child Polygons interact in an invalid way, then the MultiPolygon is replaced with an empty MultiPolygon.

func SignedArea added in v0.20.0

func SignedArea(o *areaOptionSet)

SignedArea alters the behaviour of area calculations. It causes them to give a positive areas when the outer rings are wound CCW and any inner rings are wound CW, and a negative area when the outer rings are wound CW and any inner rings are wound CCW. If the windings of the inner and outer rings are the same, then the area will be inconsistent.

Types

type AreaOption added in v0.20.0

type AreaOption func(o *areaOptionSet)

AreaOption allows the behaviour of area calculations to be modified.

func WithTransform added in v0.20.0

func WithTransform(tr func(XY) XY) AreaOption

WithTransform alters the behaviour of area calculations by first transforming the geometry with the provided transform function.

type BitSet added in v0.10.0

type BitSet struct {
	// contains filtered or unexported fields
}

BitSet is a set data structure that holds a mapping from non-negative integers to boolean values (bits). The zero value is the BitSet with all bits set to false.

func (*BitSet) Clone added in v0.10.0

func (b *BitSet) Clone() BitSet

Clone makes a deep copy of the BitSet.

func (*BitSet) Get added in v0.10.0

func (b *BitSet) Get(i int) bool

Get gets the bit as position i. It panics if i is negative. Get returns false for bits that haven't been explicitly set.

func (*BitSet) Set added in v0.10.0

func (b *BitSet) Set(i int, newVal bool)

Set sets the bit in position i to a new value.

type ConstructorOption

type ConstructorOption func(o *ctorOptionSet)

ConstructorOption allows the behaviour of Geometry constructor functions to be modified.

type Coordinates

type Coordinates struct {
	// XY represents the XY position of the point location.
	XY

	// Z represents the height of the location. Its value is zero
	// for non-3D coordinate types.
	Z float64

	// M represents a user defined measure associated with the
	// location. Its value is zero for non-measure coordinate
	// types.
	M float64

	// Type indicates the coordinates type, and therefore whether
	// or not Z and M are populated.
	Type CoordinatesType
}

Coordinates represents a point location.

type CoordinatesType added in v0.10.0

type CoordinatesType byte

CoordinatesType controls the dimensionality and type of data used to encode a point location. At minimum, a point location is defined by X and Y coordinates. It may optionally include a Z value, representing height. It may also optionally include an M value, traditionally representing an arbitrary user defined measurement associated with each point location.

const (
	// DimXY coordinates only contain X and Y values.
	DimXY CoordinatesType = 0b00

	// DimXYZ coordiantes contain X, Y, and Z (height) values.
	DimXYZ CoordinatesType = 0b01

	// DimXYM coordiantes contain X, Y, and M (measure) values.
	DimXYM CoordinatesType = 0b10

	// DimXYZM coordiantes contain X, Y, Z (height), and M (measure) values.
	DimXYZM CoordinatesType = 0b11
)

func (CoordinatesType) Dimension added in v0.10.0

func (t CoordinatesType) Dimension() int

Dimension returns the number of float64 coordinates required to encode a point location using the CoordinatesType.

func (CoordinatesType) Is3D added in v0.10.0

func (t CoordinatesType) Is3D() bool

Is3D returns true if and only if the CoordinatesType includes a Z (3D) value.

func (CoordinatesType) IsMeasured added in v0.10.0

func (t CoordinatesType) IsMeasured() bool

IsMeasured returns true if and only if the Coordinates type includes an M (measure) value.

func (CoordinatesType) String added in v0.10.0

func (t CoordinatesType) String() string

String gives a string representation of a CoordinatesType.

type Envelope

type Envelope struct {
	// contains filtered or unexported fields
}

Envelope is an axis-aligned rectangle (also known as an Axis Aligned Bounding Box or Minimum Bounding Rectangle). It usually represents a 2D area with non-zero width and height, but can also represent degenerate cases where the width or height (or both) are zero.

func EnvelopeFromGeoms

func EnvelopeFromGeoms(geoms ...Geometry) (Envelope, bool)

EnvelopeFromGeoms returns the smallest envelope that contains all points contained by the provided geometries, provided that at least one non-empty geometry is given. If no non-empty geometries are given, then the returned flag is set to false.

func NewEnvelope

func NewEnvelope(first XY, others ...XY) Envelope

NewEnvelope returns the smallest envelope that contains all provided points.

func (Envelope) Area

func (e Envelope) Area() float64

Area returns the area covered by the envelope.

func (Envelope) AsGeometry

func (e Envelope) AsGeometry() Geometry

AsGeometry returns the envelope as a Geometry. In the regular case where the envelope covers some area, then a Polygon geometry is returned. In degenerate cases where the envelope only covers a line or a point, a LineString or Point geometry is returned.

func (Envelope) Center

func (e Envelope) Center() XY

Center returns the center point of the envelope.

func (Envelope) Contains

func (e Envelope) Contains(p XY) bool

Contains returns true iff this envelope contains the given point.

func (Envelope) Covers

func (e Envelope) Covers(o Envelope) bool

Covers returns true iff and only if this envelope entirely covers another envelope (i.e. every point in the other envelope is contained within this envelope).

func (Envelope) Distance

func (e Envelope) Distance(o Envelope) float64

Distance calculates the stortest distance between this envelope and another envelope. If the envelopes intersect with each other, then the returned distance is 0.

func (Envelope) ExpandBy

func (e Envelope) ExpandBy(x, y float64) (Envelope, bool)

ExpandBy calculates a new version of this envelope that is expanded in the x and y dimensions. Both the minimum and maximum points in the envelope are expanded by the supplied x and y amounts. Positive values increase the size of the envelope and negative amounts decrease the size of the envelope. If a decrease in envelope size would result in an invalid envelope (where min is greater than max), then false is returned and no envelope is calculated.

func (Envelope) ExpandToIncludeEnvelope

func (e Envelope) ExpandToIncludeEnvelope(other Envelope) Envelope

ExpandToIncludeEnvelope returns the smallest envelope that contains all of the points in this envelope and another envelope.

func (Envelope) ExtendToIncludePoint

func (e Envelope) ExtendToIncludePoint(point XY) Envelope

ExtendToIncludePoint returns the smallest envelope that contains all of the points in this envelope along with the provided point.

func (Envelope) Height

func (e Envelope) Height() float64

Height returns the difference between the maximum and minimum X coordinates of the envelope.

func (Envelope) Intersects

func (e Envelope) Intersects(o Envelope) bool

Intersects returns true iff this envelope has any points in common with another envelope.

func (Envelope) Max

func (e Envelope) Max() XY

Max returns the point in the envelope with the maximum X and Y values.

func (Envelope) Min

func (e Envelope) Min() XY

Min returns the point in the envelope with the minimum X and Y values.

func (Envelope) Width

func (e Envelope) Width() float64

Width returns the difference between the maximum and minimum X coordinates of the envelope.

type ExactEqualsOption added in v0.24.0

type ExactEqualsOption func(exactEqualsComparator) exactEqualsComparator

ExactEqualsOption allows the behaviour of the ExactEquals method in the Geometry interface to be modified.

func ToleranceXY added in v0.10.0

func ToleranceXY(within float64) ExactEqualsOption

ToleranceXY modifies the behaviour of the ExactEquals method by allowing two geometry control points be be considered equal if their XY coordinates are within the given euclidean distance of each other.

type GeoJSONFeature

type GeoJSONFeature struct {
	// Geometry is the geometry that is associated with the Feature.
	Geometry Geometry

	// ID is an identifier to refer to the feature. If an identifier isn't
	// applicable, ID can be left as nil. If it's set, then its value should
	// marshal into a JSON string or number (this is not enforced).
	ID interface{}

	// Properties are free-form properties that are associated with the
	// feature. If there are no properties associated with the feature, then it
	// can either be left as nil.
	Properties map[string]interface{}
}

GeoJSONFeature represents a Geometry with associated free-form properties. GeoJSONFeature values have a one to one correspondence with GeoJSON Features.

func (GeoJSONFeature) MarshalJSON

func (f GeoJSONFeature) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface by marshalling into a GeoJSON FeatureCollection object.

func (*GeoJSONFeature) UnmarshalJSON

func (f *GeoJSONFeature) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface by unmarshalling a GeoJSON Feature Collection object.

type GeoJSONFeatureCollection

type GeoJSONFeatureCollection []GeoJSONFeature

GeoJSONFeatureCollection is a collection of GeoJSONFeatures. GeoJSONFeatureCollection values have a one to one correspondence with GeoJSON FeatureCollections.

func (GeoJSONFeatureCollection) MarshalJSON

func (c GeoJSONFeatureCollection) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface by marshalling into a GeoJSON FeatureCollection object.

func (*GeoJSONFeatureCollection) UnmarshalJSON

func (c *GeoJSONFeatureCollection) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface by unmarshalling a GeoJSON FeatureCollection object.

type Geometry

type Geometry struct {
	// contains filtered or unexported fields
}

Geometry is a single geometry of any type. Its zero value is valid and is an empty GeometryCollection. It is immutable after creation.

func Difference added in v0.22.0

func Difference(a, b Geometry) (Geometry, error)

Difference returns a geometry that represents the parts of input geometry A that are not part of input geometry B. An error may be returned in cases of pathological cases of numerical degeneracy. GeometryCollections are not supported.

func Intersection added in v0.22.0

func Intersection(a, b Geometry) (Geometry, error)

Intersection returns a geometry that represents the parts that are common to both geometry A and geometry B. An error may be returned in pathological cases of numerical degeneracy. GeometryCollections are not supported.

func SymmetricDifference added in v0.22.0

func SymmetricDifference(a, b Geometry) (Geometry, error)

SymmetricDifference returns a geometry that represents the parts of geometry A and B that are not in common. An error may be returned in pathological cases of numerical degeneracy. GeometryCollections are not supported.

func Union added in v0.22.0

func Union(a, b Geometry) (Geometry, error)

Union returns a geometry that represents the parts from either geometry A or geometry B (or both). An error may be returned in pathological cases of numerical degeneracy. GeometryCollections are not supported.

func UnmarshalGeoJSON

func UnmarshalGeoJSON(input []byte, opts ...ConstructorOption) (Geometry, error)

UnmarshalGeoJSON unmarshals a geometry that is encoded as a GeoJSON Geometry Object.

func UnmarshalWKB

func UnmarshalWKB(wkb []byte, opts ...ConstructorOption) (Geometry, error)

UnmarshalWKB reads the Well Known Binary (WKB), and returns the corresponding Geometry.

func UnmarshalWKT

func UnmarshalWKT(wkt string, opts ...ConstructorOption) (Geometry, error)

UnmarshalWKT parses a Well Known Text (WKT), and returns the corresponding Geometry.

func (Geometry) AppendWKB added in v0.12.0

func (g Geometry) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (Geometry) AppendWKT

func (g Geometry) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (Geometry) Area added in v0.4.0

func (g Geometry) Area(opts ...AreaOption) float64

Area gives the area of the Polygon or MultiPolygon or GeometryCollection. If the Geometry is none of those types, then 0 is returned.

func (Geometry) AsBinary

func (g Geometry) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (Geometry) AsGeometryCollection added in v0.4.0

func (g Geometry) AsGeometryCollection() GeometryCollection

AsGeometryCollection returns the geometry as a GeometryCollection. It panics if the geometry is not a GeometryCollection.

func (Geometry) AsLineString added in v0.4.0

func (g Geometry) AsLineString() LineString

AsLineString returns the geometry as a LineString. It panics if the geometry is not a LineString.

func (Geometry) AsMultiLineString added in v0.4.0

func (g Geometry) AsMultiLineString() MultiLineString

AsMultiLineString returns the geometry as a MultiLineString. It panics if the geometry is not a MultiLineString.

func (Geometry) AsMultiPoint added in v0.4.0

func (g Geometry) AsMultiPoint() MultiPoint

AsMultiPoint returns the geometry as a MultiPoint. It panics if the geometry is not a MultiPoint.

func (Geometry) AsMultiPolygon added in v0.4.0

func (g Geometry) AsMultiPolygon() MultiPolygon

AsMultiPolygon returns the geometry as a MultiPolygon. It panics if the Geometry is not a MultiPolygon.

func (Geometry) AsPoint added in v0.4.0

func (g Geometry) AsPoint() Point

AsPoint returns the geometry as a Point. It panics if the geometry is not a Point.

func (Geometry) AsPolygon added in v0.4.0

func (g Geometry) AsPolygon() Polygon

AsPolygon returns the geometry as a Polygon. It panics if the geometry is not a Polygon.

func (Geometry) AsText

func (g Geometry) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (Geometry) Boundary

func (g Geometry) Boundary() Geometry

Boundary returns the Geometry representing the spatial limit of this geometry. The precise definition is dependant on the concrete geometry type (see the documentation of each concrete Geometry's Boundary method for details).

func (Geometry) Centroid added in v0.4.0

func (g Geometry) Centroid() Point

Centroid returns the geometry's centroid Point. If the Geometry is empty, then an empty Point is returned.

func (Geometry) ConvexHull

func (g Geometry) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (Geometry) CoordinatesType added in v0.10.0

func (g Geometry) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (Geometry) Dimension

func (g Geometry) Dimension() int

Dimension returns the dimension of the Geometry. This is 0 for Points and MultiPoints, 1 for LineStrings and MultiLineStrings, and 2 for Polygons and MultiPolygons (regardless of whether or not they are empty). For GeometryCollections it is the maximum dimension over the collection (or 0 if the collection is the empty collection).

func (Geometry) Envelope

func (g Geometry) Envelope() (Envelope, bool)

Envelope returns the axis aligned bounding box that most tightly surrounds the geometry. Envelopes are not defined for empty geometries, in which case the returned flag will be false.

func (Geometry) Force2D added in v0.10.0

func (g Geometry) Force2D() Geometry

Force2D returns a copy of the geometry with Z and M values removed.

func (Geometry) ForceCCW added in v0.20.0

func (g Geometry) ForceCCW() Geometry

ForceCCW returns the equivalent Geometry that has its exterior rings in a counter-clockwise orientation and any inner rings in a clockwise orientation. Non-areal geometrys are returned as is.

func (Geometry) ForceCW added in v0.20.0

func (g Geometry) ForceCW() Geometry

ForceCW returns the equivalent Geometry that has its exterior rings in a clockwise orientation and any inner rings in a counter-clockwise orientation. Non-areal geometrys are returned as is.

func (Geometry) ForceCoordinatesType added in v0.10.0

func (g Geometry) ForceCoordinatesType(newCType CoordinatesType) Geometry

ForceCoordinatesType returns a new Geometry with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (Geometry) IsEmpty

func (g Geometry) IsEmpty() bool

IsEmpty returns true if this geometry is empty. Collection types are empty if they have zero elements or only contain empty elements.

func (Geometry) IsGeometryCollection added in v0.4.0

func (g Geometry) IsGeometryCollection() bool

IsGeometryCollection return true iff the Geometry is a GeometryCollection geometry.

func (Geometry) IsLineString added in v0.4.0

func (g Geometry) IsLineString() bool

IsLineString return true iff the Geometry is a LineString geometry.

func (Geometry) IsMultiLineString added in v0.4.0

func (g Geometry) IsMultiLineString() bool

IsMultiLineString return true iff the Geometry is a MultiLineString geometry.

func (Geometry) IsMultiPoint added in v0.4.0

func (g Geometry) IsMultiPoint() bool

IsMultiPoint return true iff the Geometry is a MultiPoint geometry.

func (Geometry) IsMultiPolygon added in v0.4.0

func (g Geometry) IsMultiPolygon() bool

IsMultiPolygon return true iff the Geometry is a MultiPolygon geometry.

func (Geometry) IsPoint added in v0.4.0

func (g Geometry) IsPoint() bool

IsPoint return true iff the Geometry is a Point geometry.

func (Geometry) IsPolygon added in v0.4.0

func (g Geometry) IsPolygon() bool

IsPolygon return true iff the Geometry is a Polygon geometry.

func (Geometry) IsSimple added in v0.4.0

func (g Geometry) IsSimple() (isSimple bool, wellDefined bool)

IsSimple calculates whether or not the geometry contains any anomalous geometric points such as self intersection or self tangency. For details about the precise definition for each type of geometry, see the IsSimple method documentation on that type. It is not defined for GeometryCollections, in which case false is returned.

func (Geometry) Length added in v0.4.0

func (g Geometry) Length() float64

Length gives the length of a Line, LineString, or MultiLineString or the sum of the lengths of the components of a GeometryCollection. Other Geometries are defined to return a length of zero.

func (Geometry) MarshalJSON added in v0.4.0

func (g Geometry) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (Geometry) PointOnSurface added in v0.16.0

func (g Geometry) PointOnSurface() Point

PointOnSurface returns a Point that lies inside the geometry.

func (Geometry) Reverse added in v0.6.0

func (g Geometry) Reverse() Geometry

Reverse returns a new geometry containing coordinates listed in reverse order. Multi component geometries do not reverse the order of their components, but merely reverse each component's coordinates in place.

func (*Geometry) Scan added in v0.4.0

func (g *Geometry) Scan(src interface{}) error

Scan implements the database/sql.Scanner interface by parsing the src value as WKB (Well Known Binary).

It constructs the resultant geometry with no ConstructionOptions. If ConstructionOptions are needed, then the value should be scanned into a byte slice and then UnmarshalWKB called manually (passing in the ConstructionOptions as desired).

func (Geometry) TransformXY

func (g Geometry) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (Geometry, error)

TransformXY transforms this Geometry into another geometry according the mapping provided by the XY function. Some classes of mappings (such as affine transformations) will preserve the validity this Geometry in the transformed Geometry, in which case no error will be returned. Other types of transformations may result in a validation error if their mapping results in an invalid Geometry.

func (Geometry) Type added in v0.9.0

func (g Geometry) Type() GeometryType

Type returns a string representation of the geometry's type.

func (*Geometry) UnmarshalJSON added in v0.4.0

func (g *Geometry) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaller interface by parsing the JSON stream as GeoJSON geometry object.

It constructs the resultant geometry with no ConstructionOptions. If ConstructionOptions are needed, then the value should be unmarshalled into a json.RawMessage value and then UnmarshalJSON called manually (passing in the ConstructionOptions as desired).

func (Geometry) Value added in v0.4.0

func (g Geometry) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type GeometryCollection

type GeometryCollection struct {
	// contains filtered or unexported fields
}

GeometryCollection is a non-homogeneous collection of geometries. Its zero value is the empty GeometryCollection (i.e. a collection of zero geometries).

func NewGeometryCollection

func NewGeometryCollection(geoms []Geometry, opts ...ConstructorOption) GeometryCollection

NewGeometryCollection creates a collection of geometries. The coordinates type of the GeometryCollection is the lowest common coordinates type of its child geometries.

func (GeometryCollection) AppendWKB added in v0.12.0

func (c GeometryCollection) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (GeometryCollection) AppendWKT

func (c GeometryCollection) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (GeometryCollection) Area added in v0.6.0

func (c GeometryCollection) Area(opts ...AreaOption) float64

Area in the case of a GeometryCollection is the sum of the areas of its parts.

func (GeometryCollection) AsBinary

func (c GeometryCollection) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (GeometryCollection) AsGeometry added in v0.4.0

func (c GeometryCollection) AsGeometry() Geometry

AsGeometry converts this GeometryCollection into a Geometry.

func (GeometryCollection) AsText

func (c GeometryCollection) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (GeometryCollection) Boundary

Boundary returns the spatial boundary of this GeometryCollection. This is the GeometryCollection containing the boundaries of each child geometry.

func (GeometryCollection) Centroid added in v0.8.0

func (c GeometryCollection) Centroid() Point

Centroid of a GeometryCollection is the centroid of its parts' centroids.

func (GeometryCollection) ConvexHull

func (c GeometryCollection) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (GeometryCollection) CoordinatesType added in v0.10.0

func (c GeometryCollection) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (GeometryCollection) Dimension

func (c GeometryCollection) Dimension() int

Dimension returns the maximum dimension over the collection, or 0 if the collection is the empty collection. Points and MultiPoints have dimension 0, LineStrings and MultiLineStrings have dimension 1, and Polygons and MultiPolygons have dimension 2.

func (GeometryCollection) Envelope

func (c GeometryCollection) Envelope() (Envelope, bool)

Envelope returns the Envelope that most tightly surrounds the geometry. If the geometry is empty, then false is returned.

func (GeometryCollection) Force2D added in v0.10.0

Force2D returns a copy of the GeometryCollection with Z and M values removed.

func (GeometryCollection) ForceCCW added in v0.20.0

ForceCCW returns the equivalent GeometryCollection that has its constituent Polygons and MultiPolygons reoriented in a counter-clockwise direction (i.e. exterior rings counter-clockwise and interior rings clockwise). Geometries other that Polygons and MultiPolygons are unchanged.

func (GeometryCollection) ForceCW added in v0.20.0

ForceCW returns the equivalent GeometryCollection that has its constituent Polygons and MultiPolygons reoriented in a clockwise direction (i.e. exterior rings clockwise and interior rings counter-clockwise). Geometries other that Polygons and MultiPolygons are unchanged.

func (GeometryCollection) ForceCoordinatesType added in v0.10.0

func (c GeometryCollection) ForceCoordinatesType(newCType CoordinatesType) GeometryCollection

ForceCoordinatesType returns a new GeometryCollection with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (GeometryCollection) GeometryN

func (c GeometryCollection) GeometryN(n int) Geometry

GeometryN gives the nth (zero based) Geometry in the GeometryCollection.

func (GeometryCollection) IsEmpty

func (c GeometryCollection) IsEmpty() bool

IsEmpty return true if and only if this GeometryCollection doesn't contain any elements, or only contains empty elements.

func (GeometryCollection) Length added in v0.8.0

func (c GeometryCollection) Length() float64

Length of a GeometryCollection is the sum of the lengths of its parts.

func (GeometryCollection) MarshalJSON

func (c GeometryCollection) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (GeometryCollection) NumGeometries

func (c GeometryCollection) NumGeometries() int

NumGeometries gives the number of Geomety elements is the GeometryCollection.

func (GeometryCollection) PointOnSurface added in v0.16.0

func (c GeometryCollection) PointOnSurface() Point

PointOnSurface returns a Point that's on one of the geometries in the collection.

func (GeometryCollection) Reverse added in v0.6.0

Reverse in the case of GeometryCollection reverses each component and also returns them in the original order.

func (GeometryCollection) TransformXY

func (c GeometryCollection) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (GeometryCollection, error)

TransformXY transforms this GeometryCollection into another GeometryCollection according to fn.

func (GeometryCollection) Type added in v0.9.0

Type returns the GeometryType for a GeometryCollection

func (GeometryCollection) Value

func (c GeometryCollection) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type GeometryType added in v0.13.0

type GeometryType int

GeometryType represents one of the 7 geometry types.

const (
	// TypeGeometryCollection is the type of a GeometryCollection.
	TypeGeometryCollection GeometryType = iota
	// TypePoint is the type of a Point.
	TypePoint
	// TypeLineString is the type of a LineString.
	TypeLineString
	// TypePolygon is the type of a Polygon.
	TypePolygon
	// TypeMultiPoint is the type of a MultiPoint.
	TypeMultiPoint
	// TypeMultiLineString is the type of a MultiLineString.
	TypeMultiLineString
	// TypeMultiPolygon is the type of a MultiPolygon.
	TypeMultiPolygon
)

func (GeometryType) String added in v0.13.0

func (t GeometryType) String() string

type LineString

type LineString struct {
	// contains filtered or unexported fields
}

LineString is a linear geometry defined by linear interpolation between a finite set of points. Its zero value is the empty line string. It is immutable after creation.

A LineString must consist of either zero points (i.e. it is the empty line string), or it must have at least 2 points with distinct XY values.

func NewLineString added in v0.10.0

func NewLineString(seq Sequence, opts ...ConstructorOption) (LineString, error)

NewLineString creates a new LineString from a Sequence of points. The sequence must contain exactly 0 points, or at least 2 points with distinct XY values (otherwise an error is returned).

func (LineString) AppendWKB added in v0.12.0

func (s LineString) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (LineString) AppendWKT

func (s LineString) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (LineString) AsBinary

func (s LineString) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (LineString) AsGeometry added in v0.4.0

func (s LineString) AsGeometry() Geometry

AsGeometry converts this LineString into a Geometry.

func (LineString) AsMultiLineString added in v0.2.0

func (s LineString) AsMultiLineString() MultiLineString

AsMultiLineString is a convenience function that converts this LineString into a MultiLineString.

func (LineString) AsText

func (s LineString) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (LineString) Boundary

func (s LineString) Boundary() MultiPoint

Boundary returns the spatial boundary of this LineString. For closed LineStrings (i.e. LineStrings where the start and end points have the same XY value), this is the empty MultiPoint. For non-closed LineStrings, this is the MultiPoint containing the two endpoints of the LineString.

func (LineString) Centroid added in v0.8.0

func (s LineString) Centroid() Point

Centroid gives the centroid of the coordinates of the line string.

func (LineString) ConvexHull

func (s LineString) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (LineString) Coordinates

func (s LineString) Coordinates() Sequence

Coordinates returns the coordinates of each point along the LineString.

func (LineString) CoordinatesType added in v0.10.0

func (s LineString) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (LineString) EndPoint

func (s LineString) EndPoint() Point

EndPoint gives the last point of the LineString. If the LineString is empty then it returns the empty Point.

func (LineString) Envelope

func (s LineString) Envelope() (Envelope, bool)

Envelope returns the Envelope that most tightly surrounds the geometry. If the geometry is empty, then false is returned.

func (LineString) Force2D added in v0.10.0

func (s LineString) Force2D() LineString

Force2D returns a copy of the LineString with Z and M values removed.

func (LineString) ForceCoordinatesType added in v0.10.0

func (s LineString) ForceCoordinatesType(newCType CoordinatesType) LineString

ForceCoordinatesType returns a new LineString with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (LineString) IsClosed

func (s LineString) IsClosed() bool

IsClosed returns true if and only if this LineString is not empty and its start and end points are coincident.

func (LineString) IsEmpty

func (s LineString) IsEmpty() bool

IsEmpty returns true if and only if this LineString is the empty LineString. The empty LineString is defined by a zero length coordinates sequence.

func (LineString) IsRing

func (s LineString) IsRing() bool

IsRing returns true iff this LineString is both simple and closed (i.e. is a linear ring).

func (LineString) IsSimple

func (s LineString) IsSimple() bool

IsSimple returns true if this geometry contains no anomalous geometry points, such as self intersection or self tangency. LineStrings are simple if and only if the curve defined by the LineString doesn't pass through the same point twice (with the except of the two endpoints being coincident).

func (LineString) Length

func (s LineString) Length() float64

Length gives the length of the line string.

func (LineString) MarshalJSON

func (s LineString) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (LineString) PointOnSurface added in v0.16.0

func (s LineString) PointOnSurface() Point

PointOnSurface returns a Point on the LineString.

func (LineString) Reverse added in v0.6.0

func (s LineString) Reverse() LineString

Reverse in the case of LineString outputs the coordinates in reverse order.

func (LineString) StartPoint

func (s LineString) StartPoint() Point

StartPoint gives the first point of the LineString. If the LineString is empty then it returns the empty Point.

func (LineString) TransformXY

func (s LineString) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (LineString, error)

TransformXY transforms this LineString into another LineString according to fn.

func (LineString) Type added in v0.9.0

func (s LineString) Type() GeometryType

Type returns the GeometryType for a LineString

func (LineString) Value

func (s LineString) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type MultiLineString

type MultiLineString struct {
	// contains filtered or unexported fields
}

MultiLineString is a linear geometry that consists of a collection of LineStrings. Its zero value is the empty MultiLineString (i.e. the collection of zero LineStrings) of 2D coordinate type. It is immutable after creation.

func NewMultiLineStringFromLineStrings added in v0.10.0

func NewMultiLineStringFromLineStrings(lines []LineString, opts ...ConstructorOption) MultiLineString

NewMultiLineStringFromLineStrings creates a MultiLineString from its constituent LineStrings. The coordinates type of the MultiLineString is the lowest common coordinates type of its LineStrings.

func (MultiLineString) AppendWKB added in v0.12.0

func (m MultiLineString) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (MultiLineString) AppendWKT

func (m MultiLineString) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (MultiLineString) AsBinary

func (m MultiLineString) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (MultiLineString) AsGeometry added in v0.4.0

func (m MultiLineString) AsGeometry() Geometry

AsGeometry converts this MultiLineString into a Geometry.

func (MultiLineString) AsText

func (m MultiLineString) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (MultiLineString) Boundary

func (m MultiLineString) Boundary() MultiPoint

Boundary returns the spatial boundary of this MultiLineString. This is calculated using the "mod 2 rule". The rule states that a Point is included as part of the boundary if and only if it appears on the boundry of an odd number of members in the collection.

func (MultiLineString) Centroid added in v0.8.0

func (m MultiLineString) Centroid() Point

Centroid gives the centroid of the coordinates of the multi line string.

func (MultiLineString) ConvexHull

func (m MultiLineString) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (MultiLineString) Coordinates

func (m MultiLineString) Coordinates() []Sequence

Coordinates returns the coordinates of each constintuent LineString in the MultiLineString.

func (MultiLineString) CoordinatesType added in v0.10.0

func (m MultiLineString) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (MultiLineString) Envelope

func (m MultiLineString) Envelope() (Envelope, bool)

Envelope returns the Envelope that most tightly surrounds the geometry. If the geometry is empty, then false is returned.

func (MultiLineString) Force2D added in v0.10.0

func (m MultiLineString) Force2D() MultiLineString

Force2D returns a copy of the MultiLineString with Z and M values removed.

func (MultiLineString) ForceCoordinatesType added in v0.10.0

func (m MultiLineString) ForceCoordinatesType(newCType CoordinatesType) MultiLineString

ForceCoordinatesType returns a new MultiLineString with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (MultiLineString) IsEmpty

func (m MultiLineString) IsEmpty() bool

IsEmpty return true if and only if this MultiLineString doesn't contain any LineStrings, or only contains empty LineStrings.

func (MultiLineString) IsSimple

func (m MultiLineString) IsSimple() bool

IsSimple returns true if this geometry contains no anomalous geometry points, such as self intersection or self tangency. A MultiLineString is simple if and only if the following conditions hold:

1. Each element (a LineString) is simple.

2. The intersection between any two distinct elements occurs at points that are on the boundaries of both elements.

func (MultiLineString) Length

func (m MultiLineString) Length() float64

Length gives the sum of the lengths of the constituent members of the multi line string.

func (MultiLineString) LineStringN

func (m MultiLineString) LineStringN(n int) LineString

LineStringN gives the nth (zero indexed) LineString element.

func (MultiLineString) MarshalJSON

func (m MultiLineString) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (MultiLineString) NumLineStrings

func (m MultiLineString) NumLineStrings() int

NumLineStrings gives the number of LineString elements in the MultiLineString.

func (MultiLineString) PointOnSurface added in v0.16.0

func (m MultiLineString) PointOnSurface() Point

PointOnSurface returns a Point on one of the LineStrings in the collection.

func (MultiLineString) Reverse added in v0.6.0

func (m MultiLineString) Reverse() MultiLineString

Reverse in the case of MultiLineString outputs each component line string in their original order, each individually reversed.

func (MultiLineString) TransformXY

func (m MultiLineString) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (MultiLineString, error)

TransformXY transforms this MultiLineString into another MultiLineString according to fn.

func (MultiLineString) Type added in v0.9.0

func (m MultiLineString) Type() GeometryType

Type returns the GeometryType for a MultiLineString

func (MultiLineString) Value

func (m MultiLineString) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type MultiPoint

type MultiPoint struct {
	// contains filtered or unexported fields
}

MultiPoint is a 0-dimensional geometry that is a collection of points. Its zero value is the empty MultiPoint (i.e. a collection of zero points) with 2D coordinates type. It is immutable after creation.

func NewMultiPoint

func NewMultiPoint(seq Sequence, opts ...ConstructorOption) MultiPoint

NewMultiPoint creates a new MultiPoint from a sequence of Coordinates.

func NewMultiPointFromPoints added in v0.10.0

func NewMultiPointFromPoints(pts []Point, opts ...ConstructorOption) MultiPoint

NewMultiPointFromPoints creates a MultiPoint from a list of Points. The coordinate type of the MultiPoint is the lowest common coordinates type of its Points.

func NewMultiPointWithEmptyMask added in v0.10.0

func NewMultiPointWithEmptyMask(seq Sequence, empty BitSet, opts ...ConstructorOption) MultiPoint

NewMultiPointWithEmptyMask creates a new MultiPoint from a sequence of coordinates. If there are any positions set in the BitSet, then these are used to indicate that the corresponding point in the sequence is an empty point.

func (MultiPoint) AppendWKB added in v0.12.0

func (m MultiPoint) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (MultiPoint) AppendWKT

func (m MultiPoint) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (MultiPoint) AsBinary

func (m MultiPoint) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (MultiPoint) AsGeometry added in v0.4.0

func (m MultiPoint) AsGeometry() Geometry

AsGeometry converts this MultiPoint into a Geometry.

func (MultiPoint) AsText

func (m MultiPoint) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (MultiPoint) Boundary

func (m MultiPoint) Boundary() GeometryCollection

Boundary returns the spatial boundary for this MultiPoint, which is always the empty set. This is represented by the empty GeometryCollection.

func (MultiPoint) Centroid added in v0.8.0

func (m MultiPoint) Centroid() Point

Centroid gives the centroid of the coordinates of the MultiPoint.

func (MultiPoint) ConvexHull

func (m MultiPoint) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (MultiPoint) Coordinates

func (m MultiPoint) Coordinates() (seq Sequence, empty BitSet)

Coordinates returns the coordinates of the points represented by the MultiPoint. If a point has its corresponding bit set to true in the BitSet, then that point is empty.

func (MultiPoint) CoordinatesType added in v0.10.0

func (m MultiPoint) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (MultiPoint) Envelope

func (m MultiPoint) Envelope() (Envelope, bool)

Envelope returns the Envelope that most tightly surrounds the geometry. If the geometry is empty, then false is returned.

func (MultiPoint) Force2D added in v0.10.0

func (m MultiPoint) Force2D() MultiPoint

Force2D returns a copy of the MultiPoint with Z and M values removed.

func (MultiPoint) ForceCoordinatesType added in v0.10.0

func (m MultiPoint) ForceCoordinatesType(newCType CoordinatesType) MultiPoint

ForceCoordinatesType returns a new MultiPoint with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (MultiPoint) IsEmpty

func (m MultiPoint) IsEmpty() bool

IsEmpty return true if and only if this MultiPoint doesn't contain any Points, or only contains empty Points.

func (MultiPoint) IsSimple

func (m MultiPoint) IsSimple() bool

IsSimple returns true if this geometry contains no anomalous geometry points, such as self intersection or self tangency. MultiPoints are simple if and only if no two of its points have equal XY coordinates.

func (MultiPoint) MarshalJSON

func (m MultiPoint) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (MultiPoint) NumPoints

func (m MultiPoint) NumPoints() int

NumPoints gives the number of element points making up the MultiPoint.

func (MultiPoint) PointN

func (m MultiPoint) PointN(n int) Point

PointN gives the nth (zero indexed) Point.

func (MultiPoint) PointOnSurface added in v0.16.0

func (m MultiPoint) PointOnSurface() Point

PointOnSurface returns one of the Points in the Collection.

func (MultiPoint) Reverse added in v0.6.0

func (m MultiPoint) Reverse() MultiPoint

Reverse in the case of MultiPoint outputs each component point in their original order.

func (MultiPoint) TransformXY

func (m MultiPoint) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (MultiPoint, error)

TransformXY transforms this MultiPoint into another MultiPoint according to fn.

func (MultiPoint) Type added in v0.9.0

func (m MultiPoint) Type() GeometryType

Type returns the GeometryType for a MultiPoint

func (MultiPoint) Value

func (m MultiPoint) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type MultiPolygon

type MultiPolygon struct {
	// contains filtered or unexported fields
}

MultiPolygon is a planar surface geometry that consists of a collection of Polygons. The zero value is the empty MultiPolygon (i.e. the collection of zero Polygons). It is immutable after creation.

For a MultiPolygon to be valid, the following assertions must hold:

1. It must be made up of zero or more valid Polygons (any of which may be empty).

2. The interiors of any two polygons must not intersect.

3. The boundaries of any two polygons may touch only at a finite number of points.

func NewMultiPolygonFromPolygons added in v0.10.0

func NewMultiPolygonFromPolygons(polys []Polygon, opts ...ConstructorOption) (MultiPolygon, error)

NewMultiPolygonFromPolygons creates a MultiPolygon from its constituent Polygons. It gives an error if any of the MultiPolygon assertions are not maintained. The coordinates type of the MultiPolygon is the lowest common coordinates type its Polygons.

func (MultiPolygon) AppendWKB added in v0.12.0

func (m MultiPolygon) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (MultiPolygon) AppendWKT

func (m MultiPolygon) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (MultiPolygon) Area

func (m MultiPolygon) Area(opts ...AreaOption) float64

Area in the case of a MultiPolygon is the sum of the areas of its polygons.

func (MultiPolygon) AsBinary

func (m MultiPolygon) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (MultiPolygon) AsGeometry added in v0.4.0

func (m MultiPolygon) AsGeometry() Geometry

AsGeometry converts this MultiPolygon into a Geometry.

func (MultiPolygon) AsText

func (m MultiPolygon) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (MultiPolygon) Boundary

func (m MultiPolygon) Boundary() MultiLineString

Boundary returns the spatial boundary of this MultiPolygon. This is the MultiLineString containing the boundaries of the MultiPolygon's elements.

func (MultiPolygon) Centroid

func (m MultiPolygon) Centroid() Point

Centroid returns the multi polygon's centroid point. It returns the empty Point if the multi polygon is empty.

func (MultiPolygon) ConvexHull

func (m MultiPolygon) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (MultiPolygon) Coordinates

func (m MultiPolygon) Coordinates() [][]Sequence

Coordinates returns the coordinates of each constituent Polygon of the MultiPolygon.

func (MultiPolygon) CoordinatesType added in v0.10.0

func (m MultiPolygon) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (MultiPolygon) Envelope

func (m MultiPolygon) Envelope() (Envelope, bool)

Envelope returns the Envelope that most tightly surrounds the geometry. If the geometry is empty, then false is returned.

func (MultiPolygon) Force2D added in v0.10.0

func (m MultiPolygon) Force2D() MultiPolygon

Force2D returns a copy of the MultiPolygon with Z and M values removed.

func (MultiPolygon) ForceCCW added in v0.20.0

func (m MultiPolygon) ForceCCW() MultiPolygon

ForceCCW returns the equivalent MultiPolygon that has its exterior rings in a counter-clockwise orientation and any inner rings in a clockwise orientation.

func (MultiPolygon) ForceCW added in v0.20.0

func (m MultiPolygon) ForceCW() MultiPolygon

ForceCW returns the equivalent MultiPolygon that has its exterior rings in a clockwise orientation and any inner rings in a counter-clockwise orientation.

func (MultiPolygon) ForceCoordinatesType added in v0.10.0

func (m MultiPolygon) ForceCoordinatesType(newCType CoordinatesType) MultiPolygon

ForceCoordinatesType returns a new MultiPolygon with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (MultiPolygon) IsEmpty

func (m MultiPolygon) IsEmpty() bool

IsEmpty return true if and only if this MultiPolygon doesn't contain any Polygons, or only contains empty Polygons.

func (MultiPolygon) IsSimple

func (m MultiPolygon) IsSimple() bool

IsSimple returns true if this geometry contains no anomalous geometry points, such as self intersection or self tangency. Because MultiPolygons are always simple, this method always returns true.

func (MultiPolygon) MarshalJSON

func (m MultiPolygon) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (MultiPolygon) NumPolygons

func (m MultiPolygon) NumPolygons() int

NumPolygons gives the number of Polygon elements in the MultiPolygon.

func (MultiPolygon) PointOnSurface added in v0.16.0

func (m MultiPolygon) PointOnSurface() Point

PointOnSurface returns a Point on the interior of the MultiPolygon.

func (MultiPolygon) PolygonN

func (m MultiPolygon) PolygonN(n int) Polygon

PolygonN gives the nth (zero based) Polygon element.

func (MultiPolygon) Reverse added in v0.6.0

func (m MultiPolygon) Reverse() MultiPolygon

Reverse in the case of MultiPolygon outputs the component polygons in their original order, each individually reversed.

func (MultiPolygon) TransformXY

func (m MultiPolygon) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (MultiPolygon, error)

TransformXY transforms this MultiPolygon into another MultiPolygon according to fn.

func (MultiPolygon) Type added in v0.9.0

func (m MultiPolygon) Type() GeometryType

Type returns the GeometryType for a MultiPolygon

func (MultiPolygon) Value

func (m MultiPolygon) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type NullGeometry added in v0.8.0

type NullGeometry struct {
	Geometry Geometry
	Valid    bool // Valid is true iff Geometry is not NULL
}

NullGeometry represents a Geometry that may be NULL. It implements the database/sql.Scanner and database/sql.Valuer interfaces, so may be used as a scan destination or query argument in SQL queries.

func (*NullGeometry) Scan added in v0.8.0

func (ng *NullGeometry) Scan(value interface{}) error

Scan implements the the database/sql.Scanner interface.

func (NullGeometry) Value added in v0.8.0

func (ng NullGeometry) Value() (driver.Value, error)

Value implements the database/sql.Valuer interface.

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point is a zero dimensional geometry that represents a single location in a coordinate space. It is immutable after creation.

The Point may be empty.

The zero value of Point is a 2D empty Point.

func NewEmptyPoint

func NewEmptyPoint(ctype CoordinatesType) Point

NewEmptyPoint creates a Point that is empty.

func NewPoint added in v0.10.0

func NewPoint(c Coordinates, _ ...ConstructorOption) Point

NewPoint creates a new point gives its Coordinates.

func NewPointFromXY added in v0.10.0

func NewPointFromXY(xy XY, _ ...ConstructorOption) Point

NewPointFromXY creates a new point from an XY.

func (Point) AppendWKB added in v0.12.0

func (p Point) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (Point) AppendWKT

func (p Point) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (Point) AsBinary

func (p Point) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (Point) AsGeometry added in v0.4.0

func (p Point) AsGeometry() Geometry

AsGeometry converts this Point into a Geometry.

func (Point) AsMultiPoint added in v0.10.0

func (p Point) AsMultiPoint() MultiPoint

AsMultiPoint is a convenience function that converts this Point into a MultiPoint.

func (Point) AsText

func (p Point) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (Point) Boundary

func (p Point) Boundary() GeometryCollection

Boundary returns the spatial boundary for this Point, which is always the empty set. This is represented by the empty GeometryCollection.

func (Point) Centroid added in v0.8.0

func (p Point) Centroid() Point

Centroid of a point is that point.

func (Point) ConvexHull

func (p Point) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (Point) Coordinates

func (p Point) Coordinates() (Coordinates, bool)

Coordinates returns the coordinates of the point. The returned flag is set to true if and only if the point is non-empty.

func (Point) CoordinatesType added in v0.10.0

func (p Point) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent the Point.

func (Point) Envelope

func (p Point) Envelope() (Envelope, bool)

Envelope returns a zero area Envelope covering the Point. If the Point is empty, then false is returned.

func (Point) Force2D added in v0.10.0

func (p Point) Force2D() Point

Force2D returns a copy of the Point with Z and M values removed.

func (Point) ForceCoordinatesType added in v0.10.0

func (p Point) ForceCoordinatesType(newCType CoordinatesType) Point

ForceCoordinatesType returns a new Point with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (Point) IsEmpty

func (p Point) IsEmpty() bool

IsEmpty returns true if and only if this Point is the empty Point.

func (Point) IsSimple

func (p Point) IsSimple() bool

IsSimple returns true if this geometry contains no anomalous geometry points, such as self intersection or self tangency. Points are always simple, so this method always return true.

func (Point) MarshalJSON

func (p Point) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (Point) PointOnSurface added in v0.16.0

func (p Point) PointOnSurface() Point

PointOnSurface returns the original Point.

func (Point) Reverse added in v0.6.0

func (p Point) Reverse() Point

Reverse in the case of Point outputs the same point.

func (Point) TransformXY

func (p Point) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (Point, error)

TransformXY transforms this Point into another Point according to fn.

func (Point) Type added in v0.9.0

func (p Point) Type() GeometryType

Type returns the GeometryType for a Point

func (Point) Value

func (p Point) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

func (Point) XY

func (p Point) XY() (XY, bool)

XY gives the XY location of the point. The returned flag is set to true if and only if the point is non-empty.

type Polygon

type Polygon struct {
	// contains filtered or unexported fields
}

Polygon is a planar surface geometry. Its zero value is the empty Polygon. It is immutable after creation. When not empty, it is defined by one outer ring and zero or more interior rings. The outer ring defines the exterior boundary of the Polygon, and each inner ring defines a hole in the polygon.

For a Polygon to be valid, the following assertions must hold:

1. The rings (outer and inner) must be valid linear rings. This means that they must be non-empty, simple, and closed.

2. Each pair of rings must only intersect at a single point.

3. The interior of the polygon must be connected.

4. The holes must be fully inside the outer ring.

func NewPolygonFromRings added in v0.10.0

func NewPolygonFromRings(rings []LineString, opts ...ConstructorOption) (Polygon, error)

NewPolygonFromRings creates a polygon given its rings. The outer ring is first, and any inner rings follow. If no rings are provided, then the returned Polygon is the empty Polygon. The coordinate type of the polygon is the lowest common coordinate type of its rings.

func (Polygon) AppendWKB added in v0.12.0

func (p Polygon) AppendWKB(dst []byte) []byte

AppendWKB appends the WKB (Well Known Text) representation of the geometry to the input slice.

func (Polygon) AppendWKT

func (p Polygon) AppendWKT(dst []byte) []byte

AppendWKT appends the WKT (Well Known Text) representation of this geometry to the input byte slice.

func (Polygon) Area

func (p Polygon) Area(opts ...AreaOption) float64

Area of a Polygon is the area enclosed by the polygon's boundary.

func (Polygon) AsBinary

func (p Polygon) AsBinary() []byte

AsBinary returns the WKB (Well Known Text) representation of the geometry.

func (Polygon) AsGeometry added in v0.4.0

func (p Polygon) AsGeometry() Geometry

AsGeometry converts this Polygon into a Geometry.

func (Polygon) AsMultiPolygon added in v0.2.0

func (p Polygon) AsMultiPolygon() MultiPolygon

AsMultiPolygon is a helper that converts this Polygon into a MultiPolygon.

func (Polygon) AsText

func (p Polygon) AsText() string

AsText returns the WKT (Well Known Text) representation of this geometry.

func (Polygon) Boundary

func (p Polygon) Boundary() MultiLineString

Boundary returns the spatial boundary of this Polygon. For non-empty Polygons, this is the MultiLineString collection containing all of the rings.

func (Polygon) Centroid

func (p Polygon) Centroid() Point

Centroid returns the polygon's centroid point. If returns an empty Point if the Polygon is empty.

func (Polygon) ConvexHull

func (p Polygon) ConvexHull() Geometry

ConvexHull returns the geometry representing the smallest convex geometry that contains this geometry.

func (Polygon) Coordinates

func (p Polygon) Coordinates() []Sequence

Coordinates returns the coordinates of the rings making up the Polygon (external ring first, then internal rings after).

func (Polygon) CoordinatesType added in v0.10.0

func (p Polygon) CoordinatesType() CoordinatesType

CoordinatesType returns the CoordinatesType used to represent points making up the geometry.

func (Polygon) Envelope

func (p Polygon) Envelope() (Envelope, bool)

Envelope returns the Envelope that most tightly surrounds the geometry. If the geometry is empty, then false is returned.

func (Polygon) ExteriorRing

func (p Polygon) ExteriorRing() LineString

ExteriorRing gives the exterior ring of the polygon boundary. If the polygon is empty, then it returns the empty LineString.

func (Polygon) Force2D added in v0.10.0

func (p Polygon) Force2D() Polygon

Force2D returns a copy of the Polygon with Z and M values removed.

func (Polygon) ForceCCW added in v0.20.0

func (p Polygon) ForceCCW() Polygon

ForceCCW returns the equivalent Polygon that has its exterior ring in a counter-clockwise orientation and any inner rings in a clockwise orientation.

func (Polygon) ForceCW added in v0.20.0

func (p Polygon) ForceCW() Polygon

ForceCW returns the equivalent Polygon that has its exterior ring in a clockwise orientation and any inner rings in a counter-clockwise orientation.

func (Polygon) ForceCoordinatesType added in v0.10.0

func (p Polygon) ForceCoordinatesType(newCType CoordinatesType) Polygon

ForceCoordinatesType returns a new Polygon with a different CoordinatesType. If a dimension is added, then new values are populated with 0.

func (Polygon) InteriorRingN

func (p Polygon) InteriorRingN(n int) LineString

InteriorRingN gives the nth (zero indexed) interior ring in the polygon boundary. It will panic if n is out of bounds with respect to the number of interior rings.

func (Polygon) IsEmpty

func (p Polygon) IsEmpty() bool

IsEmpty returns true if and only if this Polygon is the empty Polygon. The empty Polygon doesn't have any rings and doesn't enclose any area.

func (Polygon) IsSimple

func (p Polygon) IsSimple() bool

IsSimple returns true if this geometry contains no anomalous geometry points, such as self intersection or self tangency. Because Polygons are always simple, this method always returns true.

func (Polygon) MarshalJSON

func (p Polygon) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaller interface by encoding this geometry as a GeoJSON geometry object.

func (Polygon) NumInteriorRings

func (p Polygon) NumInteriorRings() int

NumInteriorRings gives the number of interior rings in the polygon boundary.

func (Polygon) PointOnSurface added in v0.16.0

func (p Polygon) PointOnSurface() Point

PointOnSurface returns a Point that lies inside the Polygon.

func (Polygon) Reverse added in v0.6.0

func (p Polygon) Reverse() Polygon

Reverse in the case of Polygon outputs the coordinates of each ring in reverse order, but note the order of the inner rings is unchanged.

func (Polygon) TransformXY

func (p Polygon) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (Polygon, error)

TransformXY transforms this Polygon into another Polygon according to fn.

func (Polygon) Type added in v0.9.0

func (p Polygon) Type() GeometryType

Type returns the GeometryType for a Polygon

func (Polygon) Value

func (p Polygon) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface by returning the WKB (Well Known Binary) representation of this Geometry.

type Sequence added in v0.10.0

type Sequence struct {
	// contains filtered or unexported fields
}

Sequence represents a list of point locations. It is immutable after creation. All locations in the Sequence are specified using the same coordinates type.

The zero value is an empty sequence of coordinate type DimXY.

func NewSequence added in v0.10.0

func NewSequence(coordinates []float64, ctype CoordinatesType) Sequence

NewSequence creates a new Sequence from a raw slice of float64 coordinates. The slice will be retained by the constructed Sequence and must NOT be modified by the caller after the function returns.

The CoordiantesType indicates what type of coordinates the Sequence will store (i.e. just XY, XYZ, XYM, or XYZM).

The coordinates in the passed slice should be interleaved. That is, all of the coordinates for the first point come first, followed by all of the coordinates for the second point etc. Coordinates must be in the order of X followed by Y, then Z (if using XYZ or XYZM), then M (if using XYM or XYZM).

The length of the coordinates slice must be a multiple of the dimensionality of the coordiantes type. If the length is not a multiple, then this is a programming error and the function will panic.

func (Sequence) CoordinatesType added in v0.10.0

func (s Sequence) CoordinatesType() CoordinatesType

CoordinatesType returns the coordinates type used to represent point locations in the Sequence.

func (Sequence) Force2D added in v0.10.0

func (s Sequence) Force2D() Sequence

Force2D returns a new Sequence with Z and M values removed (if present).

func (Sequence) ForceCoordinatesType added in v0.10.0

func (s Sequence) ForceCoordinatesType(newCType CoordinatesType) Sequence

ForceCoordinatesType returns a new Sequence with a different CoordinatesType. If a dimension is added, then its new value is set to zero for each point location in the Sequence.

func (Sequence) Get added in v0.10.0

func (s Sequence) Get(i int) Coordinates

Get returns the Coordinates of the ith point location in the Sequence. It panics if i is out of range with respect to the number of points in the Sequence.

func (Sequence) GetXY added in v0.10.0

func (s Sequence) GetXY(i int) XY

GetXY returns the XY of the ith point location in the Sequence. It panics if i is out of range with respect to the number of points in the Sequence.

func (Sequence) Length added in v0.10.0

func (s Sequence) Length() int

Length returns the number of point locations represented by the Sequence.

func (Sequence) Reverse added in v0.10.0

func (s Sequence) Reverse() Sequence

Reverse returns a new Sequence containing the same point locations, but in reversed order.

type XY

type XY struct {
	X, Y float64
}

XY represents a pair of X and Y coordinates. This can either represent a location on the XY plane, or a 2D vector in the real vector space.

func (XY) Add

func (w XY) Add(o XY) XY

Add returns the result of adding this XY to another XY (in the same manner as vector addition).

func (XY) Cross

func (w XY) Cross(o XY) float64

Cross returns the 2D cross product of this and another XY. This is defined as the 'z' coordinate of the regular 3D cross product.

func (XY) Dot

func (w XY) Dot(o XY) float64

Dot returns the dot product of this and another XY.

func (XY) Length added in v0.21.0

func (w XY) Length() float64

Length treats XY as a vector, and returns its length.

func (XY) Less

func (w XY) Less(o XY) bool

Less gives an ordering on XYs. If two XYs have different X values, then the one with the lower X value is ordered before the one with the higher X value. If the X values are then same, then the Y values are used (the lower Y value comes first).

func (XY) Midpoint

func (w XY) Midpoint(o XY) XY

Midpoint returns the midpoint of this and another XY.

func (XY) Scale

func (w XY) Scale(s float64) XY

Scale returns the XY where the X and Y have been scaled by s.

func (XY) Sub

func (w XY) Sub(o XY) XY

Sub returns the result of subtracting the other XY from this XY (in the same manner as vector subtraction).

func (XY) Unit added in v0.21.0

func (w XY) Unit() XY

Unit treats the XY as a vector, and scales it to have unit length.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL