v0.2.1 Latest Latest Go to latest
Published: Jan 17, 2021 License: MIT

## README ¶

### orb/geo The geometries defined in the `orb` package are generic 2d geometries. Depending on what projection they're in, e.g. lon/lat or flat on the plane, area and distance calculations are different. This package implements methods that assume the lon/lat or WGS84 projection.

##### Examples

Area of the San Francisco Main Library:

``````poly := orb.Polygon{
{
{ -122.4163816, 37.7792782 },
{ -122.4162786, 37.7787626 },
{ -122.4151027, 37.7789118 },
{ -122.4152143, 37.7794274 },
{ -122.4163816, 37.7792782 },
},
}

a := geo.Area(poly)

fmt.Printf("%f m^2", a)
// Output:
// 6073.368008 m^2
``````

Distance between two points:

``````oakland := orb.Point{-122.270833, 37.804444}
sf := orb.Point{-122.416667, 37.783333}

d := geo.Distance(oakland, sf)

fmt.Printf("%0.3f meters", d)
// Output:
// 13042.047 meters
``````

Circumference of the San Francisco Main Library:

``````poly := orb.Polygon{
{
{ -122.4163816, 37.7792782 },
{ -122.4162786, 37.7787626 },
{ -122.4151027, 37.7789118 },
{ -122.4152143, 37.7794274 },
{ -122.4163816, 37.7792782 },
},
}
l := geo.Length(poly)

fmt.Printf("%0.0f meters", l)
// Output:
// 325 meters
``````

## Documentation ¶

### Overview ¶

Package geo computes properties on geometries assuming they are lon/lat data.

### Constants ¶

This section is empty.

### Variables ¶

This section is empty.

### Functions ¶

#### func Area ¶

`func Area(g orb.Geometry) float64`

Area returns the area of the geometry on the earth.

Example
```package main

import (
"fmt"

"github.com/paulmach/orb"
"github.com/paulmach/orb/geo"
)

func main() {
poly := orb.Polygon{
{
{-122.4163816, 37.7792782},
{-122.4162786, 37.7787626},
{-122.4151027, 37.7789118},
{-122.4152143, 37.7794274},
{-122.4163816, 37.7792782},
},
}
a := geo.Area(poly)

fmt.Printf("%f m^2", a)
}
```
```Output:

6073.368008 m^2
```

#### func Bearing ¶

`func Bearing(from, to orb.Point) float64`

Bearing computes the direction one must start traveling on earth to be heading from, to the given points.

#### func BoundHeight ¶

`func BoundHeight(b orb.Bound) float64`

BoundHeight returns the approximate height in meters.

`func BoundPad(b orb.Bound, meters float64) orb.Bound`

BoundPad expands the bound in all directions by the given amount of meters.

#### func BoundWidth ¶

`func BoundWidth(b orb.Bound) float64`

BoundWidth returns the approximate width in meters of the center of the bound.

#### func Distance ¶

`func Distance(p1, p2 orb.Point) float64`

Distance returns the distance between two points on the earth.

Example
```package main

import (
"fmt"

"github.com/paulmach/orb"
"github.com/paulmach/orb/geo"
)

func main() {
oakland := orb.Point{-122.270833, 37.804444}
sf := orb.Point{-122.416667, 37.783333}

d := geo.Distance(oakland, sf)

fmt.Printf("%0.3f meters", d)
}
```
```Output:

13042.047 meters
```

#### func DistanceHaversine ¶

`func DistanceHaversine(p1, p2 orb.Point) float64`

DistanceHaversine computes the distance on the earth using the more accurate haversine formula.

#### func Length ¶

`func Length(g orb.Geometry) float64`

Length returns the length of the boundary of the geometry using the geo distance function.

Example
```package main

import (
"fmt"

"github.com/paulmach/orb"
"github.com/paulmach/orb/geo"
)

func main() {

poly := orb.Polygon{
{
{-122.4163816, 37.7792782},
{-122.4162786, 37.7787626},
{-122.4151027, 37.7789118},
{-122.4152143, 37.7794274},
{-122.4163816, 37.7792782},
},
}
l := geo.Length(poly)

fmt.Printf("%0.0f meters", l)
}
```
```Output:

325 meters
```

#### func LengthHaversign ¶

`func LengthHaversign(g orb.Geometry) float64`

LengthHaversign returns the length of the boundary of the geometry using the geo haversine formula

#### func Midpoint ¶

`func Midpoint(p, p2 orb.Point) orb.Point`

Midpoint returns the half-way point along a great circle path between the two points.

#### func NewBoundAroundPoint ¶

`func NewBoundAroundPoint(center orb.Point, distance float64) orb.Bound`

NewBoundAroundPoint creates a new bound given a center point, and a distance from the center point in meters.

#### func SignedArea ¶

`func SignedArea(r orb.Ring) float64`

SignedArea will return the signed area of the ring. Will return negative if the ring is in the clockwise direction. Will implicitly close the ring.

### Types ¶

This section is empty.