geogfn

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: 11 Imported by: 0

Documentation

Index

Constants

View Source
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.

Variables

This section is empty.

Functions

func Area

func Area(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, error)

Area returns the area of a given Geography.

func Azimuth

func Azimuth(a *geo.Geography, b *geo.Geography) (*float64, error)

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.

func Centroid

func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.Geography, error)

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.

func CoveredBy

func CoveredBy(a *geo.Geography, b *geo.Geography) (bool, error)

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

func Covers

func Covers(a *geo.Geography, b *geo.Geography) (bool, error)

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

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

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.

func Intersects

func Intersects(a *geo.Geography, b *geo.Geography) (bool, error)

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

func Length

func Length(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, error)

Length returns length of a given Geography.

func Perimeter

func Perimeter(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, error)

Perimeter returns the perimeter of a given Geography.

func Project

func Project(g *geo.Geography, distance float64, azimuth s1.Angle) (*geo.Geography, error)

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

func Segmentize

func Segmentize(geography *geo.Geography, segmentMaxLength float64) (*geo.Geography, error)

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.

Types

type UseSphereOrSpheroid

type UseSphereOrSpheroid bool

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
)

Jump to

Keyboard shortcuts

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