Documentation ¶
Overview ¶
Package geos provides support for creating and manipulating spatial data. At its core, it relies on the GEOS C library for the implementation of spatial operations and geometric algorithms.
Index ¶
- Variables
- func Error() error
- func Version() string
- type BufferOpts
- type CapStyle
- type Coord
- type Geometry
- func EmptyPolygon() (*Geometry, error)
- func FromHex(hex string) (*Geometry, error)
- func FromWKB(wkb []byte) (*Geometry, error)
- func FromWKT(wkt string) (*Geometry, error)
- func Must(g *Geometry, err error) *Geometry
- func NewCollection(_type GeometryType, geoms ...*Geometry) (*Geometry, error)
- func NewLineString(coords ...Coord) (*Geometry, error)
- func NewLinearRing(coords ...Coord) (*Geometry, error)
- func NewPoint(coords ...Coord) (*Geometry, error)
- func NewPolygon(shell []Coord, holes ...[]Coord) (*Geometry, error)
- func PolygonFromGeom(shell *Geometry, holes ...*Geometry) (*Geometry, error)
- func (g *Geometry) Area() (float64, error)
- func (g *Geometry) Boundary() (*Geometry, error)
- func (g *Geometry) Buffer(d float64) (*Geometry, error)
- func (g *Geometry) BufferWithOpts(width float64, opts BufferOpts) (*Geometry, error)
- func (g *Geometry) Centroid() (*Geometry, error)
- func (g *Geometry) Clone() (*Geometry, error)
- func (g *Geometry) Contains(other *Geometry) (bool, error)
- func (g *Geometry) ConvexHull() (*Geometry, error)
- func (g *Geometry) CoordDimension() int
- func (g *Geometry) Coords() ([]Coord, error)
- func (g *Geometry) CoveredBy(other *Geometry) (bool, error)
- func (g *Geometry) Covers(other *Geometry) (bool, error)
- func (g *Geometry) Crosses(other *Geometry) (bool, error)
- func (g *Geometry) Difference(other *Geometry) (*Geometry, error)
- func (g *Geometry) Dimension() int
- func (g *Geometry) Disjoint(other *Geometry) (bool, error)
- func (g *Geometry) Distance(other *Geometry) (float64, error)
- func (g *Geometry) EndPoint() (*Geometry, error)
- func (g *Geometry) Envelope() (*Geometry, error)
- func (g *Geometry) Equals(other *Geometry) (bool, error)
- func (g *Geometry) EqualsExact(other *Geometry, tolerance float64) (bool, error)
- func (g *Geometry) Geometry(n int) (*Geometry, error)
- func (g *Geometry) HasZ() (bool, error)
- func (g *Geometry) HausdorffDistance(other *Geometry) (float64, error)
- func (g *Geometry) HausdorffDistanceDensify(other *Geometry, densifyFrac float64) (float64, error)
- func (g *Geometry) Hex() ([]byte, error)
- func (g *Geometry) Holes() ([]*Geometry, error)
- func (g *Geometry) Interpolate(dist float64) (*Geometry, error)
- func (g *Geometry) Intersection(other *Geometry) (*Geometry, error)
- func (g *Geometry) Intersects(other *Geometry) (bool, error)
- func (g *Geometry) IsClosed() (bool, error)
- func (g *Geometry) IsEmpty() (bool, error)
- func (g *Geometry) IsRing() (bool, error)
- func (g *Geometry) IsSimple() (bool, error)
- func (g *Geometry) Length() (float64, error)
- func (g *Geometry) LineInterpolatePoint(dist float64) (*Geometry, error)
- func (g *Geometry) LineMerge() (*Geometry, error)
- func (g *Geometry) NCoordinate() (int, error)
- func (g *Geometry) NGeometry() (int, error)
- func (g *Geometry) NPoint() (int, error)
- func (g *Geometry) Normalize() error
- func (g *Geometry) OffsetCurve(distance float64, opts BufferOpts) (*Geometry, error)
- func (g *Geometry) Overlaps(other *Geometry) (bool, error)
- func (g *Geometry) Point(n int) (*Geometry, error)
- func (g *Geometry) PointOnSurface() (*Geometry, error)
- func (g *Geometry) Prepare() *PGeometry
- func (g *Geometry) Project(p *Geometry) float64
- func (g *Geometry) ProjectNormalized(p *Geometry) float64
- func (g *Geometry) Relate(other *Geometry) (string, error)
- func (g *Geometry) RelatePat(other *Geometry, pat string) (bool, error)
- func (g *Geometry) SRID() (int, error)
- func (g *Geometry) SetSRID(srid int)
- func (g *Geometry) SharedPaths(other *Geometry) (*Geometry, error)
- func (g *Geometry) Shell() (*Geometry, error)
- func (g *Geometry) Simplify(tolerance float64) (*Geometry, error)
- func (g *Geometry) SimplifyP(tolerance float64) (*Geometry, error)
- func (g *Geometry) Snap(other *Geometry, tolerance float64) (*Geometry, error)
- func (g *Geometry) StartPoint() (*Geometry, error)
- func (g *Geometry) String() string
- func (g *Geometry) SymDifference(other *Geometry) (*Geometry, error)
- func (g *Geometry) ToWKT() (string, error)
- func (g *Geometry) Touches(other *Geometry) (bool, error)
- func (g *Geometry) Type() (GeometryType, error)
- func (g *Geometry) UnaryUnion() (*Geometry, error)
- func (g *Geometry) Union(other *Geometry) (*Geometry, error)
- func (g *Geometry) UniquePoints() (*Geometry, error)
- func (g *Geometry) WKB() ([]byte, error)
- func (g *Geometry) Within(other *Geometry) (bool, error)
- func (g *Geometry) X() (float64, error)
- func (g *Geometry) Y() (float64, error)
- type GeometryType
- type JoinStyle
- type PGeometry
- func (p *PGeometry) Contains(other *Geometry) (bool, error)
- func (p *PGeometry) ContainsP(other *Geometry) (bool, error)
- func (p *PGeometry) CoveredBy(other *Geometry) (bool, error)
- func (p *PGeometry) Covers(other *Geometry) (bool, error)
- func (p *PGeometry) Crosses(other *Geometry) (bool, error)
- func (p *PGeometry) Disjoint(other *Geometry) (bool, error)
- func (p *PGeometry) Intersects(other *Geometry) (bool, error)
- func (p *PGeometry) Overlaps(other *Geometry) (bool, error)
- func (p *PGeometry) Touches(other *Geometry) (bool, error)
- func (p *PGeometry) Within(other *Geometry) (bool, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLineInterpolatePointDist is an error for an invalid interpolation // distance value. ErrLineInterpolatePointDist = errors.New("distance must between 0 and 1") // ErrLineInterpolatePointType is an error for an line interpolation point // performed on a non-linestring geometry. ErrLineInterpolatePointType = errors.New("geometry must be a linestring") )
Functions ¶
Types ¶
type BufferOpts ¶
type BufferOpts struct { // QuadSegs is the number of quadrant segments. QuadSegs int // CapStyle is the end cap style. CapStyle CapStyle // JoinStyle is the line segment join style. JoinStyle JoinStyle // MitreLimit is the limit in the amount of a mitred join. MitreLimit float64 }
BufferOpts are options to the BufferWithOpts method.
type CapStyle ¶
type CapStyle int
CapStyle is the style of the cap at the end of a line segment.
const ( // CapRound is a round end cap. CapRound CapStyle // CapFlat is a flat end cap. CapFlat // CapSquare is a square end cap. CapSquare )
type Coord ¶
type Coord struct {
X, Y, Z float64
}
Coord represents a coordinate in 3-dimensional space.
func MustCoords ¶
MustCoords is a helper that wraps a call to a function returning ([]Coord, error) and panics if the error is non-nil.
type Geometry ¶
type Geometry struct {
// contains filtered or unexported fields
}
Geometry represents a geometry object, which can be any one of the types of the Simple Features Specification of the Open GIS Consortium:
Point LineString LinearRing Polygon MultiPoint MultiLineString MultiPolygon GeometryCollection
func EmptyPolygon ¶
EmptyPolygon returns a new geometry of type Polygon that's empty (i.e., IsEmpty() == true).
func FromHex ¶
FromHex is a factory function that returns a new Geometry decoded from a Well-Known Binary (WKB) hex string.
func FromWKB ¶
FromWKB is a factory function that returns a new Geometry decoded from a Well-Known Binary (WKB).
func FromWKT ¶
FromWKT is a factory function that returns a new Geometry decoded from a Well-Known Text (WKT) string.
func Must ¶
Must is a helper that wraps a call to a function returning (*Geometry, error) and panics if the error is non-nil.
func NewCollection ¶
func NewCollection(_type GeometryType, geoms ...*Geometry) (*Geometry, error)
NewCollection returns a new geometry that is a collection containing multiple geometries given as variadic arguments. The type of the collection (in the SFS sense of type -- MultiPoint, MultiLineString, etc.) is determined by the first argument. If no geometries are given, the geometry is an empty version of the given collection type.
func NewLineString ¶
NewLineString returns a new geometry of type LineString, initialized with the given coordinates. If no coordinates are given, it's an empty geometry (IsEmpty() == true).
func NewLinearRing ¶
NewLinearRing returns a new geometry of type LinearRing, initialized with the given coordinates. The number of coordinates must either be zero (none given), in which case it's an empty geometry (IsEmpty() == true), or >= 4.
func NewPoint ¶
NewPoint returns a new geometry of type Point, initialized with the given coordinate(s). If no coordinates are given, it's an empty geometry (i.e., IsEmpty() == true). It's an error if more than one coordinate is given.
func NewPolygon ¶
NewPolygon returns a new geometry of type Polygon, initialized with the given shell (exterior ring) and slice of holes (interior rings). The shell and holes slice are themselves slices of coordinates. A shell is required, and a variadic number of holes (therefore are optional).
To create a new polygon from existing linear ring Geometry objects, use PolygonFromGeom.
func PolygonFromGeom ¶
PolygonFromGeom returns a new geometry of type Polygon, initialized with the given shell (exterior ring) and slice of holes (interior rings). The shell and slice of holes are geometry objects, and expected to be LinearRings.
func (*Geometry) Area ¶
Area returns the area of the geometry, which must be a areal geometry like a polygon or multipolygon.
func (*Geometry) Buffer ¶
Buffer computes a new geometry as the dilation (position amount) or erosion (negative amount) of the geometry -- a sum or difference, respectively, of the geometry with a circle of radius of the absolute value of the buffer amount.
func (*Geometry) BufferWithOpts ¶
func (g *Geometry) BufferWithOpts(width float64, opts BufferOpts) (*Geometry, error)
BufferWithOpts computes a new geometry as the dilation (position amount) or erosion (negative amount) of the geometry -- a sum or difference, respectively, of the geometry with a circle of radius of the absolute value of the buffer amount.
BufferWithOpts gives the user more control than Buffer over the parameters of the buffering, including:
- # of quadrant segments (defaults to 8 in Buffer)
- mitre limit (defaults to 5.0 in Buffer)
- end cap style (see CapStyle consts)
- join style (see JoinStyle consts)
func (*Geometry) Contains ¶
Contains returns true if every point of the other is a point of this geometry, and the interiors of the two geometries have at least one point in common.
func (*Geometry) ConvexHull ¶
ConvexHull computes the smallest convex geometry that contains all the points of the geometry.
func (*Geometry) CoordDimension ¶
CoordDimension returns the number of dimensions of the coordinates of the geometry (2 or 3).
func (*Geometry) Coords ¶
Coords returns a slice of Coord, a sequence of coordinates underlying the point, linestring, or linear ring.
func (*Geometry) CoveredBy ¶
CoveredBy returns true if every point of this geometry is a point of the other geometry.
func (*Geometry) Covers ¶
Covers returns true if every point of the other geometry is a point of this geometry.
func (*Geometry) Crosses ¶
Crosses returns true if the two geometries have some but not all interior points in common.
func (*Geometry) Difference ¶
Difference returns a new geometry representing the points making up this geometry that do not make up the other.
func (*Geometry) Dimension ¶
Dimension returns the number of dimensions geometry, eg., 1 for point, 2 for linestring.
func (*Geometry) EndPoint ¶
EndPoint returns the (n-1)th point of the geometry. Geometry must be LineString.
func (*Geometry) Equals ¶
Equals returns true if the two geometries have at least one point in common, and no point of either geometry lies in the exterior of the other geometry.
func (*Geometry) EqualsExact ¶
EqualsExact returns true if both geometries are Equal, as evaluated by their points being within the given tolerance.
func (*Geometry) Geometry ¶
Geometry returns the nth sub-geometry of the geometry (eg., of a collection).
func (*Geometry) HausdorffDistance ¶
HausdorffDistance computes the maximum distance of the geometry to the nearest point in the other geometry (i.e., considers the whole shape and position of the geometries).
func (*Geometry) HausdorffDistanceDensify ¶
HausdorffDistanceDensify computes the Hausdorff distance (see HausdorffDistance) with an additional densification fraction amount.
func (*Geometry) Hex ¶
Hex returns the geometry as a Well-Known Binary (WKB) hex-encoded byte slice.
func (*Geometry) Holes ¶
Holes returns a slice of geometries (LinearRings) representing the interior rings of a polygon (possibly nil). Geometry must be a Polygon.
func (*Geometry) Interpolate ¶
Interpolate returns the closest point to given distance within geometry. This geometry must be a LineString.
func (*Geometry) Intersection ¶
Intersection returns a new geometry representing the points shared by this geometry and the other.
func (*Geometry) Intersects ¶
Intersects returns true if the two geometries have at least one point in common.
func (*Geometry) IsClosed ¶
IsClosed returns true if the geometry is closed (i.e., start & end points equal).
func (*Geometry) IsEmpty ¶
IsEmpty returns true if the set of points of this geometry is empty (i.e., the empty geometry).
func (*Geometry) IsSimple ¶
IsSimple returns true iff the only self-intersections are at boundary points.
func (*Geometry) Length ¶
Length returns the length of the geometry, which must be a lineal geometry like a linestring or linear ring.
func (*Geometry) LineInterpolatePoint ¶
LineInterpolatePoint interpolates a point along a line.
Example ¶
package main import ( "fmt" "github.com/paulsmith/gogeos/geos" ) func main() { line := geos.Must(geos.FromWKT("LINESTRING(25 50, 100 125, 150 190)")) pt := geos.Must(line.LineInterpolatePoint(0.20)) fmt.Println(pt) }
Output: POINT (51.5974135047432014 76.5974135047432014)
func (*Geometry) LineMerge ¶
LineMerge will merge together a collection of LineStrings where they touch only at their start and end points. The LineStrings must be fully noded. The resulting geometry is a new collection.
func (*Geometry) NCoordinate ¶
NCoordinate returns the number of coordinates of the geometry.
func (*Geometry) NGeometry ¶
NGeometry returns the number of component geometries (eg., for a collection).
func (*Geometry) Normalize ¶
Normalize computes the normal form of the geometry. Modifies geometry in-place, clone first if this is not wanted/safe.
func (*Geometry) OffsetCurve ¶
func (g *Geometry) OffsetCurve(distance float64, opts BufferOpts) (*Geometry, error)
OffsetCurve computes a new linestring that is offset from the input linestring by the given distance and buffer options. A negative distance is offset on the right side; positive distance offset on the left side.
func (*Geometry) Overlaps ¶
Overlaps returns true if the geometries have some but not all points in common, they have the same dimension, and the intersection of the interiors of the two geometries has the same dimension as the geometries themselves.
func (*Geometry) PointOnSurface ¶
PointOnSurface computes a point geometry guaranteed to be on the surface of the geometry.
func (*Geometry) Prepare ¶
Prepare returns a new prepared geometry from the geometry -- see PGeometry
func (*Geometry) Project ¶
Project returns distance of point projected on this geometry from origin. This must be a lineal geometry.
func (*Geometry) ProjectNormalized ¶
ProjectNormalized returns distance of point projected on this geometry from origin, divided by its length. This must be a lineal geometry.
func (*Geometry) Relate ¶
Relate computes the intersection matrix (Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix) for the spatial relationship between the two geometries.
func (*Geometry) RelatePat ¶
RelatePat returns true if the DE-9IM matrix equals the intersection matrix of the two geometries.
func (*Geometry) SharedPaths ¶
SharedPaths finds paths shared between the two given lineal geometries. Returns a GeometryCollection having two elements:
- first element is a MultiLineString containing shared paths having the _same_ direction on both inputs
- second element is a MultiLineString containing shared paths having the _opposite_ direction on the two inputs
func (*Geometry) Shell ¶
Shell returns the exterior ring (a LinearRing) of the geometry. Geometry must be a Polygon.
func (*Geometry) Simplify ¶
Simplify returns a geometry simplified by amount given by tolerance. May not preserve topology -- see SimplifyP.
func (*Geometry) SimplifyP ¶
SimplifyP returns a geometry simplified by amount given by tolerance. Unlike Simplify, SimplifyP guarantees it will preserve topology.
func (*Geometry) Snap ¶
Snap returns a new geometry where the geometry is snapped to the given geometry by given tolerance.
func (*Geometry) StartPoint ¶
StartPoint returns the 0th point of the geometry. Geometry must be LineString.
func (*Geometry) String ¶
String returns a string encoding of the geometry, in Well-Known Text (WKT) format, or the empty string if there is an error creating the encoding.
func (*Geometry) SymDifference ¶
SymDifference returns a new geometry representing the set combining the points in this geometry not in the other, and the points in the other geometry and not in this.
func (*Geometry) ToWKT ¶
ToWKT returns a string encoding of the geometry, in Well-Known Text (WKT) format.
func (*Geometry) Touches ¶
Touches returns true if the two geometries have at least one point in common, but their interiors do not intersect.
func (*Geometry) Type ¶
func (g *Geometry) Type() (GeometryType, error)
Type returns the SFS type of the geometry.
func (*Geometry) UnaryUnion ¶
UnaryUnion computes the union of all the constituent geometries of the geometry.
func (*Geometry) Union ¶
Union returns a new geometry representing all points in this geometry and the other.
func (*Geometry) UniquePoints ¶
UniquePoints return all distinct vertices of input geometry as a MultiPoint.
func (*Geometry) Within ¶
Within returns true if every point of this geometry is a point of the other, and the interiors of the two geometries have at least one point in common.
type GeometryType ¶
GeometryType represents the various geometry types supported by GEOS, and correspond to OGC Simple Features geometry types.
const ( // POINT is a 0-dimensional geometric object, a single location is geometric // space. POINT GeometryType = C.GEOS_POINT // LINESTRING is a curve with linear interpolation between points. LINESTRING GeometryType = C.GEOS_LINESTRING // LINEARRING is a linestring that is both closed and simple. LINEARRING GeometryType = C.GEOS_LINEARRING // POLYGON is a planar surface with 1 exterior boundary and 0 or more // interior boundaries. POLYGON GeometryType = C.GEOS_POLYGON // MULTIPOINT is a 0-dimensional geometry collection, the elements of which // are restricted to points. MULTIPOINT GeometryType = C.GEOS_MULTIPOINT // MULTILINESTRING is a 1-dimensional geometry collection, the elements of // which are restricted to linestrings. MULTILINESTRING GeometryType = C.GEOS_MULTILINESTRING // MULTIPOLYGON is a 2-dimensional geometry collection, the elements of // which are restricted to polygons. MULTIPOLYGON GeometryType = C.GEOS_MULTIPOLYGON // GEOMETRYCOLLECTION is a geometric object that is a collection of some // number of geometric objects. GEOMETRYCOLLECTION GeometryType = C.GEOS_GEOMETRYCOLLECTION )
func (GeometryType) String ¶
func (t GeometryType) String() string
type JoinStyle ¶
type JoinStyle int
JoinStyle is the style of the joint of two line segments.
const ( // JoinRound is a round segment join style. JoinRound JoinStyle // JoinMitre is a mitred segment join style. JoinMitre // JoinBevel is a beveled segment join style. JoinBevel )
type PGeometry ¶
type PGeometry struct {
// contains filtered or unexported fields
}
PGeometry represents a "prepared geometry", a type of geometry object that is optimized for a limited set of operations.
func PrepareGeometry ¶
PrepareGeometry constructs a prepared geometry from a normal geometry object.
func (*PGeometry) Contains ¶
Contains computes whether the prepared geometry contains the other prepared geometry.
func (*PGeometry) ContainsP ¶
ContainsP computes whether the prepared geometry properly contains the other prepared geometry.
func (*PGeometry) CoveredBy ¶
CoveredBy computes whether the prepared geometry is covered by the other prepared geometry.
func (*PGeometry) Covers ¶
Covers computes whether the prepared geometry covers the other prepared geometry.
func (*PGeometry) Crosses ¶
Crosses computes whether the prepared geometry crosses the other prepared geometry.
func (*PGeometry) Disjoint ¶
Disjoint computes whether the prepared geometry is disjoint from the other prepared geometry.
func (*PGeometry) Intersects ¶
Intersects computes whether the prepared geometry intersects the other prepared geometry.
func (*PGeometry) Overlaps ¶
Overlaps computes whether the prepared geometry overlaps the other prepared geometry.