Documentation ¶
Overview ¶
Package geodist finds distances between two geospatial shapes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShapeDistance ¶
func ShapeDistance(c DistanceCalculator, a Shape, b Shape) (bool, error)
ShapeDistance returns the distance between two given shapes. Distance is defined by the DistanceUpdater provided by the interface. It returns whether the function above should return early.
Types ¶
type DistanceCalculator ¶
type DistanceCalculator interface { // DistanceUpdater returns the DistanceUpdater for the current set of calculations. DistanceUpdater() DistanceUpdater // NewEdgeCrosser returns a new EdgeCrosser with the given edge initialized to be // the edge to compare against, and the start point to be the start of the first // edge to compare against. NewEdgeCrosser(edge Edge, startPoint Point) EdgeCrosser // PointInLinearRing returns whether the point is inside the given linearRing. PointInLinearRing(point Point, linearRing LinearRing) bool // ClosestPointToEdge returns the closest point to the infinite line denoted by // the edge, and a bool on whether this point lies on the edge segment. ClosestPointToEdge(edge Edge, point Point) (Point, bool) // BoundingBoxIntersects returns whether the bounding boxes of the shapes in // question intersect. BoundingBoxIntersects() bool }
DistanceCalculator contains calculations which allow ShapeDistance to calculate the distance between two shapes.
type DistanceUpdater ¶
type DistanceUpdater interface { // Update updates the distance based on two provided points, // returning if the function should return early. Update(a Point, b Point) bool // OnIntersects is called when two shapes intersects. OnIntersects(p Point) bool // Distance returns the distance to return so far. Distance() float64 // IsMaxDistance returns whether the updater is looking for maximum distance. IsMaxDistance() bool // FlipGeometries is called to flip the order of geometries. FlipGeometries() }
DistanceUpdater is a provided hook that has a series of functions that allows the caller to maintain the distance value desired.
type Edge ¶
type Edge struct {
V0, V1 Point
}
Edge is a struct that represents a connection between two points.
type EdgeCrosser ¶
type EdgeCrosser interface { // ChainCrossing assumes there is an edge to compare against, and the previous // point `p0` is the start of the next edge. It will then returns whether (p0, p) // intersects with the edge and point of intersection if they intersect. // When complete, point p will become p0. // Desired usage examples: // crosser := NewEdgeCrosser(edge.V0, edge.V1, startingP0) // intersects, _ := crosser.ChainCrossing(p1) // laterIntersects, _ := crosser.ChainCrossing(p2) // intersects |= laterIntersects .... ChainCrossing(p Point) (bool, Point) }
EdgeCrosser is a provided hook that calculates whether edges intersect.
type LineString ¶
type LineString interface { Edge(i int) Edge NumEdges() int Vertex(i int) Point NumVertexes() int IsShape() IsLineString() }
LineString is an interface that represents a geospatial LineString.
type LinearRing ¶
type LinearRing interface { Edge(i int) Edge NumEdges() int Vertex(i int) Point NumVertexes() int IsShape() IsLinearRing() }
LinearRing is an interface that represents a geospatial LinearRing.
type Point ¶
Point is a union of the point types used in geometry and geography representation. The interfaces for distance calculation defined below are shared for both representations, and this union helps us avoid heap allocations by doing cheap copy-by-value of points. The code that peers inside a Point knows which of the two fields is populated.
type Polygon ¶
type Polygon interface { LinearRing(i int) LinearRing NumLinearRings() int IsShape() IsPolygon() }
Polygon is an interface that represents a geospatial Polygon.