cockroach: github.com/cockroachdb/cockroach/pkg/geo Index | Files | Directories

package geo

import "github.com/cockroachdb/cockroach/pkg/geo"

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

Index

Package Files

bbox.go encode.go errors.go geo.go hilbert.go iterator.go latlng.go parse.go summary.go

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
)
const GeoHashAutoPrecision = 0

GeoHashAutoPrecision means to calculate the precision of SpatialObjectToGeoHash based on input, up to 32 characters.

const GeoHashMaxPrecision = 20

GeoHashMaxPrecision is the maximum precision for GeoHashes. 20 is picked as doubles have 51 decimals of precision, and each base32 position can contain 5 bits of data. As we have two points, we use floor((2 * 51) / 5) = 20.

Variables

var DefaultEWKBEncodingFormat = binary.LittleEndian

DefaultEWKBEncodingFormat is the default encoding format for EWKB.

func GeomTContainsEmpty Uses

func GeomTContainsEmpty(g geom.T) bool

GeomTContainsEmpty returns whether a geom.T contains any empty element.

func GeospatialTypeFitsColumnMetadata Uses

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 Uses

func IsEmptyGeometryError(err error) bool

IsEmptyGeometryError returns true if the error is of type EmptyGeometryError.

func IsLinearRingCCW Uses

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 Uses

func NewMismatchingSRIDsError(a GeospatialType, b GeospatialType) error

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

func NormalizeLatitudeDegrees Uses

func NormalizeLatitudeDegrees(lat float64) float64

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

func NormalizeLongitudeDegrees Uses

func NormalizeLongitudeDegrees(lng float64) float64

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

func S2RegionsFromGeomT Uses

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 Uses

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

SpatialObjectToEWKT transforms a given SpatialObject to EWKT.

func SpatialObjectToGeoHash Uses

func SpatialObjectToGeoHash(so geopb.SpatialObject, p int) (string, error)

SpatialObjectToGeoHash transforms a given SpatialObject to a GeoHash.

func SpatialObjectToGeoJSON Uses

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

SpatialObjectToGeoJSON transforms a given SpatialObject to GeoJSON.

func SpatialObjectToKML Uses

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

SpatialObjectToKML transforms a given SpatialObject to KML.

func SpatialObjectToWKB Uses

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

SpatialObjectToWKB transforms a given SpatialObject to WKB.

func SpatialObjectToWKBHex Uses

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

SpatialObjectToWKBHex transforms a given SpatialObject to WKBHex.

func SpatialObjectToWKT Uses

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

SpatialObjectToWKT transforms a given SpatialObject to WKT.

func StringToByteOrder Uses

func StringToByteOrder(s string) binary.ByteOrder

StringToByteOrder returns the byte order of string.

func Summary Uses

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

type CartesianBoundingBox Uses

type CartesianBoundingBox struct {
    geopb.BoundingBox
}

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

func BoundingBoxFromGeomTGeometryType Uses

func BoundingBoxFromGeomTGeometryType(g geom.T) *CartesianBoundingBox

BoundingBoxFromGeomTGeometryType returns an appropriate bounding box for a Geometry type.

func NewCartesianBoundingBox Uses

func NewCartesianBoundingBox() *CartesianBoundingBox

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

func (*CartesianBoundingBox) AddPoint Uses

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

AddPoint adds a point to the BoundingBox coordinates.

func (*CartesianBoundingBox) Buffer Uses

func (b *CartesianBoundingBox) Buffer(n float64) *CartesianBoundingBox

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

func (*CartesianBoundingBox) Covers Uses

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 Uses

func (b *CartesianBoundingBox) Intersects(o *CartesianBoundingBox) bool

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

type EmptyBehavior Uses

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 Uses

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 Uses

func NewEmptyGeometryError() *EmptyGeometryError

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

func (*EmptyGeometryError) Cause Uses

func (w *EmptyGeometryError) Cause() error

Cause implements the errors.SafeDetailer interface.

func (*EmptyGeometryError) Error Uses

func (w *EmptyGeometryError) Error() string

Error implements the error interface.

func (*EmptyGeometryError) Format Uses

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

Format implements the errors.Formatter interface.

func (*EmptyGeometryError) FormatError Uses

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

FormatError implements the errors.Formatter interface.

func (*EmptyGeometryError) SafeDetails Uses

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

SafeDetails implements the SafeDetailer interface.

func (*EmptyGeometryError) Unwrap Uses

func (w *EmptyGeometryError) Unwrap() error

Unwrap implements the SafeDetailer interface.

type Geography Uses

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

Geography is a spherical spatial object.

func MustNewGeographyFromGeomT Uses

func MustNewGeographyFromGeomT(g geom.T) *Geography

MustNewGeographyFromGeomT enforces no error from NewGeographyFromGeomT.

func MustParseGeography Uses

func MustParseGeography(str string) *Geography

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

func MustParseGeographyFromEWKB Uses

func MustParseGeographyFromEWKB(ewkb geopb.EWKB) *Geography

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

func NewGeography Uses

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

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

func NewGeographyFromGeomT Uses

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

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

func NewGeographyUnsafe Uses

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 Uses

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

ParseGeography parses a Geography from a given text.

func ParseGeographyFromEWKB Uses

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

ParseGeographyFromEWKB parses the EWKB into a Geography.

func ParseGeographyFromEWKBAndSRID Uses

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 Uses

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 Uses

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

ParseGeographyFromEWKT parses the EWKT into a Geography.

func ParseGeographyFromGeoJSON Uses

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

ParseGeographyFromGeoJSON parses the GeoJSON into a given Geography.

func (*Geography) AsGeomT Uses

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

AsGeomT returns the Geography as a geom.T object.

func (*Geography) AsGeometry Uses

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

AsGeometry converts a given Geography to its Geometry form.

func (*Geography) AsS2 Uses

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

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

func (*Geography) BoundingCap Uses

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

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

func (*Geography) BoundingRect Uses

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

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

func (*Geography) CloneWithSRID Uses

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) Compare Uses

func (g *Geography) Compare(o *Geography) int

Compare compares a Geography against another. It compares using SpaceCurveIndex, followed by the byte representation of the Geography. This must produce the same ordering as the index mechanism.

func (*Geography) EWKB Uses

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

EWKB returns the EWKB representation of the Geography.

func (*Geography) EWKBHex Uses

func (g *Geography) EWKBHex() string

EWKBHex returns the EWKBHex representation of the Geography.

func (*Geography) SRID Uses

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

SRID returns the SRID representation of the Geography.

func (*Geography) ShapeType Uses

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

ShapeType returns the shape type of the Geography.

func (*Geography) SpaceCurveIndex Uses

func (g *Geography) SpaceCurveIndex() uint64

SpaceCurveIndex returns an uint64 index to use representing an index into a space-filling curve. This will return 0 for empty spatial objects.

func (*Geography) SpatialObject Uses

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

SpatialObject returns the SpatialObject representation of the Geography.

func (*Geography) Spheroid Uses

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

Spheroid returns the spheroid represented by the given Geography.

type GeomTIterator Uses

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

GeomTIterator decomposes geom.T objects into individual components (i.e. either a POINT, LINESTRING or POLYGON) and presents them as an iterator. It automatically decomposes MULTI-* and GEOMETRYCOLLECTION objects. This prevents an allocation compared to decomposing the objects into a geom.T array.

func NewGeomTIterator Uses

func NewGeomTIterator(g geom.T, emptyBehavior EmptyBehavior) GeomTIterator

NewGeomTIterator returns a new GeomTIterator.

func (*GeomTIterator) Next Uses

func (it *GeomTIterator) Next() (geom.T, bool, error)

Next returns the next geom.T object, a bool as to whether there is an entry and an error if any.

type Geometry Uses

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

Geometry is planar spatial object.

func MustParseGeometry Uses

func MustParseGeometry(str string) *Geometry

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

func MustParseGeometryFromEWKB Uses

func MustParseGeometryFromEWKB(ewkb geopb.EWKB) *Geometry

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

func NewGeometry Uses

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

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

func NewGeometryFromGeomT Uses

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

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

func NewGeometryFromPointCoords Uses

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

NewGeometryFromPointCoords makes a point from x, y coordinates.

func NewGeometryUnsafe Uses

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 Uses

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

ParseGeometry parses a Geometry from a given text.

func ParseGeometryFromEWKB Uses

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

ParseGeometryFromEWKB parses the EWKB into a Geometry.

func ParseGeometryFromEWKBAndSRID Uses

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 Uses

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 Uses

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

ParseGeometryFromEWKT parses the EWKT into a Geometry.

func ParseGeometryFromGeoJSON Uses

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

ParseGeometryFromGeoJSON parses the GeoJSON into a given Geometry.

func (*Geometry) AsGeography Uses

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

AsGeography converts a given Geometry to its Geography form.

func (*Geometry) AsGeomT Uses

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

AsGeomT returns the geometry as a geom.T object.

func (*Geometry) CartesianBoundingBox Uses

func (g *Geometry) CartesianBoundingBox() *CartesianBoundingBox

CartesianBoundingBox returns a Cartesian bounding box.

func (*Geometry) CloneWithSRID Uses

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) Compare Uses

func (g *Geometry) Compare(o *Geometry) int

Compare compares a Geometry against another. It compares using SpaceCurveIndex, followed by the byte representation of the Geometry. This must produce the same ordering as the index mechanism.

func (*Geometry) EWKB Uses

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

EWKB returns the EWKB representation of the Geometry.

func (*Geometry) EWKBHex Uses

func (g *Geometry) EWKBHex() string

EWKBHex returns the EWKBHex representation of the Geometry.

func (*Geometry) Empty Uses

func (g *Geometry) Empty() bool

Empty returns whether the given Geometry is empty.

func (*Geometry) SRID Uses

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

SRID returns the SRID representation of the Geometry.

func (*Geometry) ShapeType Uses

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

ShapeType returns the shape type of the Geometry.

func (*Geometry) SpaceCurveIndex Uses

func (g *Geometry) SpaceCurveIndex() uint64

SpaceCurveIndex returns an uint64 index to use representing an index into a space-filling curve. This will return 0 for empty spatial objects, and math.MaxUint64 for any object outside the defined bounds of the given SRID projection.

func (*Geometry) SpatialObject Uses

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

SpatialObject returns the SpatialObject representation of the Geometry.

type GeospatialType Uses

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 Uses

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

PathSynopsis
geodistPackage geodist finds distances between two geospatial shapes.
geogfn
geographiclibPackage geographiclib is a wrapper around the GeographicLib library.
geoindex
geomfnPackage geomfn contains functions that are used for geometry-based builtins.
geopb
geoprojPackage geoproj contains functions that interface with the PROJ library.
geoprojbasePackage geoprojbase is a minimal dependency package that contains basic metadata and data structures for SRIDs and their CRS transformations.
geosPackage geos is a wrapper around the spatial data types between the geo package and the GEOS C library.
geosegmentize
geotransform

Package geo imports 26 packages (graph) and is imported by 16 packages. Updated 2020-08-11. Refresh now. Tools for package owners.