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.
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. |
declare function geoproj:deg-to-dms($deg as xs:double) as xs:string
Convertion from Degrees to Degrees-Minutes-Seconds (DMS).
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).
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.
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".
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.
declare function geoproj:rad-to-deg($rad as xs:double) as xs:double
Convert angle from radians to degrees.
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".
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.