Documentation ¶
Overview ¶
Package geo contains the base types for spatial data type operations.
Index ¶
- Constants
- Variables
- func CompareSpatialObject(lhs geopb.SpatialObject, rhs geopb.SpatialObject) int
- func GeospatialTypeFitsColumnMetadata(t GeospatialType, srid geopb.SRID, shapeType geopb.ShapeType) error
- func IsEmptyGeometryError(err error) bool
- func IsLinearRingCCW(linearRing *geom.LinearRing) bool
- func NewMismatchingSRIDsError(a GeospatialType, b GeospatialType) error
- func NormalizeLatitudeDegrees(lat float64) float64
- func NormalizeLongitudeDegrees(lng float64) float64
- func S2RegionsFromGeomT(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Region, error)
- func SpatialObjectToEWKT(so geopb.SpatialObject, maxDecimalDigits int) (geopb.EWKT, error)
- func SpatialObjectToGeoJSON(so geopb.SpatialObject, maxDecimalDigits int, flag SpatialObjectToGeoJSONFlag) ([]byte, error)
- func SpatialObjectToKML(so geopb.SpatialObject) (string, error)
- func SpatialObjectToWKB(so geopb.SpatialObject, byteOrder binary.ByteOrder) (geopb.WKB, error)
- func SpatialObjectToWKBHex(so geopb.SpatialObject) (string, error)
- func SpatialObjectToWKT(so geopb.SpatialObject, maxDecimalDigits int) (geopb.WKT, error)
- func StringToByteOrder(s string) binary.ByteOrder
- func Summary(t geom.T, hasBoundingBox bool, shape geopb.ShapeType, isGeography bool) (string, error)
- type CartesianBoundingBox
- type EmptyBehavior
- type EmptyGeometryError
- func (w *EmptyGeometryError) Cause() error
- func (w *EmptyGeometryError) Error() string
- func (w *EmptyGeometryError) Format(s fmt.State, verb rune)
- func (w *EmptyGeometryError) FormatError(p errors.Printer) (next error)
- func (w *EmptyGeometryError) SafeDetails() []string
- func (w *EmptyGeometryError) Unwrap() error
- type Geography
- func MustNewGeographyFromGeomT(g geom.T) *Geography
- func MustParseGeography(str string) *Geography
- func MustParseGeographyFromEWKB(ewkb geopb.EWKB) *Geography
- func NewGeography(spatialObject geopb.SpatialObject) (*Geography, error)
- func NewGeographyFromGeomT(g geom.T) (*Geography, error)
- func NewGeographyUnsafe(spatialObject geopb.SpatialObject) *Geography
- func ParseGeography(str string) (*Geography, error)
- func ParseGeographyFromEWKB(ewkb geopb.EWKB) (*Geography, error)
- func ParseGeographyFromEWKBAndSRID(ewkb geopb.EWKB, srid geopb.SRID) (*Geography, error)
- func ParseGeographyFromEWKBUnsafe(ewkb geopb.EWKB) (*Geography, error)
- func ParseGeographyFromEWKT(ewkt geopb.EWKT, srid geopb.SRID, ...) (*Geography, error)
- func ParseGeographyFromGeoJSON(json []byte) (*Geography, error)
- func (g *Geography) AsGeomT() (geom.T, error)
- func (g *Geography) AsGeometry() (*Geometry, error)
- func (g *Geography) AsS2(emptyBehavior EmptyBehavior) ([]s2.Region, error)
- func (g *Geography) BoundingCap() s2.Cap
- func (g *Geography) BoundingRect() s2.Rect
- func (g *Geography) CloneWithSRID(srid geopb.SRID) (*Geography, error)
- func (g *Geography) EWKB() geopb.EWKB
- func (g *Geography) EWKBHex() string
- func (g *Geography) SRID() geopb.SRID
- func (g *Geography) ShapeType() geopb.ShapeType
- func (g *Geography) SpatialObject() geopb.SpatialObject
- func (g *Geography) Spheroid() (*geographiclib.Spheroid, error)
- type Geometry
- func MustParseGeometry(str string) *Geometry
- func MustParseGeometryFromEWKB(ewkb geopb.EWKB) *Geometry
- func NewGeometry(spatialObject geopb.SpatialObject) (*Geometry, error)
- func NewGeometryFromGeomT(g geom.T) (*Geometry, error)
- func NewGeometryFromPointCoords(x, y float64) (*Geometry, error)
- func NewGeometryUnsafe(spatialObject geopb.SpatialObject) *Geometry
- func ParseGeometry(str string) (*Geometry, error)
- func ParseGeometryFromEWKB(ewkb geopb.EWKB) (*Geometry, error)
- func ParseGeometryFromEWKBAndSRID(ewkb geopb.EWKB, srid geopb.SRID) (*Geometry, error)
- func ParseGeometryFromEWKBUnsafe(ewkb geopb.EWKB) (*Geometry, error)
- func ParseGeometryFromEWKT(ewkt geopb.EWKT, srid geopb.SRID, ...) (*Geometry, error)
- func ParseGeometryFromGeoJSON(json []byte) (*Geometry, error)
- func (g *Geometry) AsGeography() (*Geography, error)
- func (g *Geometry) AsGeomT() (geom.T, error)
- func (g *Geometry) CartesianBoundingBox() *CartesianBoundingBox
- func (g *Geometry) CloneWithSRID(srid geopb.SRID) (*Geometry, error)
- func (g *Geometry) EWKB() geopb.EWKB
- func (g *Geometry) EWKBHex() string
- func (g *Geometry) Empty() bool
- func (g *Geometry) SRID() geopb.SRID
- func (g *Geometry) ShapeType() geopb.ShapeType
- func (g *Geometry) SpatialObject() geopb.SpatialObject
- type GeospatialType
- type SpatialObjectToGeoJSONFlag
Constants ¶
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 ¶
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 ¶
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 ¶
NormalizeLatitudeDegrees normalizes latitudes to the range [-90, 90].
func NormalizeLongitudeDegrees ¶
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 ¶
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 ¶
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 ¶
SpatialObjectToWKT transforms a given SpatialObject to WKT.
func StringToByteOrder ¶
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 ¶
func (b *CartesianBoundingBox) Buffer(n float64) *CartesianBoundingBox
Buffer adds n units to each side of the bounding box.
func (*CartesianBoundingBox) Covers ¶
func (b *CartesianBoundingBox) Covers(o *CartesianBoundingBox) bool
Covers returns whether the BoundingBox covers the other bounding box. Empty bounding boxes never cover.
func (*CartesianBoundingBox) Intersects ¶
func (b *CartesianBoundingBox) Intersects(o *CartesianBoundingBox) bool
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 ¶
MustParseGeography behaves as ParseGeography, but panics if there is an error.
func MustParseGeographyFromEWKB ¶
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 ¶
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 ¶
ParseGeography parses a Geography from a given text.
func ParseGeographyFromEWKB ¶
ParseGeographyFromEWKB parses the EWKB into a Geography.
func ParseGeographyFromEWKBAndSRID ¶
ParseGeographyFromEWKBAndSRID parses the EWKB into a given Geography with the given SRID set.
func ParseGeographyFromEWKBUnsafe ¶
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 ¶
ParseGeographyFromGeoJSON parses the GeoJSON into a given Geography.
func (*Geography) AsGeometry ¶
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 ¶
BoundingCap returns the bounding s2.Cap of the given Geography.
func (*Geography) BoundingRect ¶
BoundingRect returns the bounding s2.Rect of the given Geography.
func (*Geography) CloneWithSRID ¶
CloneWithSRID sets a given Geography's SRID to another, without any transformations. Returns a new Geography object.
func (*Geography) SpatialObject ¶
func (g *Geography) SpatialObject() geopb.SpatialObject
SpatialObject returns the SpatialObject representation of the Geography.
type Geometry ¶
type Geometry struct {
// contains filtered or unexported fields
}
Geometry is planar spatial object.
func MustParseGeometry ¶
MustParseGeometry behaves as ParseGeometry, but panics if there is an error.
func MustParseGeometryFromEWKB ¶
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 ¶
NewGeometryFromGeomT creates a new Geometry object from a geom.T object.
func NewGeometryFromPointCoords ¶
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 ¶
ParseGeometry parses a Geometry from a given text.
func ParseGeometryFromEWKB ¶
ParseGeometryFromEWKB parses the EWKB into a Geometry.
func ParseGeometryFromEWKBAndSRID ¶
ParseGeometryFromEWKBAndSRID parses the EWKB into a given Geometry with the given SRID set.
func ParseGeometryFromEWKBUnsafe ¶
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 ¶
ParseGeometryFromGeoJSON parses the GeoJSON into a given Geometry.
func (*Geometry) AsGeography ¶
AsGeography converts a given Geometry to its Geography form.
func (*Geometry) CartesianBoundingBox ¶
func (g *Geometry) CartesianBoundingBox() *CartesianBoundingBox
CartesianBoundingBox returns a Cartesian bounding box.
func (*Geometry) CloneWithSRID ¶
CloneWithSRID sets a given Geometry's SRID to another, without any transformations. Returns a new Geometry object.
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)
Source Files ¶
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. |