http://zorba.io/modules/geoproj

View as XML or JSON.

Geographic projection module.

Forward and inverse projection from WGS84 lat-long coordinates to Oblique Mercator x-y projection.

Oblique Mercator projection is a sphere to cylinder projection.

This projection results in a conformal output, meaning the shape of small areas is preserved, no matter the distance from the origin. But it is not equal area, meaning the area size increases heavily when getting closer to North or South. The area size increases with the same amount on x and y axes, so the relative shape remains almost the same.

Mercator projection is the oldest projection, and it is still widely used because it produces a rectangular map.

This projection is used in Google Maps because of its conformal output.

For military or measurements purposes the UTM projection is used (or variants). This splits the Earth into small areas and computes the cartesian coordinates relative to each area.

Here we use Oblique Mercator projection. Its advantage over the normal Mercator is that you can set the tangent point between the cylinder and the sphere to be anywhere on Earth. So you can set the center of the map to be close to the area you want projected and be able to measure accurately the distances between points and lines.

The map deformation is minimal close to the center point and close to the "equator" line.

The advantage over the UTM projection is that it can also produce a global rectangular map, like Mercator, which is great for viewing.

The disadvantage over Mercator is that it needs more processing power.

WGS84 is the ellipsoid aproximation of the Earth, with big radius of 6,378,137 m and small radius of 6,356,752.3 m.

The geographic coordinates expressed for this ellipsoid are widely used today in maps and gps coordinates.

It is the default standard for representing geographic coordinates.

The purpose of this module is to provide convertion from polar to cartesian coordinates, so you can process the geographic data with the Simple Features API functions implemented in the geo module.

That module works only with cartesian coordinates, but most maps have polar coordinates.

The projection formulas are taken from lib_proj library and implemented in XQuery.

Function Summary

deg-to-dms ($deg as xs:double) as xs:string

Convertion from Degrees to Degrees-Minutes-Seconds (DMS).

deg-to-rad ($deg as xs:double) as xs:double

Convert angle from degrees to radians.

dms-to-deg ($dms as xs:string) as xs:double

Convertion from Degrees-Minutes-Seconds (DMS) to Degrees.

omerc-gmlpos-to-wgs84 ($lat_0 as xs:double, $long_c as xs:double, $k0 as xs:double, $gmlposs as element(gml:pos)*) as element(geoproj-param:latlong)*

Inverse projection from cartesian coordinates on Oblique Mercator cylinder to geographic coordinates lat-long on WGS84 ellipsoid.

omerc-to-wgs84 ($lat-0 as xs:double, $long-c as xs:double, $k0 as xs:double, $coords as element(geoproj-param:coord)*) as element(geoproj-param:latlong)*

Inverse projection from cartesian coordinates on Oblique Mercator cylinder to geographic coordinates lat-long on WGS84 ellipsoid.

rad-to-deg ($rad as xs:double) as xs:double

Convert angle from radians to degrees.

wgs84-to-omerc-gmlpos ($lat-0 as xs:double, $long-c as xs:double, $k0 as xs:double, $lat-long-degrees as element(geoproj-param:latlong)*) as element(gml:pos)*

Forward projection from geographic coordinates lat-long on WGS84 ellipsoid to Oblique Mercator cylinder.

wgs84-to-omerc ($lat-0 as xs:double, $long-c as xs:double, $k0 as xs:double, $lat-long-degrees as element(geoproj-param:latlong)*) as element(geoproj-param:coord)*

Forward projection from geographic coordinates lat-long on WGS84 ellipsoid to Oblique Mercator cylinder.

Functions

deg-to-dms#1

declare  function geoproj:deg-to-dms($deg as xs:double) as xs:string

Convertion from Degrees to Degrees-Minutes-Seconds (DMS).

Parameters

deg as xs:double
the degree value

Returns

xs:string
the value in DMS format, [-]degreedminutes'seconds

deg-to-rad#1

declare  function geoproj:deg-to-rad($deg as xs:double) as xs:double

Convert angle from degrees to radians.

The parameter is first reduced to value range of (-360, 360).

Parameters

deg as xs:double
angle in degrees

Returns

xs:double
value in radians (-2PI, 2PI)

dms-to-deg#1

declare  function geoproj:dms-to-deg($dms as xs:string) as xs:double

Convertion from Degrees-Minutes-Seconds (DMS) to Degrees.

The values for DMS can be like 11d12'13", meaning 11 degrees, 12 minutes and 13 seconds.

One degree has 60 minutes, and one minute has 60 seconds.

The separator for degrees can be one of the characters [dDoO].

The separator for minutes can be one of the characters ['m].

The separator for seconds can be " or nothing.

The seconds can be a floating point number.

The seconds can be missing, and if it is missing, the minutes can be missing too.

The negative value can be expressed as -11d12'13" or 11d12'13"S or 11d12'13"W.

Values for N (North) and E (East) are positive, and S (South) and W (West) are negative.

Parameters

dms as xs:string
the degree-minutes-seconds string expressed in the format described above

Returns

xs:double
the value in degrees

omerc-gmlpos-to-wgs84#4

declare  function geoproj:omerc-gmlpos-to-wgs84($lat_0 as xs:double, $long_c as xs:double, $k0 as xs:double, $gmlposs as element(gml:pos)*) as element(geoproj-param:latlong)*

Inverse projection from cartesian coordinates on Oblique Mercator cylinder to geographic coordinates lat-long on WGS84 ellipsoid.

This is an intermediate function for omerc-to-wgs84.

The difference is that it works with coordinates in gml:pos format, gml being the prefix for the GML namespace "http://www.opengis.net/gml".

Parameters

lat_0 as xs:double
is the latitude for center point, in degrees (-90, 90)
long_c as xs:double
is the longitude for center point, in degrees (-180, 180)
k0 as xs:double
is the scale in the center point.
gmlposs as element(gml:pos)
a sequence of nodes of type <gml:pos>x y</gml:pos> in namespace "http://www.opengis.net/gml"

Returns

element(geoproj-param:latlong)*
a sequence of geographic coordinates in format v <latlong><lat>latitude degree</lat><long>longitude degree</long></latlong> in namespace "http://zorba.io/modules/geoproj-param"

omerc-to-wgs84#4

declare  function geoproj:omerc-to-wgs84($lat-0 as xs:double, $long-c as xs:double, $k0 as xs:double, $coords as element(geoproj-param:coord)*) as element(geoproj-param:latlong)*

Inverse projection from cartesian coordinates on Oblique Mercator cylinder to geographic coordinates lat-long on WGS84 ellipsoid.

The parameters for center point and scale should be the same as for the initial forward projection, otherwise you will get wrong results.

Parameters

lat-0 as xs:double
long-c as xs:double
k0 as xs:double
is the scale in the center point.
coords as element(geoproj-param:coord)
a sequence of nodes of type <coord><x>x</x><y>y</y></coord> in namespace "http://zorba.io/modules/geoproj-param" The coordinates are expressed in meters.

Returns

element(geoproj-param:latlong)*
a sequence of geographic coordinates in format <latlong><lat>latitude degree</lat><long>longitude degree</long></latlong> in namespace "http://zorba.io/modules/geoproj-param" Note that the longitude corresponds to the x coordinate, and the latitude to the y coordinate.

rad-to-deg#1

declare  function geoproj:rad-to-deg($rad as xs:double) as xs:double

Convert angle from radians to degrees.

Parameters

rad as xs:double
value in radians

Returns

xs:double
value in degrees (-360, 360)

wgs84-to-omerc-gmlpos#4

declare  function geoproj:wgs84-to-omerc-gmlpos($lat-0 as xs:double, $long-c as xs:double, $k0 as xs:double, $lat-long-degrees as element(geoproj-param:latlong)*) as element(gml:pos)*

Forward projection from geographic coordinates lat-long on WGS84 ellipsoid to Oblique Mercator cylinder.

This is an intermediate function for wgs84-to-omerc.

The difference is that it returns the x-y coordinates in gml:pos format, gml being the prefix for the GML namespace "http://www.opengis.net/gml".

Parameters

lat-0 as xs:double
long-c as xs:double
k0 as xs:double
is the scale in the center point.
lat-long-degrees as element(geoproj-param:latlong)

Returns

element(gml:pos)*
a sequence of x-y coordinates in format <gml:pos>x y</gml:pos> in namespace "http://www.opengis.net/gml"

wgs84-to-omerc#4

declare  function geoproj:wgs84-to-omerc($lat-0 as xs:double, $long-c as xs:double, $k0 as xs:double, $lat-long-degrees as element(geoproj-param:latlong)*) as element(geoproj-param:coord)*

Forward projection from geographic coordinates lat-long on WGS84 ellipsoid to Oblique Mercator cylinder.

The Oblique Mercator projection is like the standard Mercator projection, but you can choose the point of origin.

Specify the coordinates of the center point somewhere near the points being projected, so the projection deformation is small.

The azimuth in the center point, alpha, is hardcoded to zero, so the true north is preserved.

This is a simplification of the standard Oblique Mercator projection.

Gamma, the azimuth of the rectified bearing of center line is also zero, calculated from alpha.

The radius of the Earth in WGS84 is 6378137 m.

Reverse flatening 298.257223563.

Eccentricity e 0.0818192.

Parameters

lat-0 as xs:double
long-c as xs:double
k0 as xs:double
is the scale in the center point. The scale will increase when going far to north and south. Use value 1 to get the true distances between points, in meters. At equator, the distance for 1 degree is aproximately 110 km.
lat-long-degrees as element(geoproj-param:latlong)

Returns

element(geoproj-param:coord)*
a sequence of x-y coordinates in format <coord><x>x</x><y>y</y></coord> in namespace "http://zorba.io/modules/geoproj-param" Note that the x coordinate corresponds to the longitude, and y coordinate to the latitude. The coordinates are expressed in meters. The coordinates are relative to the center point.