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

- Constants
- func Area(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, error)
- func Azimuth(a *geo.Geography, b *geo.Geography) (*float64, error)
- func BestGeomProjection(boundingRect s2.Rect) (geoprojbase.Proj4Text, error)
- func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.Geography, error)
- func CoveredBy(a *geo.Geography, b *geo.Geography) (bool, error)
- func Covers(a *geo.Geography, b *geo.Geography) (bool, error)
- func DWithin( a *geo.Geography, b *geo.Geography, distance float64, useSphereOrSpheroid UseSphereOrSpheroid, ) (bool, error)
- func Distance( a *geo.Geography, b *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid, ) (float64, error)
- func Intersects(a *geo.Geography, b *geo.Geography) (bool, error)
- func Length(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, error)
- func Perimeter(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, error)
- func Project(g *geo.Geography, distance float64, azimuth s1.Angle) (*geo.Geography, error)
- func Segmentize(geography *geo.Geography, segmentMaxLength float64) (*geo.Geography, error)
- type UseSphereOrSpheroid

azimuth.go best_projection.go covers.go distance.go dwithin.go geogfn.go geographiclib.go intersects.go segmentize.go topology_operations.go unary_operators.go

❖

`const SpheroidErrorFraction = 0.05`

SpheroidErrorFraction is an error fraction to compensate for using a sphere to calculate the distance for what is actually a spheroid. The distance calculation has an error that is bounded by (2 * spheroid.Flattening)%. This 5% margin is pretty safe.

Area returns the area of a given Geography.

Azimuth returns the azimuth in radians of the segment defined by the given point geometries. The azimuth is angle is referenced from north, and is positive clockwise. North = 0; East = π/2; South = π; West = 3π/2. Returns nil if the two points are the same. Returns an error if any of the two Geography items are not points.

BestGeomProjection translates roughly to the ST_BestSRID function in PostGIS. It attempts to find the best projection for a bounding box into an accurate geometry-type projection.

The algorithm is described by ST_Buffer/ST_Intersection documentation (paraphrased):

It first determines the best SRID that fits the bounding box of the 2 geography objects (ST_Intersection only). It favors a north/south pole projection, then UTM, then LAEA for smaller zones, otherwise falling back to web mercator. If geography objects are within one half zone UTM but not the same UTM it will pick one of those. After the calculation is complete, it will fall back to WGS84 Geography.

Centroid returns the Centroid of a given Geography.

NOTE: In the case of (Multi)Polygon Centroid result, it doesn't mirror with PostGIS's result. We are using the same algorithm of dividing into triangles. However, The PostGIS implementation differs as it cuts triangles in a different way - namely, it fixes the first point in the exterior ring as the first point of the triangle, whereas we always update the reference point to be the first point of the ring when moving from one ring to another.

See: http://jennessent.com/downloads/Graphics_Shapes_Manual_A4.pdf#page=49 for more details.

Ideally, both implementations should provide the same result. However, the centroid of the triangles is the vectorized mean of all the points, not the actual projection in the Spherical surface, which causes a small inaccuracies. This inaccuracy will eventually grow if there is a substantial number of a triangle with a larger area.

CoveredBy returns whether geography A is covered by geography B. See Covers for limitations.

Covers returns whether geography A covers geography B.

This calculation is done on the sphere.

Due to minor inaccuracies and lack of certain primitives in S2, precision for Covers will be for up to 1cm.

Current limitations (which are also limitations in PostGIS): * POLYGON/LINESTRING only works as "contains" - if any point of the LINESTRING

touches the boundary of the polygon, we will return false but should be true - e.g. SELECT st_covers( 'multipolygon(((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0)), ((1.0 0.0, 2.0 0.0, 2.0 1.0, 1.0 1.0, 1.0 0.0)))', 'linestring(0.0 0.0, 1.0 0.0)'::geography );

* Furthermore, LINESTRINGS that are covered in multiple POLYGONs inside

MULTIPOLYGON but NOT within a single POLYGON in the MULTIPOLYGON currently return false but should be true, e.g. SELECT st_covers( 'multipolygon(((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0)), ((1.0 0.0, 2.0 0.0, 2.0 1.0, 1.0 1.0, 1.0 0.0)))', 'linestring(0.0 0.0, 2.0 0.0)'::geography );

❖

func DWithin( a *geo.Geography, b *geo.Geography, distance float64, useSphereOrSpheroid UseSphereOrSpheroid, ) (bool, error)

DWithin returns whether a is within distance d of b, i.e. Distance(a, b) <= d. If A or B contains empty Geography objects, this will return false.

❖

func Distance( a *geo.Geography, b *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid, ) (float64, error)

Distance returns the distance between geographies a and b on a sphere or spheroid. Returns a geo.EmptyGeometryError if any of the Geographies are EMPTY.

Intersects returns whether geography A intersects geography B. This calculation is done on the sphere. Precision of intersect measurements is up to 1cm.

Length returns length of a given Geography.

Perimeter returns the perimeter of a given Geography.

Project returns calculate a projected point given a source point, a distance and a azimuth.

Segmentize return modified Geography having no segment longer that given maximum segment length. This works by dividing each segment by a power of 2 to find the smallest power less than or equal to the segmentMaxLength.

UseSphereOrSpheroid indicates whether to use a Sphere or Spheroid for certain calculations.

❖

const ( // UseSpheroid indicates to use the spheroid for calculations. UseSpheroid UseSphereOrSpheroid = true // UseSphere indicates to use the sphere for calculations. UseSphere UseSphereOrSpheroid = false )

Package geogfn imports 13 packages (graph) and is imported by 3 packages. Updated 2020-08-12. Refresh now. Tools for package owners.