geo

package module
v0.0.0-...-350ba7a Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2016 License: MIT Imports: 7 Imported by: 0

README

geo

Go Report Card

Simple package for converting geometrical primitives to/from GeoJSON and Well Known Text.

This package aims to be simple and high quality. If test coverage is not 100% or it does not pass gometalinter feel free to open an issue.

Documentation

Overview

Package geo provides a small set of geometrical types and operations on them. This package aims to be simple and very high quality.

Index

Constants

View Source
const (
	CircleType            = "Circle"
	FeatureCollectionType = "FeatureCollection"
	FeatureType           = "Feature"
	LineType              = "LineString"
	PointType             = "Point"
	PolygonType           = "Polygon"
)

Geometry types.

Variables

View Source
var (
	// CircleContainsMethod provides a way to control
	// which algorithm is used to calculate if a point is
	// inside a circle.
	CircleContainsMethod = "equirectangular"
)

Functions

This section is empty.

Types

type Circle

type Circle struct {
	Coordinates Point   `json:"coordinates"`
	Radius      float64 `json:"radius"`
}

Circle is a circle in the XY plane.

func (Circle) Compare

func (c Circle) Compare(g Geometry) bool

Compare compares the circle to another geometry.

func (Circle) Contains

func (c Circle) Contains(p Point) bool

Contains determines if the circle contains the point. This assumes radius is specified in feet. This method uses the package variable

CircleContainsMethod

to choose a way to calculate if the point is in the circle. See http://www.movable-type.co.uk/scripts/latlong.html for more info. If CircleContainsMethod is not set to one of

  • "haversine"
  • "equirectangular"
  • "slc"

then this method panics.

func (Circle) ContainsEquirectangular

func (c Circle) ContainsEquirectangular(p Point) bool

ContainsEquirectangular uses equirectangular projection to determine if the point is contained in the circle.

func (Circle) ContainsHaversine

func (c Circle) ContainsHaversine(p Point) bool

ContainsHaversine uses the haversine formula to determine if the point is contained in the circle.

func (Circle) ContainsSLC

func (c Circle) ContainsSLC(p Point) bool

ContainsSLC uses the spherical law of cosines to determine if the point is contained in the circle.

func (Circle) MarshalJSON

func (c Circle) MarshalJSON() ([]byte, error)

MarshalJSON marshals a circle to GeoJSON. See https://github.com/geojson/geojson-spec/wiki/Proposal---Circles-and-Ellipses-Geoms

func (*Circle) Scan

func (c *Circle) Scan(src interface{}) error

Scan scans a circle from well known text.

func (Circle) String

func (c Circle) String() string

String returns a string representation of the circle.

func (*Circle) UnmarshalJSON

func (c *Circle) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the circle from GeoJSON.

func (Circle) Value

func (c Circle) Value() (driver.Value, error)

Value returns a sql driver value.

type Feature

type Feature struct {
	Geometry   Geometry    `json:"geometry"`
	Properties interface{} `json:"properties,omitempty"`
}

Feature is a GeoJSON feature.

func (Feature) Compare

func (f Feature) Compare(g Geometry) bool

Compare compares one feature to another. Note that this method does not compare properties.

func (Feature) Contains

func (f Feature) Contains(p Point) bool

Contains determines if the feature's geometry contains the point.

func (Feature) MarshalJSON

func (f Feature) MarshalJSON() ([]byte, error)

MarshalJSON marshals the feature to GeoJSON.

func (*Feature) Scan

func (f *Feature) Scan(src interface{}) error

Scan scans a feature from well known text.

func (Feature) String

func (f Feature) String() string

String converts the feature to a WKT string.

func (*Feature) UnmarshalJSON

func (f *Feature) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a feature from JSON.

func (Feature) Value

func (f Feature) Value() (driver.Value, error)

Value returns well known text for the feature.

type FeatureCollection

type FeatureCollection []Feature

FeatureCollection represents a feature collection.

func (FeatureCollection) Compare

func (coll FeatureCollection) Compare(g Geometry) bool

Compare compares one feature collection to another.

func (FeatureCollection) Contains

func (coll FeatureCollection) Contains(p Point) bool

Contains returns true if every feature in the collection contains the p, and false otherwise.

func (FeatureCollection) MarshalJSON

func (coll FeatureCollection) MarshalJSON() ([]byte, error)

MarshalJSON marshals the feature collection to geojson.

func (*FeatureCollection) Scan

func (coll *FeatureCollection) Scan(src interface{}) error

Scan scans the feature collection from WKT. This method expects a GEOMETRYCOLLECTION. TODO: implement this.

func (FeatureCollection) String

func (coll FeatureCollection) String() string

String converts the feature collection to a GEOMETRYCOLLECTION.

func (*FeatureCollection) UnmarshalJSON

func (coll *FeatureCollection) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the feature collection from geojson.

func (FeatureCollection) Value

func (coll FeatureCollection) Value() (driver.Value, error)

Value returns WKT for the feature collection. Note that this returns a GEOMETRYCOLLECTION.

type Geometry

type Geometry interface {
	json.Marshaler
	sql.Scanner
	driver.Valuer

	Compare(g Geometry) bool
	Contains(p Point) bool
	String() string
}

Geometry defines the interface of every geometry type.

func ScanGeometry

func ScanGeometry(s string) (Geometry, error)

ScanGeometry scans a geometry from well known text.

func UnmarshalGeometry

func UnmarshalGeometry(data []byte) (Geometry, error)

UnmarshalGeometry unmarshals a geometry from geojson data.

type Line

type Line [][2]float64

Line is a line.

func (Line) Compare

func (line Line) Compare(g Geometry) bool

Compare compares one line to another.

func (Line) Contains

func (line Line) Contains(p Point) bool

Contains determines if the line contains a point.

func (Line) MarshalJSON

func (line Line) MarshalJSON() ([]byte, error)

MarshalJSON marshals the line to JSON.

func (*Line) Scan

func (line *Line) Scan(src interface{}) error

Scan scans a line from Well Known Text.

func (Line) String

func (line Line) String() string

String converts the line to a string.

func (Line) Value

func (line Line) Value() (driver.Value, error)

Value returns a driver Value.

type MultiPoint

type MultiPoint []Point

MultiPoint is a collection of points.

type Point

type Point [2]float64

Point defines a point.

func (Point) Compare

func (point Point) Compare(g Geometry) bool

Compare compares one point to another.

func (Point) Contains

func (point Point) Contains(other Point) bool

Contains is the exact same as Compare.

func (Point) DistanceFrom

func (point Point) DistanceFrom(other Point) float64

DistanceFrom computes the distance from one point to another.

func (Point) MarshalJSON

func (point Point) MarshalJSON() ([]byte, error)

MarshalJSON returns the GeoJSON representation of the point.

func (Point) RayhIntersects

func (point Point) RayhIntersects(a, b Point) bool

RayhIntersects returns true if the horizontal ray going from point to positive infinity intersects the line that connects a and b.

func (*Point) Scan

func (point *Point) Scan(src interface{}) error

Scan scans a point from Well Known Text.

func (Point) String

func (point Point) String() string

String convert the point to a string.

func (Point) Value

func (point Point) Value() (driver.Value, error)

Value converts a point to Well Known Text.

type Polygon

type Polygon [][][2]float64

Polygon is a GeoJSON Polygon.

func (Polygon) Compare

func (polygon Polygon) Compare(g Geometry) bool

Compare compares one polygon to another.

func (Polygon) Contains

func (polygon Polygon) Contains(point Point) bool

Contains uses the ray casting algorithm to decide if the point is contained in the polygon.

func (Polygon) MarshalJSON

func (polygon Polygon) MarshalJSON() ([]byte, error)

MarshalJSON returns the GeoJSON representation of the polygon.

func (*Polygon) Scan

func (polygon *Polygon) Scan(src interface{}) error

Scan scans a polygon from Well Known Text.

func (Polygon) String

func (polygon Polygon) String() string

String converts the polygon to a string.

func (*Polygon) UnmarshalJSON

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

UnmarshalJSON unmarshals the polygon from GeoJSON.

func (Polygon) Value

func (polygon Polygon) Value() (driver.Value, error)

Value converts a point to Well Known Text.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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