geom

package module
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: BSD-2-Clause Imports: 5 Imported by: 47

Documentation

Overview

Package geom holds geometry objects and functions to operate on them. They can be encoded and decoded by other packages in this repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	Min, Max Point
}

Bounds holds the spatial extent of a geometry.

func NewBounds

func NewBounds() *Bounds

NewBounds initializes a new bounds object.

func NewBoundsPoint

func NewBoundsPoint(point Point) *Bounds

NewBoundsPoint creates a bounds object from a point.

func (*Bounds) Area added in v0.2.0

func (b *Bounds) Area() float64

Area returns the area of the reciever.

func (*Bounds) Bounds

func (b *Bounds) Bounds() *Bounds

Bounds returns b

func (*Bounds) Centroid added in v0.2.0

func (b *Bounds) Centroid() Point

func (*Bounds) Copy

func (b *Bounds) Copy() *Bounds

Copy returns a copy of b.

func (*Bounds) Difference added in v0.2.0

func (b *Bounds) Difference(p Polygonal) Polygonal

Difference subtracts p from b.

func (*Bounds) Empty

func (b *Bounds) Empty() bool

Empty returns true if b does not contain any points.

func (*Bounds) Extend

func (b *Bounds) Extend(b2 *Bounds)

Extend increases the extent of b1 to include b2.

func (*Bounds) Intersection added in v0.2.0

func (b *Bounds) Intersection(p Polygonal) Polygonal

Intersection returns the Intersection of the receiver with p.

func (*Bounds) Len

func (b *Bounds) Len() int

Len returns the number of points in the receiver (always==5).

func (*Bounds) Overlaps

func (b *Bounds) Overlaps(b2 *Bounds) bool

Overlaps returns whether b and b2 overlap.

func (*Bounds) Points

func (b *Bounds) Points() func() Point

Points returns an iterator for the corners of the receiver.

func (*Bounds) Polygons added in v0.2.0

func (b *Bounds) Polygons() []Polygon

Polygons returns a rectangle polygon to fulfill the Polygonal interface.

func (*Bounds) Similar

func (b *Bounds) Similar(g Geom, tolerance float64) bool

Similar determines whether two bounds are similar within tolerance.

func (*Bounds) Simplify added in v0.2.0

func (b *Bounds) Simplify(tolerance float64) Geom

Simplify returns the receiver to fulfill the Polygonal interface.

func (*Bounds) Transform

func (b *Bounds) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of b according to t. If t is not nil, this function returns a Polygon instead of a *Bounds because the transformed polygon may not match the transformed bounding rectangle.

func (*Bounds) Union added in v0.2.0

func (b *Bounds) Union(p Polygonal) Polygonal

Union returns the combination of the receiver and p.

func (*Bounds) Within

func (b *Bounds) Within(poly Polygonal) WithinStatus

Within calculates whether b is within poly.

func (*Bounds) XOr added in v0.2.0

func (b *Bounds) XOr(p Polygonal) Polygonal

XOr returns the area(s) occupied by either the receiver or p but not both.

type Geom

type Geom interface {
	Bounds() *Bounds
	Similar(Geom, float64) bool
	Transform(proj.Transformer) (Geom, error)

	// Len returns the total number of points in the geometry
	Len() int

	// Points returns an iterator that returns the points in the
	// geometry.
	Points() func() Point
}

Geom is an interface for generic geometry types.

type GeometryCollection

type GeometryCollection []Geom

GeometryCollection is a holder for multiple related geometry objects of arbitrary type.

func (GeometryCollection) Bounds

func (gc GeometryCollection) Bounds() *Bounds

Bounds gives the rectangular extents of the GeometryCollection.

func (GeometryCollection) Len

func (gc GeometryCollection) Len() int

Len returns the number of points in the receiver.

func (GeometryCollection) Points

func (gc GeometryCollection) Points() func() Point

Points returns an iterator for the points in the receiver.

func (GeometryCollection) Similar

func (gc GeometryCollection) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries collections are similar within tolerance. If gc and g have the same geometries but in a different order, it will return true.

func (GeometryCollection) Transform

func (gc GeometryCollection) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of gc according to t.

type LineString

type LineString Path

LineString is a number of points that make up a path or line.

func (LineString) Bounds

func (l LineString) Bounds() *Bounds

Bounds gives the rectangular extents of the LineString.

func (LineString) Clip

func (l LineString) Clip(p Polygonal) Linear

Clip returns the part of the receiver that falls within the given polygon.

func (LineString) Distance

func (l LineString) Distance(p Point) float64

Distance calculates the shortest distance from p to the LineString.

func (LineString) Len

func (l LineString) Len() int

Len returns the number of points in the receiver.

func (LineString) Length

func (l LineString) Length() float64

Length calculates the length of l.

func (LineString) Points

func (l LineString) Points() func() Point

Points returns an iterator for the points in the receiver.

func (LineString) Similar

func (l LineString) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries are similar within tolerance. If two lines contain the same points but in different directions it will return false.

func (LineString) Simplify

func (l LineString) Simplify(tolerance float64) Geom

Simplify simplifies l by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting).

It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).

func (LineString) Transform

func (l LineString) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of l according to t.

func (LineString) Within

func (l LineString) Within(p Polygonal) WithinStatus

Within calculates whether l is completely within p or touching its edge.

type Linear

type Linear interface {
	Geom
	Length() float64

	// Clip returns the part of the line that falls within the given polygon.
	Clip(Polygonal) Linear

	Simplify(tolerance float64) Geom

	// Within determines whether this geometry is within the Polygonal geometry.
	// Points that lie on the edge of the polygon are considered within.
	Within(Polygonal) WithinStatus

	// Distance calculates the shortest distance to the given Point.
	Distance(Point) float64
}

Linear is an interface for types that are linear in nature.

type MultiLineString

type MultiLineString []LineString

MultiLineString is a holder for multiple related LineStrings.

func (MultiLineString) Bounds

func (ml MultiLineString) Bounds() *Bounds

Bounds gives the rectangular extents of the MultiLineString.

func (MultiLineString) Clip

func (ml MultiLineString) Clip(p Polygonal) Linear

Clip returns the part of the receiver that falls within the given polygon.

func (MultiLineString) Distance

func (ml MultiLineString) Distance(p Point) float64

Distance calculates the shortest distance from p to the MultiLineString.

func (MultiLineString) Len

func (ml MultiLineString) Len() int

Len returns the number of points in the receiver.

func (MultiLineString) Length

func (ml MultiLineString) Length() float64

Length calculates the combined length of the linestrings in ml.

func (MultiLineString) Points

func (ml MultiLineString) Points() func() Point

Points returns an iterator for the points in the receiver.

func (MultiLineString) Similar

func (ml MultiLineString) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries are similar within tolerance. If ml and g have the similar linestrings but in a different order, it will return true.

func (MultiLineString) Simplify

func (ml MultiLineString) Simplify(tolerance float64) Geom

Simplify simplifies ml by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting).

It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).

func (MultiLineString) Transform

func (ml MultiLineString) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of ml according to t.

func (MultiLineString) Within

func (ml MultiLineString) Within(p Polygonal) WithinStatus

Within calculates whether ml is completely within p or on its edge.

type MultiPoint

type MultiPoint []Point

MultiPoint is a holder for multiple related points.

func (MultiPoint) Bounds

func (mp MultiPoint) Bounds() *Bounds

Bounds gives the rectangular extents of the MultiPoint.

func (MultiPoint) Len

func (mp MultiPoint) Len() int

Len returns the number of points in the receiver.

func (MultiPoint) Points

func (mp MultiPoint) Points() func() Point

Points returns an iterator for the points in the receiver.

func (MultiPoint) Similar

func (mp MultiPoint) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries are similar within tolerance.

func (MultiPoint) Transform

func (mp MultiPoint) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of mp according to t.

func (MultiPoint) Within

func (mp MultiPoint) Within(poly Polygonal) WithinStatus

Within calculates whether all of the points in mp are within poly or touching its edge.

type MultiPolygon

type MultiPolygon []Polygon

MultiPolygon is a holder for multiple related polygons.

func (MultiPolygon) Area

func (mp MultiPolygon) Area() float64

Area returns the combined area of the polygons in p. The function works correctly for polygons with holes, regardless of the winding order of the holes, but may give the wrong result for self-intersecting polygons, or polygons in mp that overlap each other.

func (MultiPolygon) Bounds

func (mp MultiPolygon) Bounds() *Bounds

Bounds gives the rectangular extents of the MultiPolygon.

func (MultiPolygon) Centroid

func (mp MultiPolygon) Centroid() Point

Centroid calculates the centroid of mp, from wikipedia: http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon. The polygon can have holes, but each ring must be closed (i.e., p[0] == p[n-1], where the ring has n points) and must not be self-intersecting. The algorithm will not check to make sure the holes are actually inside the outer rings.

func (MultiPolygon) Difference

func (mp MultiPolygon) Difference(p2 Polygonal) Polygonal

Difference subtracts p2 from mp.

func (MultiPolygon) Intersection

func (mp MultiPolygon) Intersection(p2 Polygonal) Polygonal

Intersection returns the area(s) shared by mp and p2.

func (MultiPolygon) Len

func (mp MultiPolygon) Len() int

Len returns the number of points in the receiver.

func (MultiPolygon) Points

func (mp MultiPolygon) Points() func() Point

Points returns an iterator for the points in the receiver.

func (MultiPolygon) Polygons

func (mp MultiPolygon) Polygons() []Polygon

Polygons returns the polygons that make up mp.

func (MultiPolygon) Similar

func (mp MultiPolygon) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries are similar within tolerance. If ml and g have the similar polygons but in a different order, it will return true.

func (MultiPolygon) Simplify

func (mp MultiPolygon) Simplify(tolerance float64) Geom

Simplify simplifies mp by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting). Self-intersecting polygons may cause the algorithm to fall into an infinite loop.

It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).

func (MultiPolygon) Transform

func (mp MultiPolygon) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of mp according to t.

func (MultiPolygon) Union

func (mp MultiPolygon) Union(p2 Polygonal) Polygonal

Union returns the combination of mp and p2.

func (MultiPolygon) XOr

func (mp MultiPolygon) XOr(p2 Polygonal) Polygonal

XOr returns the area(s) occupied by either mp or p2 but not both.

type Path

type Path []Point

A Path is a series of connected points.

func (Path) Len

func (p Path) Len() int

Len returns the number of Points in the receiver.

func (Path) XY

func (p Path) XY(i int) (x, y float64)

XY returns the coordinates of point i.

type Point

type Point struct {
	X, Y float64
}

Point is a holder for 2D coordinates X and Y.

func NewPoint

func NewPoint(x, y float64) *Point

NewPoint returns a new point with coordinates x and y.

func (Point) Bounds

func (p Point) Bounds() *Bounds

Bounds gives the rectangular extents of the Point.

func (Point) Buffer

func (p Point) Buffer(radius float64, segments int) Polygon

Buffer returns a circle with the specified radius centered at the receiver location. The circle is represented as a polygon with the specified number of segments.

func (Point) Equals

func (p Point) Equals(p2 Point) bool

Equals returns whether p is equal to p2.

func (Point) Len

func (p Point) Len() int

Len returns the number of points in the receiver (always==1).

func (Point) Points

func (p Point) Points() func() Point

Points returns an iterator for the points in the receiver (there will only be one point).

func (Point) Similar

func (p Point) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries are similar within tolerance.

func (Point) Transform

func (p Point) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of p according to t.

func (Point) Within

func (p Point) Within(poly Polygonal) WithinStatus

Within calculates whether p is within poly.

type PointLike

type PointLike interface {
	Geom

	// Within determines whether this geometry is within the Polygonal geometry.
	Within(Polygonal) WithinStatus
}

PointLike is an interface for types that are pointlike in nature.

type Polygon

type Polygon []Path

A Polygon is a series of closed rings. The inner rings should be nested inside of the outer ring.

func (Polygon) Area

func (p Polygon) Area() float64

Area returns the area of p. The function works correctly for polygons with holes, regardless of the winding order of the holes, but will give the wrong result for self-intersecting polygons.

func (Polygon) Bounds

func (p Polygon) Bounds() *Bounds

Bounds gives the rectangular extents of the polygon.

func (Polygon) Centroid

func (p Polygon) Centroid() Point

Centroid calculates the centroid of p, from wikipedia: http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon. The polygon can have holes, but each ring must be closed (i.e., p[0] == p[n-1], where the ring has n points) and must not be self-intersecting. The algorithm will not check to make sure the holes are actually inside the outer rings. This has not been thoroughly tested.

func (Polygon) Difference

func (p Polygon) Difference(p2 Polygonal) Polygonal

Difference subtracts p2 from p.

func (Polygon) Intersection

func (p Polygon) Intersection(p2 Polygonal) Polygonal

Intersection returns the area(s) shared by p and p2.

func (Polygon) Len

func (p Polygon) Len() int

Len returns the number of points in the receiver.

func (Polygon) Points

func (p Polygon) Points() func() Point

Points returns an iterator for the points in the receiver.

func (Polygon) Polygons

func (p Polygon) Polygons() []Polygon

Polygons returns []{p} to fulfill the Polygonal interface.

func (Polygon) Similar

func (p Polygon) Similar(g Geom, tolerance float64) bool

Similar determines whether two geometries are similar within tolerance. If p and g have the same points with the same winding direction, but a different starting point, it will return true. If they have the same rings but in a different order, it will return true. If the rings have the same points but different winding directions, it will return false.

func (Polygon) Simplify

func (p Polygon) Simplify(tolerance float64) Geom

Simplify simplifies p by removing points according to the tolerance parameter, while ensuring that the resulting shape is not self intersecting (but only if the input shape is not self intersecting). Self-intersecting polygons may cause the algorithm to fall into an infinite loop.

It is based on the algorithm: J. L. G. Pallero, Robust line simplification on the plane. Comput. Geosci. 61, 152–159 (2013).

func (Polygon) Transform

func (p Polygon) Transform(t proj.Transformer) (Geom, error)

Transform shifts the coordinates of p according to t.

func (Polygon) Union

func (p Polygon) Union(p2 Polygonal) Polygonal

Union returns the combination of p and p2.

func (Polygon) Within added in v0.2.9

func (p Polygon) Within(poly Polygonal) WithinStatus

Within calculates whether p is within poly.

func (Polygon) XOr

func (p Polygon) XOr(p2 Polygonal) Polygonal

XOr returns the area(s) occupied by either p or p2 but not both.

type Polygonal

type Polygonal interface {
	Geom
	Polygons() []Polygon
	Intersection(Polygonal) Polygonal
	Union(Polygonal) Polygonal
	XOr(Polygonal) Polygonal
	Difference(Polygonal) Polygonal
	Area() float64
	Simplify(tolerance float64) Geom
	Centroid() Point
}

Polygonal is an interface for types that are polygonal in nature.

type Simplifier

type Simplifier interface {
	Simplify(tolerance float64) Geom
}

Simplifier is an interface for types that can be simplified.

type WithinStatus

type WithinStatus int

WithinStatus gives the status of a point relative to a polygon: whether it is inside, outside, or on the edge.

const (
	Outside WithinStatus = iota
	Inside
	OnEdge
)

WithinStatus gives the status of a point relative to a polygon: whether it is inside, outside, or on the edge.

type Withiner added in v0.2.9

type Withiner interface {
	Within(Polygonal) WithinStatus
}

Withiner is an interface for types that can be determined to be within a polygon or not.

Directories

Path Synopsis
Package carto is a Go language map drawing library
Package carto is a Go language map drawing library
encoding
hex
osm
Package osm extracts and manipulates OpenStreetMap (OSM) data.
Package osm extracts and manipulates OpenStreetMap (OSM) data.
shp
Package shp decodes and encodes shapefiles to and from geometry objects.
Package shp decodes and encodes shapefiles to and from geometry objects.
wkb
wkt
index
rtree
A library for efficiently storing and querying spatial data.
A library for efficiently storing and querying spatial data.
Package op provides implementation of algorithms for geometry operations.
Package op provides implementation of algorithms for geometry operations.
Package route finds the shortest route between two points along a geometrical network (e.g., a road network).
Package route finds the shortest route between two points along a geometrical network (e.g., a road network).

Jump to

Keyboard shortcuts

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