geo

package
v0.0.0-...-1dc08c0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package geo contains the base types for spatial data type operations.

Index

Constants

View Source
const (
	// DefaultSRIDShouldOverwrite implies the parsing function should overwrite
	// the SRID with the defaultSRID.
	DefaultSRIDShouldOverwrite defaultSRIDOverwriteSetting = true
	// DefaultSRIDIsHint implies that the default SRID is only a hint
	// and if the SRID is provided by the given EWKT/EWKB, it should be
	// used instead.
	DefaultSRIDIsHint defaultSRIDOverwriteSetting = false
)

Variables

View Source
var DefaultEWKBEncodingFormat = binary.LittleEndian

DefaultEWKBEncodingFormat is the default encoding format for EWKB.

Functions

func CompareSpatialObject

func CompareSpatialObject(lhs geopb.SpatialObject, rhs geopb.SpatialObject) int

CompareSpatialObject compares the SpatialObject. This must match the byte ordering that is be produced by encoding.EncodeGeoAscending.

func GeospatialTypeFitsColumnMetadata

func GeospatialTypeFitsColumnMetadata(
	t GeospatialType, srid geopb.SRID, shapeType geopb.ShapeType,
) error

GeospatialTypeFitsColumnMetadata determines whether a GeospatialType is compatible with the given SRID and Shape. Returns an error if the types does not fit.

func IsEmptyGeometryError

func IsEmptyGeometryError(err error) bool

IsEmptyGeometryError returns true if the error is of type EmptyGeometryError.

func IsLinearRingCCW

func IsLinearRingCCW(linearRing *geom.LinearRing) bool

IsLinearRingCCW returns whether a given linear ring is counter clock wise. See 2.07 of http://www.faqs.org/faqs/graphics/algorithms-faq/. "Find the lowest vertex (or, if there is more than one vertex with the same lowest coordinate,

the rightmost of those vertices) and then take the cross product of the edges fore and aft of it."

func NewMismatchingSRIDsError

func NewMismatchingSRIDsError(a GeospatialType, b GeospatialType) error

NewMismatchingSRIDsError returns the error message for SRIDs of GeospatialTypes a and b being a mismatch.

func NormalizeLatitudeDegrees

func NormalizeLatitudeDegrees(lat float64) float64

NormalizeLatitudeDegrees normalizes latitudes to the range [-90, 90].

func NormalizeLongitudeDegrees

func NormalizeLongitudeDegrees(lng float64) float64

NormalizeLongitudeDegrees normalizes longitude to the range [-180, 180].

func S2RegionsFromGeomT

func S2RegionsFromGeomT(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Region, error)

S2RegionsFromGeomT converts an geom representation of an object to s2 regions. As S2 does not really handle empty geometries well, we need to ingest emptyBehavior and react appropriately.

func SpatialObjectToEWKT

func SpatialObjectToEWKT(so geopb.SpatialObject, maxDecimalDigits int) (geopb.EWKT, error)

SpatialObjectToEWKT transforms a given SpatialObject to EWKT.

func SpatialObjectToGeoJSON

func SpatialObjectToGeoJSON(
	so geopb.SpatialObject, maxDecimalDigits int, flag SpatialObjectToGeoJSONFlag,
) ([]byte, error)

SpatialObjectToGeoJSON transforms a given SpatialObject to GeoJSON.

func SpatialObjectToKML

func SpatialObjectToKML(so geopb.SpatialObject) (string, error)

SpatialObjectToKML transforms a given SpatialObject to KML.

func SpatialObjectToWKB

func SpatialObjectToWKB(so geopb.SpatialObject, byteOrder binary.ByteOrder) (geopb.WKB, error)

SpatialObjectToWKB transforms a given SpatialObject to WKB.

func SpatialObjectToWKBHex

func SpatialObjectToWKBHex(so geopb.SpatialObject) (string, error)

SpatialObjectToWKBHex transforms a given SpatialObject to WKBHex.

func SpatialObjectToWKT

func SpatialObjectToWKT(so geopb.SpatialObject, maxDecimalDigits int) (geopb.WKT, error)

SpatialObjectToWKT transforms a given SpatialObject to WKT.

func StringToByteOrder

func StringToByteOrder(s string) binary.ByteOrder

StringToByteOrder returns the byte order of string.

func Summary

func Summary(
	t geom.T, hasBoundingBox bool, shape geopb.ShapeType, isGeography bool,
) (string, error)

Summary returns a text summary of the contents of the geometry type.

Flags shown square brackets after the geometry type have the following meaning: M: has M coordinate Z: has Z coordinate B: has a cached bounding box G: is geography S: has spatial reference system

Types

type CartesianBoundingBox

type CartesianBoundingBox struct {
	geopb.BoundingBox
}

CartesianBoundingBox is the cartesian BoundingBox representation, meant for use for GEOMETRY types.

func BoundingBoxFromGeomTGeometryType

func BoundingBoxFromGeomTGeometryType(g geom.T) *CartesianBoundingBox

BoundingBoxFromGeomTGeometryType returns an appropriate bounding box for a Geometry type.

func NewCartesianBoundingBox

func NewCartesianBoundingBox() *CartesianBoundingBox

NewCartesianBoundingBox returns a properly initialized empty bounding box for carestian plane types.

func (*CartesianBoundingBox) AddPoint

func (b *CartesianBoundingBox) AddPoint(x, y float64)

AddPoint adds a point to the BoundingBox coordinates.

func (*CartesianBoundingBox) Buffer

Buffer adds n units to each side of the bounding box.

func (*CartesianBoundingBox) Covers

Covers returns whether the BoundingBox covers the other bounding box. Empty bounding boxes never cover.

func (*CartesianBoundingBox) Intersects

Intersects returns whether the BoundingBoxes intersect. Empty bounding boxes never intersect.

type EmptyBehavior

type EmptyBehavior uint8

EmptyBehavior is the behavior to adopt when an empty Geometry is encountered.

const (
	// EmptyBehaviorError will error with EmptyGeometryError when an empty geometry
	// is encountered.
	EmptyBehaviorError EmptyBehavior = 0
	// EmptyBehaviorOmit will omit an entry when an empty geometry is encountered.
	EmptyBehaviorOmit EmptyBehavior = 1
)

type EmptyGeometryError

type EmptyGeometryError struct {
	// contains filtered or unexported fields
}

EmptyGeometryError is an error that is returned when the Geometry or any parts of its subgeometries are empty.

func NewEmptyGeometryError

func NewEmptyGeometryError() *EmptyGeometryError

NewEmptyGeometryError returns an error indicating an empty geometry has been found.

func (*EmptyGeometryError) Cause

func (w *EmptyGeometryError) Cause() error

Cause implements the errors.SafeDetailer interface.

func (*EmptyGeometryError) Error

func (w *EmptyGeometryError) Error() string

Error implements the error interface.

func (*EmptyGeometryError) Format

func (w *EmptyGeometryError) Format(s fmt.State, verb rune)

Format implements the errors.Formatter interface.

func (*EmptyGeometryError) FormatError

func (w *EmptyGeometryError) FormatError(p errors.Printer) (next error)

FormatError implements the errors.Formatter interface.

func (*EmptyGeometryError) SafeDetails

func (w *EmptyGeometryError) SafeDetails() []string

SafeDetails implements the SafeDetailer interface.

func (*EmptyGeometryError) Unwrap

func (w *EmptyGeometryError) Unwrap() error

Unwrap implements the SafeDetailer interface.

type Geography

type Geography struct {
	// contains filtered or unexported fields
}

Geography is a spherical spatial object.

func MustNewGeographyFromGeomT

func MustNewGeographyFromGeomT(g geom.T) *Geography

MustNewGeographyFromGeomT enforces no error from NewGeographyFromGeomT.

func MustParseGeography

func MustParseGeography(str string) *Geography

MustParseGeography behaves as ParseGeography, but panics if there is an error.

func MustParseGeographyFromEWKB

func MustParseGeographyFromEWKB(ewkb geopb.EWKB) *Geography

MustParseGeographyFromEWKB behaves as ParseGeographyFromEWKB, but panics if an error occurs.

func NewGeography

func NewGeography(spatialObject geopb.SpatialObject) (*Geography, error)

NewGeography returns a new Geography. Assumes the input EWKB is validated and in little endian.

func NewGeographyFromGeomT

func NewGeographyFromGeomT(g geom.T) (*Geography, error)

NewGeographyFromGeomT creates a new Geography from a geom.T object.

func NewGeographyUnsafe

func NewGeographyUnsafe(spatialObject geopb.SpatialObject) *Geography

NewGeographyUnsafe creates a geometry object that assumes spatialObject is from the DB. It assumes the spatialObject underneath is safe.

func ParseGeography

func ParseGeography(str string) (*Geography, error)

ParseGeography parses a Geography from a given text.

func ParseGeographyFromEWKB

func ParseGeographyFromEWKB(ewkb geopb.EWKB) (*Geography, error)

ParseGeographyFromEWKB parses the EWKB into a Geography.

func ParseGeographyFromEWKBAndSRID

func ParseGeographyFromEWKBAndSRID(ewkb geopb.EWKB, srid geopb.SRID) (*Geography, error)

ParseGeographyFromEWKBAndSRID parses the EWKB into a given Geography with the given SRID set.

func ParseGeographyFromEWKBUnsafe

func ParseGeographyFromEWKBUnsafe(ewkb geopb.EWKB) (*Geography, error)

ParseGeographyFromEWKBUnsafe returns a new Geography from an EWKB, without any SRID checks. You should only do this if you trust the EWKB is setup correctly. You most likely want ParseGeographyFromEWKB instead.

func ParseGeographyFromEWKT

func ParseGeographyFromEWKT(
	ewkt geopb.EWKT, srid geopb.SRID, defaultSRIDOverwriteSetting defaultSRIDOverwriteSetting,
) (*Geography, error)

ParseGeographyFromEWKT parses the EWKT into a Geography.

func ParseGeographyFromGeoJSON

func ParseGeographyFromGeoJSON(json []byte) (*Geography, error)

ParseGeographyFromGeoJSON parses the GeoJSON into a given Geography.

func (*Geography) AsGeomT

func (g *Geography) AsGeomT() (geom.T, error)

AsGeomT returns the Geography as a geom.T object.

func (*Geography) AsGeometry

func (g *Geography) AsGeometry() (*Geometry, error)

AsGeometry converts a given Geography to its Geometry form.

func (*Geography) AsS2

func (g *Geography) AsS2(emptyBehavior EmptyBehavior) ([]s2.Region, error)

AsS2 converts a given Geography into it's S2 form.

func (*Geography) BoundingCap

func (g *Geography) BoundingCap() s2.Cap

BoundingCap returns the bounding s2.Cap of the given Geography.

func (*Geography) BoundingRect

func (g *Geography) BoundingRect() s2.Rect

BoundingRect returns the bounding s2.Rect of the given Geography.

func (*Geography) CloneWithSRID

func (g *Geography) CloneWithSRID(srid geopb.SRID) (*Geography, error)

CloneWithSRID sets a given Geography's SRID to another, without any transformations. Returns a new Geography object.

func (*Geography) EWKB

func (g *Geography) EWKB() geopb.EWKB

EWKB returns the EWKB representation of the Geography.

func (*Geography) EWKBHex

func (g *Geography) EWKBHex() string

EWKBHex returns the EWKBHex representation of the Geography.

func (*Geography) SRID

func (g *Geography) SRID() geopb.SRID

SRID returns the SRID representation of the Geography.

func (*Geography) ShapeType

func (g *Geography) ShapeType() geopb.ShapeType

ShapeType returns the shape type of the Geography.

func (*Geography) SpatialObject

func (g *Geography) SpatialObject() geopb.SpatialObject

SpatialObject returns the SpatialObject representation of the Geography.

func (*Geography) Spheroid

func (g *Geography) Spheroid() (*geographiclib.Spheroid, error)

Spheroid returns the spheroid represented by the given Geography.

type Geometry

type Geometry struct {
	// contains filtered or unexported fields
}

Geometry is planar spatial object.

func MustParseGeometry

func MustParseGeometry(str string) *Geometry

MustParseGeometry behaves as ParseGeometry, but panics if there is an error.

func MustParseGeometryFromEWKB

func MustParseGeometryFromEWKB(ewkb geopb.EWKB) *Geometry

MustParseGeometryFromEWKB behaves as ParseGeometryFromEWKB, but panics if an error occurs.

func NewGeometry

func NewGeometry(spatialObject geopb.SpatialObject) (*Geometry, error)

NewGeometry returns a new Geometry. Assumes the input EWKB is validated and in little endian.

func NewGeometryFromGeomT

func NewGeometryFromGeomT(g geom.T) (*Geometry, error)

NewGeometryFromGeomT creates a new Geometry object from a geom.T object.

func NewGeometryFromPointCoords

func NewGeometryFromPointCoords(x, y float64) (*Geometry, error)

NewGeometryFromPointCoords makes a point from x, y coordinates.

func NewGeometryUnsafe

func NewGeometryUnsafe(spatialObject geopb.SpatialObject) *Geometry

NewGeometryUnsafe creates a geometry object that assumes spatialObject is from the DB. It assumes the spatialObject underneath is safe.

func ParseGeometry

func ParseGeometry(str string) (*Geometry, error)

ParseGeometry parses a Geometry from a given text.

func ParseGeometryFromEWKB

func ParseGeometryFromEWKB(ewkb geopb.EWKB) (*Geometry, error)

ParseGeometryFromEWKB parses the EWKB into a Geometry.

func ParseGeometryFromEWKBAndSRID

func ParseGeometryFromEWKBAndSRID(ewkb geopb.EWKB, srid geopb.SRID) (*Geometry, error)

ParseGeometryFromEWKBAndSRID parses the EWKB into a given Geometry with the given SRID set.

func ParseGeometryFromEWKBUnsafe

func ParseGeometryFromEWKBUnsafe(ewkb geopb.EWKB) (*Geometry, error)

ParseGeometryFromEWKBUnsafe returns a new Geometry from an EWKB, without any SRID checks. You should only do this if you trust the EWKB is setup correctly. You most likely want geo.ParseGeometryFromEWKB instead.

func ParseGeometryFromEWKT

func ParseGeometryFromEWKT(
	ewkt geopb.EWKT, srid geopb.SRID, defaultSRIDOverwriteSetting defaultSRIDOverwriteSetting,
) (*Geometry, error)

ParseGeometryFromEWKT parses the EWKT into a Geometry.

func ParseGeometryFromGeoJSON

func ParseGeometryFromGeoJSON(json []byte) (*Geometry, error)

ParseGeometryFromGeoJSON parses the GeoJSON into a given Geometry.

func (*Geometry) AsGeography

func (g *Geometry) AsGeography() (*Geography, error)

AsGeography converts a given Geometry to its Geography form.

func (*Geometry) AsGeomT

func (g *Geometry) AsGeomT() (geom.T, error)

AsGeomT returns the geometry as a geom.T object.

func (*Geometry) CartesianBoundingBox

func (g *Geometry) CartesianBoundingBox() *CartesianBoundingBox

CartesianBoundingBox returns a Cartesian bounding box.

func (*Geometry) CloneWithSRID

func (g *Geometry) CloneWithSRID(srid geopb.SRID) (*Geometry, error)

CloneWithSRID sets a given Geometry's SRID to another, without any transformations. Returns a new Geometry object.

func (*Geometry) EWKB

func (g *Geometry) EWKB() geopb.EWKB

EWKB returns the EWKB representation of the Geometry.

func (*Geometry) EWKBHex

func (g *Geometry) EWKBHex() string

EWKBHex returns the EWKBHex representation of the Geometry.

func (*Geometry) Empty

func (g *Geometry) Empty() bool

Empty returns whether the given Geometry is empty.

func (*Geometry) SRID

func (g *Geometry) SRID() geopb.SRID

SRID returns the SRID representation of the Geometry.

func (*Geometry) ShapeType

func (g *Geometry) ShapeType() geopb.ShapeType

ShapeType returns the shape type of the Geometry.

func (*Geometry) SpatialObject

func (g *Geometry) SpatialObject() geopb.SpatialObject

SpatialObject returns the SpatialObject representation of the Geometry.

type GeospatialType

type GeospatialType interface {
	// SRID returns the SRID of the given type.
	SRID() geopb.SRID
	// ShapeType returns the ShapeType of the given type.
	ShapeType() geopb.ShapeType
}

GeospatialType are functions that are common between all Geospatial types.

type SpatialObjectToGeoJSONFlag

type SpatialObjectToGeoJSONFlag int

SpatialObjectToGeoJSONFlag maps to the ST_AsGeoJSON flags for PostGIS.

const (
	SpatialObjectToGeoJSONFlagIncludeBBox SpatialObjectToGeoJSONFlag = 1 << (iota)
	SpatialObjectToGeoJSONFlagShortCRS
	SpatialObjectToGeoJSONFlagLongCRS
	SpatialObjectToGeoJSONFlagShortCRSIfNot4326

	SpatialObjectToGeoJSONFlagZero = 0
)

These should be kept with ST_AsGeoJSON in PostGIS. 0: means no option 1: GeoJSON BBOX 2: GeoJSON Short CRS (e.g EPSG:4326) 4: GeoJSON Long CRS (e.g urn:ogc:def:crs:EPSG::4326) 8: GeoJSON Short CRS if not EPSG:4326 (default)

Directories

Path Synopsis
Package geodist finds distances between two geospatial shapes.
Package geodist finds distances between two geospatial shapes.
Package geographiclib is a wrapper around the GeographicLib library.
Package geographiclib is a wrapper around the GeographicLib library.
Package geomfn contains functions that are used for geometry-based builtins.
Package geomfn contains functions that are used for geometry-based builtins.
Package geoproj contains functions that interface with the PROJ library.
Package geoproj contains functions that interface with the PROJ library.
Package geoprojbase is a minimal dependency package that contains basic metadata and data structures for SRIDs and their CRS transformations.
Package geoprojbase is a minimal dependency package that contains basic metadata and data structures for SRIDs and their CRS transformations.
Package geos is a wrapper around the spatial data types between the geo package and the GEOS C library.
Package geos is a wrapper around the spatial data types between the geo package and the GEOS C library.

Jump to

Keyboard shortcuts

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