Documentation ¶
Overview ¶
Package geospatial implements objects and functions useful for representing a geographic State as a geospatial entity and performing operations on that entity such as: visualization with mapping tools and efficiently determining if a geographic coordinate is contained within the entity's borders
Index ¶
Constants ¶
const ( RingTooShort = "polygon ring too short, must contain at least 4 positions" RingUnclosed = "polygon ring must be closed, first and last positions must be equal" RingCounterClockwise = "polygon exterior ring must be clockwise" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Coordinate ¶
type Coordinate struct {
Lng, Lat float64
}
Represents a single point on a map or spherical geometry
func LatLng ¶
func LatLng(lat, lng float64) Coordinate
Creates the expected Coordinate object with ordered arguments by latitude and longitude
func (Coordinate) MarshalJSON ¶
func (c Coordinate) MarshalJSON() ([]byte, error)
func (*Coordinate) UnmarshalJSON ¶
func (c *Coordinate) UnmarshalJSON(data []byte) error
type InvalidGeometryError ¶
type InvalidGeometryError struct {
// contains filtered or unexported fields
}
func (*InvalidGeometryError) Error ¶
func (e *InvalidGeometryError) Error() string
type Polygon ¶
type Polygon []Coordinate
Provides methods for validation and analysis of the geospatial shape represented by the array of coordinates
func NewPolygon ¶
func NewPolygon(coords []Coordinate) (*Polygon, error)
Constructs a new instance of a Polygon struct with valid coordinates which satisfy the RFC 7946 GeoJSON specifications [See: 3.1.6 Polygon](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6)
func (Polygon) Contains ¶
func (p Polygon) Contains(coord Coordinate) (contains bool)
Uses the [Ray-casting algorithm] to efficiently identify if the given coordinate is contained within the geospatial polygon. In simple terms, this algorithm creates horizontal lines (rays) and counts the number of intersections with the polygon's boundaries, an odd number of intersections indicates that the coordinate lies within the boundaries of the polygon. [Ray-casting algortithm](https://rosettacode.org/wiki/Ray-casting_algorithm)
func (Polygon) MarshalJSON ¶
func (*Polygon) UnmarshalJSON ¶
type RighthandRuleError ¶
type RighthandRuleError struct {
Angle float64
}
func (*RighthandRuleError) Error ¶
func (e *RighthandRuleError) Error() string
type State ¶
Represents a geographic state as a name and a geospatial polygon (i.e. a linear ring of boundary coordinates)