geom: github.com/ctessum/geom Index | Files | Directories

package geom

import "github.com/ctessum/geom"

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

Index

Package Files

area.go bounds.go geom.go geometrycollection.go intersection.go linestring.go multilinestring.go multipoint.go multipolygon.go point.go polygon.go similar.go simplify.go transform.go within.go

type Bounds Uses

type Bounds struct {
    Min, Max Point
}

Bounds holds the spatial extent of a geometry.

func NewBounds Uses

func NewBounds() *Bounds

NewBounds initializes a new bounds object.

func NewBoundsPoint Uses

func NewBoundsPoint(point Point) *Bounds

NewBoundsPoint creates a bounds object from a point.

func (*Bounds) Area Uses

func (b *Bounds) Area() float64

Area returns the area of the reciever.

func (*Bounds) Bounds Uses

func (b *Bounds) Bounds() *Bounds

Bounds returns b

func (*Bounds) Centroid Uses

func (b *Bounds) Centroid() Point

func (*Bounds) Copy Uses

func (b *Bounds) Copy() *Bounds

Copy returns a copy of b.

func (*Bounds) Difference Uses

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

Difference subtracts p from b.

func (*Bounds) Empty Uses

func (b *Bounds) Empty() bool

Empty returns true if b does not contain any points.

func (*Bounds) Extend Uses

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

Extend increases the extent of b1 to include b2.

func (*Bounds) Intersection Uses

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

Intersection returns the Intersection of the receiver with p.

func (*Bounds) Len Uses

func (b *Bounds) Len() int

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

func (*Bounds) Overlaps Uses

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

Overlaps returns whether b and b2 overlap.

func (*Bounds) Points Uses

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

Points returns an iterator for the corners of the receiver.

func (*Bounds) Polygons Uses

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

Polygons returns a rectangle polygon to fulfill the Polygonal interface.

func (*Bounds) Similar Uses

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

Similar determines whether two bounds are similar within tolerance.

func (*Bounds) Simplify Uses

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

Simplify returns the receiver to fulfill the Polygonal interface.

func (*Bounds) Transform Uses

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

Transform shifts the coordinates of b according to t.

func (*Bounds) Union Uses

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

Union returns the combination of the receiver and p.

func (*Bounds) Within Uses

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

Within calculates whether b is within poly.

func (*Bounds) XOr Uses

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

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

type Geom Uses

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 Uses

type GeometryCollection []Geom

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

func (GeometryCollection) Bounds Uses

func (gc GeometryCollection) Bounds() *Bounds

Bounds gives the rectangular extents of the GeometryCollection.

func (GeometryCollection) Len Uses

func (gc GeometryCollection) Len() int

Len returns the number of points in the receiver.

func (GeometryCollection) Points Uses

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

Points returns an iterator for the points in the receiver.

func (GeometryCollection) Similar Uses

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 Uses

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

Transform shifts the coordinates of gc according to t.

type LineString Uses

type LineString Path

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

func (LineString) Bounds Uses

func (l LineString) Bounds() *Bounds

Bounds gives the rectangular extents of the LineString.

func (LineString) Clip Uses

func (l LineString) Clip(p Polygonal) Linear

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

func (LineString) Distance Uses

func (l LineString) Distance(p Point) float64

Distance calculates the shortest distance from p to the LineString.

func (LineString) Len Uses

func (l LineString) Len() int

Len returns the number of points in the receiver.

func (LineString) Length Uses

func (l LineString) Length() float64

Length calculates the length of l.

func (LineString) Points Uses

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

Points returns an iterator for the points in the receiver.

func (LineString) Similar Uses

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 Uses

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 Uses

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

Transform shifts the coordinates of l according to t.

func (LineString) Within Uses

func (l LineString) Within(p Polygonal) WithinStatus

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

type Linear Uses

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 Uses

type MultiLineString []LineString

MultiLineString is a holder for multiple related LineStrings.

func (MultiLineString) Bounds Uses

func (ml MultiLineString) Bounds() *Bounds

Bounds gives the rectangular extents of the MultiLineString.

func (MultiLineString) Clip Uses

func (ml MultiLineString) Clip(p Polygonal) Linear

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

func (MultiLineString) Distance Uses

func (ml MultiLineString) Distance(p Point) float64

Distance calculates the shortest distance from p to the MultiLineString.

func (MultiLineString) Len Uses

func (ml MultiLineString) Len() int

Len returns the number of points in the receiver.

func (MultiLineString) Length Uses

func (ml MultiLineString) Length() float64

Length calculates the combined length of the linestrings in ml.

func (MultiLineString) Points Uses

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

Points returns an iterator for the points in the receiver.

func (MultiLineString) Similar Uses

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 Uses

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 Uses

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

Transform shifts the coordinates of ml according to t.

func (MultiLineString) Within Uses

func (ml MultiLineString) Within(p Polygonal) WithinStatus

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

type MultiPoint Uses

type MultiPoint []Point

MultiPoint is a holder for multiple related points.

func (MultiPoint) Bounds Uses

func (mp MultiPoint) Bounds() *Bounds

Bounds gives the rectangular extents of the MultiPoint.

func (MultiPoint) Len Uses

func (mp MultiPoint) Len() int

Len returns the number of points in the receiver.

func (MultiPoint) Points Uses

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

Points returns an iterator for the points in the receiver.

func (MultiPoint) Similar Uses

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

Similar determines whether two geometries are similar within tolerance.

func (MultiPoint) Transform Uses

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

Transform shifts the coordinates of mp according to t.

func (MultiPoint) Within Uses

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 Uses

type MultiPolygon []Polygon

MultiPolygon is a holder for multiple related polygons.

func (MultiPolygon) Area Uses

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 Uses

func (mp MultiPolygon) Bounds() *Bounds

Bounds gives the rectangular extents of the MultiPolygon.

func (MultiPolygon) Centroid Uses

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 Uses

func (mp MultiPolygon) Difference(p2 Polygonal) Polygonal

Difference subtracts p2 from mp.

func (MultiPolygon) Intersection Uses

func (mp MultiPolygon) Intersection(p2 Polygonal) Polygonal

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

func (MultiPolygon) Len Uses

func (mp MultiPolygon) Len() int

Len returns the number of points in the receiver.

func (MultiPolygon) Points Uses

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

Points returns an iterator for the points in the receiver.

func (MultiPolygon) Polygons Uses

func (mp MultiPolygon) Polygons() []Polygon

Polygons returns the polygons that make up mp.

func (MultiPolygon) Similar Uses

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 Uses

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 Uses

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

Transform shifts the coordinates of mp according to t.

func (MultiPolygon) Union Uses

func (mp MultiPolygon) Union(p2 Polygonal) Polygonal

Union returns the combination of mp and p2.

func (MultiPolygon) XOr Uses

func (mp MultiPolygon) XOr(p2 Polygonal) Polygonal

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

type Path Uses

type Path []Point

A Path is a series of connected points.

func (Path) Len Uses

func (p Path) Len() int

Len returns the number of Points in the receiver.

func (Path) XY Uses

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

XY returns the coordinates of point i.

type Point Uses

type Point struct {
    X, Y float64
}

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

func NewPoint Uses

func NewPoint(x, y float64) *Point

NewPoint returns a new point with coordinates x and y.

func (Point) Bounds Uses

func (p Point) Bounds() *Bounds

Bounds gives the rectangular extents of the Point.

func (Point) Buffer Uses

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 Uses

func (p Point) Equals(p2 Point) bool

Equals returns whether p is equal to p2.

func (Point) Len Uses

func (p Point) Len() int

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

func (Point) Points Uses

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 Uses

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

Similar determines whether two geometries are similar within tolerance.

func (Point) Transform Uses

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

Transform shifts the coordinates of p according to t.

func (Point) Within Uses

func (p Point) Within(poly Polygonal) WithinStatus

Within calculates whether p is within poly.

type PointLike Uses

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 Uses

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 Uses

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 Uses

func (p Polygon) Bounds() *Bounds

Bounds gives the rectangular extents of the polygon.

func (Polygon) Centroid Uses

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 Uses

func (p Polygon) Difference(p2 Polygonal) Polygonal

Difference subtracts p2 from p.

func (Polygon) Intersection Uses

func (p Polygon) Intersection(p2 Polygonal) Polygonal

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

func (Polygon) Len Uses

func (p Polygon) Len() int

Len returns the number of points in the receiver.

func (Polygon) Points Uses

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

Points returns an iterator for the points in the receiver.

func (Polygon) Polygons Uses

func (p Polygon) Polygons() []Polygon

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

func (Polygon) Similar Uses

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 Uses

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 Uses

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

Transform shifts the coordinates of p according to t.

func (Polygon) Union Uses

func (p Polygon) Union(p2 Polygonal) Polygonal

Union returns the combination of p and p2.

func (Polygon) XOr Uses

func (p Polygon) XOr(p2 Polygonal) Polygonal

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

type Polygonal Uses

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 Uses

type Simplifier interface {
    Simplify(tolerance float64) Geom
}

Simplifier is an interface for types that can be simplified.

type WithinStatus Uses

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.

Directories

PathSynopsis
cartoPackage carto is a Go language map drawing library
encoding/geojson
encoding/hex
encoding/osmPackage osm extracts and manipulates OpenStreetMap (OSM) data.
encoding/shpPackage shp decodes and encodes shapefiles to and from geometry objects.
encoding/wkb
encoding/wkt
index/rtreeA library for efficiently storing and querying spatial data.
opPackage op provides implementation of algorithms for geometry operations.
proj
routePackage route finds the shortest route between two points along a geometrical network (e.g., a road network).
test

Package geom imports 4 packages (graph) and is imported by 25 packages. Updated 2019-10-21. Refresh now. Tools for package owners.