geos

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2014 License: MIT Imports: 8 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

View Source
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

func Error

func Error() error

Error gets the last error that occured in the GEOS C API as a Go error type.

func Version

func Version() string

Version returns the version of the GEOS C API in use.

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

func MustCoords(c []Coord, err error) []Coord

MustCoords is a helper that wraps a call to a function returning ([]Coord, error) and panics if the error is non-nil.

func NewCoord

func NewCoord(x, y float64) Coord

NewCoord is the constructor for a Coord object.

func (Coord) String

func (c Coord) String() string

String returns a (2d) string representation of a Coord.

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

func EmptyPolygon() (*Geometry, error)

EmptyPolygon returns a new geometry of type Polygon that's empty (i.e., IsEmpty() == true).

func FromHex

func FromHex(hex string) (*Geometry, error)

FromHex is a factory function that returns a new Geometry decoded from a Well-Known Binary (WKB) hex string.

func FromWKB

func FromWKB(wkb []byte) (*Geometry, error)

FromWKB is a factory function that returns a new Geometry decoded from a Well-Known Binary (WKB).

func FromWKT

func FromWKT(wkt string) (*Geometry, error)

FromWKT is a factory function that returns a new Geometry decoded from a Well-Known Text (WKT) string.

func Must

func Must(g *Geometry, err error) *Geometry

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

func NewLineString(coords ...Coord) (*Geometry, error)

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

func NewLinearRing(coords ...Coord) (*Geometry, error)

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

func NewPoint(coords ...Coord) (*Geometry, error)

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

func NewPolygon(shell []Coord, holes ...[]Coord) (*Geometry, error)

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

func PolygonFromGeom(shell *Geometry, holes ...*Geometry) (*Geometry, error)

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

func (g *Geometry) Area() (float64, error)

Area returns the area of the geometry, which must be a areal geometry like a polygon or multipolygon.

func (*Geometry) Boundary

func (g *Geometry) Boundary() (*Geometry, error)

Boundary is the boundary of the geometry.

func (*Geometry) Buffer

func (g *Geometry) Buffer(d float64) (*Geometry, error)

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) Centroid

func (g *Geometry) Centroid() (*Geometry, error)

Centroid is the center point of the geometry.

func (*Geometry) Clone

func (g *Geometry) Clone() (*Geometry, error)

Clone performs a deep copy on the geometry.

func (*Geometry) Contains

func (g *Geometry) Contains(other *Geometry) (bool, error)

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

func (g *Geometry) ConvexHull() (*Geometry, error)

ConvexHull computes the smallest convex geometry that contains all the points of the geometry.

func (*Geometry) CoordDimension

func (g *Geometry) CoordDimension() int

CoordDimension returns the number of dimensions of the coordinates of the geometry (2 or 3).

func (*Geometry) Coords

func (g *Geometry) Coords() ([]Coord, error)

Coords returns a slice of Coord, a sequence of coordinates underlying the point, linestring, or linear ring.

func (*Geometry) CoveredBy

func (g *Geometry) CoveredBy(other *Geometry) (bool, error)

CoveredBy returns true if every point of this geometry is a point of the other geometry.

func (*Geometry) Covers

func (g *Geometry) Covers(other *Geometry) (bool, error)

Covers returns true if every point of the other geometry is a point of this geometry.

func (*Geometry) Crosses

func (g *Geometry) Crosses(other *Geometry) (bool, error)

Crosses returns true if the two geometries have some but not all interior points in common.

func (*Geometry) Difference

func (g *Geometry) Difference(other *Geometry) (*Geometry, error)

Difference returns a new geometry representing the points making up this geometry that do not make up the other.

func (*Geometry) Dimension

func (g *Geometry) Dimension() int

Dimension returns the number of dimensions geometry, eg., 1 for point, 2 for linestring.

func (*Geometry) Disjoint

func (g *Geometry) Disjoint(other *Geometry) (bool, error)

Disjoint returns true if the two geometries have no point in common.

func (*Geometry) Distance

func (g *Geometry) Distance(other *Geometry) (float64, error)

Distance returns the Cartesian distance between the two geometries.

func (*Geometry) EndPoint

func (g *Geometry) EndPoint() (*Geometry, error)

EndPoint returns the (n-1)th point of the geometry. Geometry must be LineString.

func (*Geometry) Envelope

func (g *Geometry) Envelope() (*Geometry, error)

Envelope is the bounding box of a geometry, as a polygon.

func (*Geometry) Equals

func (g *Geometry) Equals(other *Geometry) (bool, error)

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

func (g *Geometry) EqualsExact(other *Geometry, tolerance float64) (bool, error)

EqualsExact returns true if both geometries are Equal, as evaluated by their points being within the given tolerance.

func (*Geometry) Geometry

func (g *Geometry) Geometry(n int) (*Geometry, error)

Geometry returns the nth sub-geometry of the geometry (eg., of a collection).

func (*Geometry) HasZ

func (g *Geometry) HasZ() (bool, error)

HasZ returns true if the geometry is 3D.

func (*Geometry) HausdorffDistance

func (g *Geometry) HausdorffDistance(other *Geometry) (float64, error)

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

func (g *Geometry) HausdorffDistanceDensify(other *Geometry, densifyFrac float64) (float64, error)

HausdorffDistanceDensify computes the Hausdorff distance (see HausdorffDistance) with an additional densification fraction amount.

func (*Geometry) Hex

func (g *Geometry) Hex() ([]byte, error)

Hex returns the geometry as a Well-Known Binary (WKB) hex-encoded byte slice.

func (*Geometry) Holes

func (g *Geometry) Holes() ([]*Geometry, error)

Holes returns a slice of geometries (LinearRings) representing the interior rings of a polygon (possibly nil). Geometry must be a Polygon.

func (*Geometry) Interpolate

func (g *Geometry) Interpolate(dist float64) (*Geometry, error)

Interpolate returns the closest point to given distance within geometry. This geometry must be a LineString.

func (*Geometry) Intersection

func (g *Geometry) Intersection(other *Geometry) (*Geometry, error)

Intersection returns a new geometry representing the points shared by this geometry and the other.

func (*Geometry) Intersects

func (g *Geometry) Intersects(other *Geometry) (bool, error)

Intersects returns true if the two geometries have at least one point in common.

func (*Geometry) IsClosed

func (g *Geometry) IsClosed() (bool, error)

IsClosed returns true if the geometry is closed (i.e., start & end points equal).

func (*Geometry) IsEmpty

func (g *Geometry) IsEmpty() (bool, error)

IsEmpty returns true if the set of points of this geometry is empty (i.e., the empty geometry).

func (*Geometry) IsRing

func (g *Geometry) IsRing() (bool, error)

IsRing returns true if the lineal geometry has the ring property.

func (*Geometry) IsSimple

func (g *Geometry) IsSimple() (bool, error)

IsSimple returns true iff the only self-intersections are at boundary points.

func (*Geometry) Length

func (g *Geometry) Length() (float64, error)

Length returns the length of the geometry, which must be a lineal geometry like a linestring or linear ring.

func (*Geometry) LineInterpolatePoint

func (g *Geometry) LineInterpolatePoint(dist float64) (*Geometry, error)

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

func (g *Geometry) LineMerge() (*Geometry, error)

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

func (g *Geometry) NCoordinate() (int, error)

NCoordinate returns the number of coordinates of the geometry.

func (*Geometry) NGeometry

func (g *Geometry) NGeometry() (int, error)

NGeometry returns the number of component geometries (eg., for a collection).

func (*Geometry) NPoint

func (g *Geometry) NPoint() (int, error)

NPoint returns the number of points in the geometry.

func (*Geometry) Normalize

func (g *Geometry) Normalize() error

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

func (g *Geometry) Overlaps(other *Geometry) (bool, error)

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) Point

func (g *Geometry) Point(n int) (*Geometry, error)

Point returns the nth point of the geometry. Geometry must be LineString.

func (*Geometry) PointOnSurface

func (g *Geometry) PointOnSurface() (*Geometry, error)

PointOnSurface computes a point geometry guaranteed to be on the surface of the geometry.

func (*Geometry) Prepare

func (g *Geometry) Prepare() *PGeometry

Prepare returns a new prepared geometry from the geometry -- see PGeometry

func (*Geometry) Project

func (g *Geometry) Project(p *Geometry) float64

Project returns distance of point projected on this geometry from origin. This must be a lineal geometry.

func (*Geometry) ProjectNormalized

func (g *Geometry) ProjectNormalized(p *Geometry) float64

ProjectNormalized returns distance of point projected on this geometry from origin, divided by its length. This must be a lineal geometry.

func (*Geometry) Relate

func (g *Geometry) Relate(other *Geometry) (string, error)

Relate computes the intersection matrix (Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix) for the spatial relationship between the two geometries.

func (*Geometry) RelatePat

func (g *Geometry) RelatePat(other *Geometry, pat string) (bool, error)

RelatePat returns true if the DE-9IM matrix equals the intersection matrix of the two geometries.

func (*Geometry) SRID

func (g *Geometry) SRID() (int, error)

SRID returns the geometry's SRID, if set.

func (*Geometry) SetSRID

func (g *Geometry) SetSRID(srid int)

SetSRID sets the geometry's SRID.

func (*Geometry) SharedPaths

func (g *Geometry) SharedPaths(other *Geometry) (*Geometry, error)

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

func (g *Geometry) Shell() (*Geometry, error)

Shell returns the exterior ring (a LinearRing) of the geometry. Geometry must be a Polygon.

func (*Geometry) Simplify

func (g *Geometry) Simplify(tolerance float64) (*Geometry, error)

Simplify returns a geometry simplified by amount given by tolerance. May not preserve topology -- see SimplifyP.

func (*Geometry) SimplifyP

func (g *Geometry) SimplifyP(tolerance float64) (*Geometry, error)

SimplifyP returns a geometry simplified by amount given by tolerance. Unlike Simplify, SimplifyP guarantees it will preserve topology.

func (*Geometry) Snap

func (g *Geometry) Snap(other *Geometry, tolerance float64) (*Geometry, error)

Snap returns a new geometry where the geometry is snapped to the given geometry by given tolerance.

func (*Geometry) StartPoint

func (g *Geometry) StartPoint() (*Geometry, error)

StartPoint returns the 0th point of the geometry. Geometry must be LineString.

func (*Geometry) String

func (g *Geometry) String() 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

func (g *Geometry) SymDifference(other *Geometry) (*Geometry, error)

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

func (g *Geometry) ToWKT() (string, error)

ToWKT returns a string encoding of the geometry, in Well-Known Text (WKT) format.

func (*Geometry) Touches

func (g *Geometry) Touches(other *Geometry) (bool, error)

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

func (g *Geometry) UnaryUnion() (*Geometry, error)

UnaryUnion computes the union of all the constituent geometries of the geometry.

func (*Geometry) Union

func (g *Geometry) Union(other *Geometry) (*Geometry, error)

Union returns a new geometry representing all points in this geometry and the other.

func (*Geometry) UniquePoints

func (g *Geometry) UniquePoints() (*Geometry, error)

UniquePoints return all distinct vertices of input geometry as a MultiPoint.

func (*Geometry) WKB

func (g *Geometry) WKB() ([]byte, error)

WKB returns the geoemtry encoded as a Well-Known Binary (WKB).

func (*Geometry) Within

func (g *Geometry) Within(other *Geometry) (bool, error)

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.

func (*Geometry) X

func (g *Geometry) X() (float64, error)

X returns the x ordinate of the geometry. Geometry must be a Point.

func (*Geometry) Y

func (g *Geometry) Y() (float64, error)

Y returns the y ordinate of the geometry. Geometry must be a Point

type GeometryType

type GeometryType C.int

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

func PrepareGeometry(g *Geometry) *PGeometry

PrepareGeometry constructs a prepared geometry from a normal geometry object.

func (*PGeometry) Contains

func (p *PGeometry) Contains(other *Geometry) (bool, error)

Contains computes whether the prepared geometry contains the other prepared geometry.

func (*PGeometry) ContainsP

func (p *PGeometry) ContainsP(other *Geometry) (bool, error)

ContainsP computes whether the prepared geometry properly contains the other prepared geometry.

func (*PGeometry) CoveredBy

func (p *PGeometry) CoveredBy(other *Geometry) (bool, error)

CoveredBy computes whether the prepared geometry is covered by the other prepared geometry.

func (*PGeometry) Covers

func (p *PGeometry) Covers(other *Geometry) (bool, error)

Covers computes whether the prepared geometry covers the other prepared geometry.

func (*PGeometry) Crosses

func (p *PGeometry) Crosses(other *Geometry) (bool, error)

Crosses computes whether the prepared geometry crosses the other prepared geometry.

func (*PGeometry) Disjoint

func (p *PGeometry) Disjoint(other *Geometry) (bool, error)

Disjoint computes whether the prepared geometry is disjoint from the other prepared geometry.

func (*PGeometry) Intersects

func (p *PGeometry) Intersects(other *Geometry) (bool, error)

Intersects computes whether the prepared geometry intersects the other prepared geometry.

func (*PGeometry) Overlaps

func (p *PGeometry) Overlaps(other *Geometry) (bool, error)

Overlaps computes whether the prepared geometry overlaps the other prepared geometry.

func (*PGeometry) Touches

func (p *PGeometry) Touches(other *Geometry) (bool, error)

Touches computes whether the prepared geometry touches the other prepared geometry.

func (*PGeometry) Within

func (p *PGeometry) Within(other *Geometry) (bool, error)

Within computes whether the prepared geometry is within the other prepared geometry.

Jump to

Keyboard shortcuts

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