geospatial

package
v0.0.0-...-4d2a565 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 7 Imported by: 0

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

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

func (c Coordinate) String() string

Formats the coordinate as a string

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 (p Polygon) MarshalJSON() ([]byte, error)

func (Polygon) String

func (p Polygon) String() string

Formats the coordinate array so that is marshals into valid JSON

func (*Polygon) UnmarshalJSON

func (p *Polygon) UnmarshalJSON(data []byte) error

func (Polygon) Validate

func (p Polygon) Validate() error

Implements the RFC 7946 specifications for a geospatial Polygon [See: 3.1.6 Polygon](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6)

type RighthandRuleError

type RighthandRuleError struct {
	Angle float64
}

func (*RighthandRuleError) Error

func (e *RighthandRuleError) Error() string

type State

type State struct {
	Name   string  `json:"state"`
	Border Polygon `json:"border"`
}

Represents a geographic state as a name and a geospatial polygon (i.e. a linear ring of boundary coordinates)

func NewState

func NewState(name string, coords []Coordinate) (state State, err error)

Constructor generates a new State object with the provided name and array of coordinates. Translates the coordinates into a [Polyon] object which ensures the state's border is representable as valid GeoJSON

func (State) Contains

func (s State) Contains(coordinate Coordinate) bool

Calls the Contains method for the Polygon object representing the state's border

Jump to

Keyboard shortcuts

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