geom

package
Version: v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 13 Imported by: 1

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 Contains added in v0.26.0

func Contains(a, b Geometry) (bool, error)

Contains returns true if and only if geometry A contains geometry B. Formally, the following two conditions must hold:

1. No points of B lies on the exterior of geometry A. That is, B must only be in the exterior or boundary of A.

2 .At least one point of the interior of B lies on the interior of A. That is, they can't *only* intersect at their boundaries.

func CoveredBy added in v0.26.0

func CoveredBy(a, b Geometry) (bool, error)

CoveredBy returns true if and only if geometry A is covered by geometry B. Formally, the following two conditions must hold:

1. No points of A lies on the exterior of geometry B. That is, A must only be in the exterior or boundary of B.

2. At least one point of A lies on B (either its interior or boundary).

func Covers added in v0.26.0

func Covers(a, b Geometry) (bool, error)

Covers returns true if and only if geometry A covers geometry B. Formally, the following two conditions must hold:

1. No points of B lies on the exterior of geometry A. That is, B must only be in the exterior or boundary of A.

2. At least one point of B lies on A (either its interior or boundary).

func Crosses added in v0.26.0

func Crosses(a, b Geometry) (bool, error)

Crosses returns true if and only if geometry A and B cross each other. Formally, the following conditions must hold:

1. The geometries must have some but not all interior points in common.

2. The dimensionality of the intersection must be less than the maximum dimension of the input geometries.

3. The intersection must not equal either of the input geometries.

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 Disjoint added in v0.26.0

func Disjoint(a, b Geometry) (bool, error)

Disjoint returns true if and only if the input geometries have no points in common.

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 Equals added in v0.26.0

func Equals(a, b Geometry) (bool, error)

Equals returns true if and only if the input geometries are spatially equal, i.e. they represent exactly the same set of points.

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: if the Point is invalid, then it is replaced with an empty Point.

* MultiPoint: if a child Point is invalid, then it is replace with an empty Point within the MultiPoint.

* 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 Overlaps added in v0.26.0

func Overlaps(a, b Geometry) (bool, error)

Overlaps returns true if and only if geometry A and B overlap with each other. Formally, the following conditions must hold:

1. The geometries must have the same dimension.

2. The geometries must have some but not all points in common.

3. The intersection of the geometries must have the same dimension as the geometries themselves.

func Relate added in v0.26.0

func Relate(a, b Geometry) (string, error)

Relate calculates the DE-9IM matrix between two geometries, describing how the two geometries relate to each other.

A DE-9IM matrix is a 3 by 3 matrix that describes the intersection between two geometries. Specifically, it considers the Interior (I), Boundary (B), and Exterior (E) of each geometry separately, and shows how each part intersects with the 3 parts of the other geometry.

Each entry in the matrix holds the dimension of the set formed when a specific combination of I, B, and E (one from each geometry) are intersected with each other. The entries are 2 for an areal intersection, 1 for a linear intersection, and 0 for a point intersection. The entry is F if there is no intersection at all (F stands for 'False').

For example, the BI entry could contain a 1 if the set formed by intersecting the boundary of the first geometry and the interior of the second geometry has dimension 1.

The matrix is represented by a 9 character string, with entries in row-major order (i.e. entries are ordered II, IB, IE, BI, BB, BE, EI, EB, EE).

func RelateMatches added in v0.26.0

func RelateMatches(intersectionMatrix, intersectionMatrixPattern string) (bool, error)

RelateMatches checks to see if an intersection matrix matches against an intersection matrix pattern. Each is a 9 character string that encodes a 3 by 3 matrix.

The intersection matrix has the same format as those computed by the Relate function. That is, it must be a 9 character string consisting of 'F', '0', '1', and '2' entries.

The intersection matrix pattern is also 9 characters, and consists of 'F', '0', '1', '2', 'T', and '*' entries.

An intersection matrix matches against an intersection matrix pattern if each entry in the intersection matrix matches against the corresponding entry in the intersection matrix pattern. An 'F' entry matches against an 'F' or '*' pattern. A '0' entry matches against '0', 'T', or '*'. A '1' entry matches against '1', 'T', or '*'. A '2' entry matches against '2', 'T', or '*'.

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.

func Touches added in v0.26.0

func Touches(a, b Geometry) (bool, error)

Touches returns true if and only if the geometries have at least 1 point in common, but their interiors don't intersect.

func Within added in v0.26.0

func Within(a, b Geometry) (bool, error)

Within returns true if and only if geometry A is completely within geometry B. Formally, the following two conditions must hold:

1. No points of A lies on the exterior of geometry B. That is, A must only be in the exterior or boundary of B.

2.At least one point of the interior of A lies on the interior of B. That is, they can't *only* intersect at their boundaries.

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 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. Coordinates values may be constructed manually using the type definition directly. Alternatively, one of the New(XYZM)Coordinates constructor functions can be used.

func (Coordinates) String added in v0.31.0

func (c Coordinates) String() string

String gives a string representation of the coordinates.

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 coordinates contain X, Y, and Z (height) values.
	DimXYZ CoordinatesType = 0b01

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

	// DimXYZM coordinates 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 a generalised 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 it can also represent degenerate cases where the width or height (or both) are zero, or the envelope is empty. Its bounds are validated so as to not be NaN or +/- Infinity.

An envelope can be thought of as as being similar to a regular geometry, but can only represent an empty geometry, a single point, a horizontal or vertical line, or an axis aligned rectangle with some area.

The Envelope zero value is the empty envelope. Envelopes are immutable after creation.

func NewEnvelope

func NewEnvelope(xys []XY) (Envelope, error)

NewEnvelope returns the smallest envelope that contains all provided XYs. It returns an error if any of the XYs contain NaN or +/- Infinity coordinates.

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. In the case of an empty envelope, the zero value Geometry is returned (representing an empty GeometryCollection).

func (Envelope) Center

func (e Envelope) Center() Point

Center returns the center point of the envelope.

func (Envelope) Contains

func (e Envelope) Contains(p XY) bool

Contains returns true if and only if this envelope contains the given XY. It always returns false in the case where the XY contains NaN or +/- Infinity coordinates.

func (Envelope) Covers

func (e Envelope) Covers(o Envelope) bool

Covers returns true if and only if this envelope entirely covers another envelope (i.e. every point in the other envelope is contained within this envelope). An envelope can only cover another if it is non-empty. Furthermore, an envelope can only be covered if it is non-empty.

func (Envelope) Distance

func (e Envelope) Distance(o Envelope) (float64, bool)

Distance calculates the shortest distance between this envelope and another envelope, which both must be non-empty for the distance to be well-defined (indicated by the bool return being true). If the envelopes are both non-empty and intersect with each other, the distance between them is still well-defined, but zero.

func (Envelope) ExpandToIncludeEnvelope

func (e Envelope) ExpandToIncludeEnvelope(o Envelope) Envelope

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

func (Envelope) ExtendToIncludeXY added in v0.32.0

func (e Envelope) ExtendToIncludeXY(xy XY) (Envelope, error)

ExtendToIncludeXY returns the smallest envelope that contains all of the points in this envelope along with the provided point. It gives an error if the XY contains NaN or +/- Infinite coordinates.

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 if and only if this envelope has any points in common with another envelope.

func (Envelope) IsEmpty added in v0.33.0

func (e Envelope) IsEmpty() bool

IsEmpty returns true if and only if this envelope is empty.

func (Envelope) IsLine added in v0.33.0

func (e Envelope) IsLine() bool

IsLine returns true if and only if this envelope represents a single line (which must be either vertical or horizontal).

func (Envelope) IsPoint added in v0.33.0

func (e Envelope) IsPoint() bool

IsPoint returns true if and only if this envelope represents a single point.

func (Envelope) IsRectangle added in v0.33.0

func (e Envelope) IsRectangle() bool

IsRectangle returns true if and only if this envelope represents a non-degenerate rectangle with some area.

func (Envelope) Max

func (e Envelope) Max() Point

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

func (Envelope) Min

func (e Envelope) Min() Point

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

func (Envelope) MinMaxXYs added in v0.33.1

func (e Envelope) MinMaxXYs() (XY, XY, bool)

MinMaxXYs returns the two XY values in the envelope that contain the minimum (first return value) and maximum (second return value) X and Y values in the envelope. The third return value is true if and only if the Envelope is non-empty and thus the first two return values are populated.

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, bool)

AsGeometryCollection checks if the geometry is a GeometryCollection, and returns it as a GeometryCollection if it is. The returned flag indicates if the conversion was successful.

func (Geometry) AsLineString added in v0.4.0

func (g Geometry) AsLineString() (LineString, bool)

AsLineString checks if the geometry is a LineString, and returns it as a LineString if it is. The returned flag indicates if the conversion was successful.

func (Geometry) AsMultiLineString added in v0.4.0

func (g Geometry) AsMultiLineString() (MultiLineString, bool)

AsMultiLineString checks if the geometry is a MultiLineString, and returns it as a MultiLineString if it is. The returned flag indicates if the conversion was successful.

func (Geometry) AsMultiPoint added in v0.4.0

func (g Geometry) AsMultiPoint() (MultiPoint, bool)

AsMultiPoint checks if the geometry is a MultiPoint, and returns it as a MultiPoint if it is. The returned flag indicates if the conversion was successful.

func (Geometry) AsMultiPolygon added in v0.4.0

func (g Geometry) AsMultiPolygon() (MultiPolygon, bool)

AsMultiPolygon checks if the geometry is a MultiPolygon, and returns it as a MultiPolygon if it is. The returned flag indicates if the conversion was successful.

func (Geometry) AsPoint added in v0.4.0

func (g Geometry) AsPoint() (Point, bool)

AsPoint checks if the geometry is a Point, and returns it as a Point if it is. The returned flag indicates if the conversion was successful.

func (Geometry) AsPolygon added in v0.4.0

func (g Geometry) AsPolygon() (Polygon, bool)

AsPolygon checks if the geometry is a Polygon, and returns it as a Polygon if it is. The returned flag indicates if the conversion was successful.

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) Dump added in v0.30.0

func (g Geometry) Dump() []Geometry

Dump breaks multi types (MultiPoints, MultiLineStrings, and MultiPolygons) and GeometryCollections into their constituent non-multi types (Points, LineStrings, and Polygons).

The returned slice will only ever contain Points, LineStrings, and Polygons.

When called on a Point, LineString, or Polygon is input, the original value is returned in a slice of length 1.

func (Geometry) DumpCoordinates added in v0.31.0

func (g Geometry) DumpCoordinates() Sequence

DumpCoordinates returns the control points making up the geometry as a Sequence.

func (Geometry) Envelope

func (g Geometry) Envelope() Envelope

Envelope returns the axis aligned bounding box that most tightly surrounds the geometry.

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.Marshaler interface by encoding this geometry as a GeoJSON geometry object.

func (Geometry) MustAsGeometryCollection added in v0.34.0

func (g Geometry) MustAsGeometryCollection() GeometryCollection

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

func (Geometry) MustAsLineString added in v0.34.0

func (g Geometry) MustAsLineString() LineString

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

func (Geometry) MustAsMultiLineString added in v0.34.0

func (g Geometry) MustAsMultiLineString() MultiLineString

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

func (Geometry) MustAsMultiPoint added in v0.34.0

func (g Geometry) MustAsMultiPoint() MultiPoint

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

func (Geometry) MustAsMultiPolygon added in v0.34.0

func (g Geometry) MustAsMultiPolygon() MultiPolygon

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

func (Geometry) MustAsPoint added in v0.34.0

func (g Geometry) MustAsPoint() Point

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

func (Geometry) MustAsPolygon added in v0.34.0

func (g Geometry) MustAsPolygon() Polygon

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

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) Simplify added in v0.35.0

func (g Geometry) Simplify(threshold float64, opts ...ConstructorOption) (Geometry, error)

Simplify returns a simplified version of the geometry using the Ramer-Douglas-Peucker algorithm. Sometimes a simplified geometry can become invalid, in which case an error is returned rather than attempting to fix the geometry. Validation of the result can be skipped by making use of the geometry constructor options.

func (Geometry) String added in v0.31.0

func (g Geometry) String() string

String returns the string representation of the Geometry.

func (Geometry) Summary added in v0.31.0

func (g Geometry) Summary() string

Summary returns a text summary of the Geometry following a similar format to https://postgis.net/docs/ST_Summary.html.

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) Dump added in v0.30.0

func (c GeometryCollection) Dump() []Geometry

Dump breaks this GeometryCollection into its constituent non-multi types (Points, LineStrings, and Polygons).

The returned slice will only ever contain Points, LineStrings, and Polygons.

func (GeometryCollection) DumpCoordinates added in v0.31.0

func (c GeometryCollection) DumpCoordinates() Sequence

DumpCoordinates returns a Sequence holding all control points in the GeometryCollection.

func (GeometryCollection) Envelope

func (c GeometryCollection) Envelope() Envelope

Envelope returns the Envelope that most tightly surrounds the geometry.

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.Marshaler interface by encoding this geometry as a GeoJSON geometry object.

func (GeometryCollection) NumGeometries

func (c GeometryCollection) NumGeometries() int

NumGeometries gives the number of Geometry elements in the GeometryCollection.

func (GeometryCollection) NumTotalGeometries added in v0.31.0

func (c GeometryCollection) NumTotalGeometries() int

NumTotalGeometries gives the total number of Geometry elements in the GeometryCollection. If there are GeometryCollection-type child geometries, this will recursively count its children.

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) Scan added in v0.27.0

func (c *GeometryCollection) Scan(src interface{}) error

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

If the WKB doesn't represent a GeometryCollection geometry, then an error is returned.

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 (GeometryCollection) Simplify added in v0.35.0

func (c GeometryCollection) Simplify(threshold float64, opts ...ConstructorOption) (GeometryCollection, error)

Simplify returns a simplified version of the GeometryCollection by applying Simplify to each child geometry. Any supplied ConstructorOptions will be used when simplifying each child geometry.

func (GeometryCollection) String added in v0.31.0

func (c GeometryCollection) String() string

String returns the string representation of the GeometryCollection.

func (GeometryCollection) Summary added in v0.31.0

func (c GeometryCollection) Summary() string

Summary returns a text summary of the GeometryCollection following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (c *GeometryCollection) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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

Envelope returns the Envelope that most tightly surrounds the geometry.

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.Marshaler 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) Scan added in v0.27.0

func (s *LineString) Scan(src interface{}) error

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

If the WKB doesn't represent a LineString geometry, then an error is returned.

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 (LineString) Simplify added in v0.35.0

func (s LineString) Simplify(threshold float64) LineString

Simplify returns a simplified version of the LineString using the Ramer-Douglas-Peucker algorithm. If the Ramer-Douglas-Peucker algorithm were to create an invalid LineString (i.e. one having only a single distinct point), then the empty LineString is returned.

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) String added in v0.31.0

func (s LineString) String() string

String returns the string representation of the LineString.

func (LineString) Summary added in v0.31.0

func (s LineString) Summary() string

Summary returns a text summary of the LineString following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (s *LineString) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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 NewMultiLineString

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

NewMultiLineString 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 boundary 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 constituent 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) Dump added in v0.30.0

func (m MultiLineString) Dump() []LineString

Dump returns the MultiLineString represented as a LineString slice.

func (MultiLineString) DumpCoordinates added in v0.31.0

func (m MultiLineString) DumpCoordinates() Sequence

DumpCoordinates returns the coordinates (as a Sequence) that constitute the MultiLineString.

func (MultiLineString) Envelope

func (m MultiLineString) Envelope() Envelope

Envelope returns the Envelope that most tightly surrounds the geometry.

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.Marshaler 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) Scan added in v0.27.0

func (m *MultiLineString) Scan(src interface{}) error

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

If the WKB doesn't represent a MultiLineString geometry, then an error is returned.

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 (MultiLineString) Simplify added in v0.35.0

func (m MultiLineString) Simplify(threshold float64) MultiLineString

Simplify returns a simplified version of the MultiLineString by using the Ramer-Douglas-Peucker algorithm on each of the child LineStrings. If the Ramer-Douglas-Peucker were to create an invalid child LineString (i.e. one having only a single distinct point), then it is omitted in the output. Empty child LineStrings are also omitted from the output.

func (MultiLineString) String added in v0.31.0

func (m MultiLineString) String() string

String returns the string representation of the MultiLineString.

func (MultiLineString) Summary added in v0.31.0

func (m MultiLineString) Summary() string

Summary returns a text summary of the MultiLineString following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (m *MultiLineString) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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(pts []Point, opts ...ConstructorOption) MultiPoint

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

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() Sequence

Coordinates returns the coordinates of the non-empty points represented by the MultiPoint.

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) Dump added in v0.30.0

func (m MultiPoint) Dump() []Point

Dump returns the MultiPoint represented as a Point slice.

func (MultiPoint) DumpCoordinates added in v0.31.0

func (m MultiPoint) DumpCoordinates() Sequence

DumpCoordinates returns the non-empty points in a MultiPoint represented as a Sequence.

func (MultiPoint) Envelope

func (m MultiPoint) Envelope() Envelope

Envelope returns the Envelope that most tightly surrounds the geometry.

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.Marshaler 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) Scan added in v0.27.0

func (m *MultiPoint) Scan(src interface{}) error

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

If the WKB doesn't represent a MultiPoint geometry, then an error is returned.

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 (MultiPoint) String added in v0.31.0

func (m MultiPoint) String() string

String returns the string representation of the MultiPoint.

func (MultiPoint) Summary added in v0.31.0

func (m MultiPoint) Summary() string

Summary returns a text summary of the MultiPoint following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (m *MultiPoint) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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 NewMultiPolygon

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

NewMultiPolygon 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) Dump added in v0.30.0

func (m MultiPolygon) Dump() []Polygon

Dump returns the MultiPolygon represented as a Polygon slice.

func (MultiPolygon) DumpCoordinates added in v0.31.0

func (m MultiPolygon) DumpCoordinates() Sequence

DumpCoordinates returns the points making up the rings in a MultiPolygon as a Sequence.

func (MultiPolygon) Envelope

func (m MultiPolygon) Envelope() Envelope

Envelope returns the Envelope that most tightly surrounds the geometry.

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.Marshaler 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) Scan added in v0.27.0

func (m *MultiPolygon) Scan(src interface{}) error

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

If the WKB doesn't represent a MultiPolygon geometry, then an error is returned.

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 (MultiPolygon) Simplify added in v0.35.0

func (m MultiPolygon) Simplify(threshold float64, opts ...ConstructorOption) (MultiPolygon, error)

Simplify returns a simplified version of the MultiPolygon by applying Simplify to each child Polygon and constructing a new MultiPolygon from the result. Any supplied ConstructorOptions will be used when simplifying each child Polygon, or constructing the final MultiPolygon output.

func (MultiPolygon) String added in v0.31.0

func (m MultiPolygon) String() string

String returns the string representation of the MultiPolygon.

func (MultiPolygon) Summary added in v0.31.0

func (m MultiPolygon) Summary() string

Summary returns a text summary of the MultiPolygon following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (m *MultiPolygon) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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/driver.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 database/sql.Scanner interface.

func (NullGeometry) Value added in v0.8.0

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

Value implements the database/sql/driver.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, opts ...ConstructorOption) (Point, error)

NewPoint creates a new point given its Coordinates.

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) DumpCoordinates added in v0.31.0

func (p Point) DumpCoordinates() Sequence

DumpCoordinates returns a Sequence representing the point. For an empty Point, the Sequence will be empty. For a non-empty Point, the Sequence will contain the single set of coordinates representing the point.

func (Point) Envelope

func (p Point) Envelope() Envelope

Envelope returns the envelope best fitting the Point (either an empty envelope, or an envelope covering a single point).

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.Marshaler 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) Scan added in v0.27.0

func (p *Point) Scan(src interface{}) error

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

If the WKB doesn't represent a Point geometry, then an error is returned.

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 (Point) String added in v0.31.0

func (p Point) String() string

String returns the string representation of the Point.

func (Point) Summary added in v0.31.0

func (p Point) Summary() string

Summary returns a text summary of the Point following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (p *Point) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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 NewPolygon

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

NewPolygon 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) DumpCoordinates added in v0.31.0

func (p Polygon) DumpCoordinates() Sequence

DumpCoordinates returns the points making up the rings in a Polygon as a Sequence.

func (Polygon) Envelope

func (p Polygon) Envelope() Envelope

Envelope returns the Envelope that most tightly surrounds the geometry.

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.Marshaler 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) NumRings added in v0.31.0

func (p Polygon) NumRings() int

NumRings gives the total number of rings: ExternalRing + NumInteriorRings().

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) Scan added in v0.27.0

func (p *Polygon) Scan(src interface{}) error

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

If the WKB doesn't represent a Polygon geometry, then an error is returned.

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 (Polygon) Simplify added in v0.35.0

func (p Polygon) Simplify(threshold float64, opts ...ConstructorOption) (Polygon, error)

Simplify returns a simplified version of the Polygon by applying the Ramer-Douglas-Peucker algorithm to each constituent ring. If the exterior ring collapses to a point or single linear element, the empty Polygon is returned. If any interior ring collapses to a point or a single linear element, then it is omitted from the final output. The output Polygon will be invalid if any rings in the input become non-rings (e.g. via self intersection) in the output, or if any two rings were to interact in ways prohibited by Polygon validation rules (such as intersecting at more than one point). In these cases, an error is returned. Construction behaviour of the output (which includes omitting errors) may be controlled via ConstructorOptions.

func (Polygon) String added in v0.31.0

func (p Polygon) String() string

String returns the string representation of the Polygon.

func (Polygon) Summary added in v0.31.0

func (p Polygon) Summary() string

Summary returns a text summary of the Polygon following a similar format to https://postgis.net/docs/ST_Summary.html.

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) UnmarshalJSON added in v0.35.0

func (p *Polygon) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface by decoding the GeoJSON representation of 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 coordinates 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.

func (Sequence) Slice added in v0.28.0

func (s Sequence) Slice(i, j int) Sequence

Slice creates a new Sequence that is a subslice of this Sequence. Indexing rules work in the same way as Go Slices.

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) AsPoint added in v0.32.0

func (w XY) AsPoint(opts ...ConstructorOption) (Point, error)

AsPoint is a convenience function to convert this XY value into a Point geometry.

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