Documentation ¶
Overview ¶
Package project defines projections to and from Mercator and WGS84 along with helpers to apply them to orb geometry types.
Index ¶
- Variables
- func Bound(bound orb.Bound, proj orb.Projection) orb.Bound
- func Collection(c orb.Collection, proj orb.Projection) orb.Collection
- func Geometry(g orb.Geometry, proj orb.Projection) orb.Geometry
- func LineString(ls orb.LineString, proj orb.Projection) orb.LineString
- func MercatorScaleFactor(g orb.Point) float64
- func MultiLineString(mls orb.MultiLineString, proj orb.Projection) orb.MultiLineString
- func MultiPoint(mp orb.MultiPoint, proj orb.Projection) orb.MultiPoint
- func MultiPolygon(mp orb.MultiPolygon, proj orb.Projection) orb.MultiPolygon
- func Point(p orb.Point, proj orb.Projection) orb.Point
- func Polygon(p orb.Polygon, proj orb.Projection) orb.Polygon
- func Ring(r orb.Ring, proj orb.Projection) orb.Ring
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Mercator = struct { ToWGS84 orb.Projection }{ ToWGS84: func(p orb.Point) orb.Point { return orb.Point{ 180.0 * p[0] / earthRadiusPi, 180.0 / math.Pi * (2*math.Atan(math.Exp(p[1]/orb.EarthRadius)) - math.Pi/2.0), } }, }
Mercator performs the Spherical Pseudo-Mercator projection used by most web maps.
var WGS84 = struct { // ToMercator projections from WGS to Mercator, used by most web maps ToMercator orb.Projection }{ ToMercator: func(g orb.Point) orb.Point { y := math.Log(math.Tan((90.0+g[1])*math.Pi/360.0)) * orb.EarthRadius return orb.Point{ earthRadiusPi / 180.0 * g[0], math.Max(-earthRadiusPi, math.Min(y, earthRadiusPi)), } }, }
WGS84 is what common uses lon/lat projection.
Functions ¶
func Collection ¶
func Collection(c orb.Collection, proj orb.Projection) orb.Collection
Collection is a helper to project a rectangle.
func LineString ¶
func LineString(ls orb.LineString, proj orb.Projection) orb.LineString
LineString is a helper to project an entire line string.
func MercatorScaleFactor ¶
MercatorScaleFactor returns the mercator scaling factor for a given degree latitude.
func MultiLineString ¶
func MultiLineString(mls orb.MultiLineString, proj orb.Projection) orb.MultiLineString
MultiLineString is a helper to project an entire multi linestring.
func MultiPoint ¶
func MultiPoint(mp orb.MultiPoint, proj orb.Projection) orb.MultiPoint
MultiPoint is a helper to project an entire multi point.
func MultiPolygon ¶
func MultiPolygon(mp orb.MultiPolygon, proj orb.Projection) orb.MultiPolygon
MultiPolygon is a helper to project an entire multi polygon.
func Point ¶
Point is a helper to project an a point
Example (ToMercator) ¶
package main import ( "fmt" "github.com/Smadarl/orb" "github.com/Smadarl/orb/project" ) func main() { sf := orb.Point{-122.416667, 37.783333} merc := project.Geometry(sf, project.WGS84.ToMercator) fmt.Println(merc) }
Output: [-1.3627361035049736e+07 4.548863085837512e+06]
func Polygon ¶
Polygon is a helper to project an entire polygon.
Example ¶
package main import ( "fmt" "github.com/Smadarl/orb" "github.com/Smadarl/orb/planar" "github.com/Smadarl/orb/project" ) 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}, }, } merc := project.Polygon(poly, project.WGS84.ToMercator) centroid, _ := planar.CentroidArea(merc) centroid = project.Mercator.ToWGS84(centroid) fmt.Println(centroid) }
Output: [-122.41574403384001 37.77909471899779]
Types ¶
This section is empty.