Writing the Forward Projection
Before writing the forward functions for the Mercator projection, you must be familiar with the
IlvProjection::forward function.
The IlvProjection::forward Function
The IlvProjection::forward public function is called by the user to project data. The function prepares data for projection computation and scales it appropriately. It then redirects the calls to either one of the eForward or sForward protected functions which are defined in the projection subclass (the Mercator class in our example).
The IlvProjection::forward function:
adjusts the latitude if the coordinates are geocentric,
adjusts the longitude to the central meridian of the projection,
adjusts the longitude to the range
[-PI;PI], if longitude reduction is used (the default value),
calls either the function
sForward or
eForward depending on whether the earth is represented as a sphere or as an ellipsoid, and
adjusts the projected data to the dimensions of the ellipsoid as well as to the Cartesian offsets, and converts them to the selected measurement unit.
Projecting Data from a Sphere
The sForward protected function implements the projection for a sphere.
Since the appropriate scaling is actually carried out by the function IlvProjection::forward, the sForward function always assumes that the radius of the sphere is 1.
In our example, the Mercator function is the projection of a sphere on a cylinder that is tangent to the equator. The x coordinate is equal to the longitude (expressed in radians) because we assume that the radius of the sphere is 1. In this case, we do not have to change the x value of ll.
Because the Mercator projection cannot show regions near the poles, an error code is returned if the latitude is too close to PI/2.
We apply the following equation to compute the y coordinate of the projected data.
IlvMapsError
Mercator::sForward(IlvCoordinate& ll) const
{
// Return an error if the point is close to a pole.
if (fabs(fabs(ll.y()) - IlvMaps::Pi() / 2.) <= 1e-10)
return ToleranceConditionError();
ll.setY(log(tan(IlvMaps::Pi() / 4. + 0.5 * ll.y())));
return IlvMaps::NoError();
Projecting Data from an Ellipsoid
The eForward protected function is called by the IlvProjection::forward function if data is projected from a nonspherical ellipsoid.
It is not necessary for you to implement the
eForward function for your projection. If you are projecting data from a nonspherical ellipsoid and if the projection you are using does not support this kind of ellipsoid, the
forward function will return the error code given by
IlvProjection::UnsupportedFeatureError(). In this case, you can use any spherical ellipsoid or create an equivalent sphere using the appropriate conversion functions of the class
IlvEllipsoid.
The eForward function is slightly more complex than the sForward function although the formulas obtain equivalent results if getEllipsoid()->getE() returns 0.
IlvMapsError
Mercator::eForward(IlvCoordinate& ll) const
{
// Return an error if the point is close to a pole.
if (fabs(fabs(ll.y()) - IlvMaps::Pi() / 2.) <= 1e-10)
return ToleranceConditionError();
IlvDoublee = sqrt(getEllipsoid()->getES());
IlvDouble sinphi = e * sin(ll.y());
ll.setY(tan(.5 * (IlvMaps::Pi() / 2. -
ll.y())) /
pow((1. - sinphi) / (1. + sinphi),
0.5 * e));
ll.setY(-log(ll.y()));
return IlvMaps::NoError();
}
Version 5.7
Copyright © 2013, Rogue Wave Software, Inc. All Rights Reserved.