| Programming with JViews Maps > Ellipsoid and Geodetic Datums > Map Projections > Creating a New Projection |
Creating a New Projection |
INDEX
PREVIOUS
NEXT
|
This section shows how to extend the JViews Maps projection package with your own projections. It is based on an example that implements a simplified version of the Mercator projection.
The complete code for this example can be found in the following file:
<installdir>/jviews-maps81/codefragments/projection/srchtml/Mercator.java
This section covers the following topics:
To define a new class, you must first import the projection library located in the package ilog.views.maps.projection.
The complete source code of the examples presented in the next sections can be found in the following file:
<installdir>/jviews-maps81/codefragments/projection/srchtml/Mercator.java
Your projection class must extend the class IlvProjection, which is the base class for all the projections in the package.
import ilog.views.maps.projection.*; import ilog.views.maps.*; class MercatorProjection extends IlvProjection |
You must call the constructor of the superclass IlvProjection.
MercatorProjection() { super(true, true, IlvProjection.CONFORMAL); } |
This constructor takes the following three arguments:
boolean value specifying whether the projection supports nonspherical ellipsoids. In our example, this argument is set to true since the projection supports the equations for these ellipsoids.
boolean value indicating whether the projection supports an inverse method. In our example, this argument is set to true since the projection supports an inverse method.
int value that indicates the geometric properties of the projection. In our example, this argument is IlvProjection.CONFORMAL since the Mercator projection is conformal.
Before writing the forward() method for the Mercator projection, you must be familiar with the IlvProjection.forward() method.
The IlvProjection.forward() public method is called by the user to project data. This method prepares data for projection computation and scales it appropriately. It then redirects the calls to either one of the eforward or sForward protected methods which are defined in the projection subclass (the Mercator class in our example). In most cases, the forward method should not be overridden.
The IlvProjection.forward() method does the following:
[-PI;PI], if longitude reduction is used (the default value).
sForward() or eForward() depending on whether the Earth is represented as a sphere or as an ellipsoid.
The sforward() protected method implements the projection of a sphere.
Since the appropriate scaling is actually carried out by the method IlvProjection.forward(), the sForward() method always assumes that the radius of the sphere is 1.
In our example, the Mercator projection is the projection of a sphere onto a cylinder that is tangent to the equator. The x coordinate is equal to the longitude because it is assumed that the radius of the sphere is 1, and longitude is expressed in radians. In this case, you do not need to change the x value of ll.
Because the Mercator projection cannot show regions near the poles, the exception IlvToleranceConditionException is thrown if the latitude is too close to PI/2.
Apply the equation to compute the y coordinate of the projected data.
The eforward() protected method is called by the IlvProjection.forward() method if data is projected from a nonspherical ellipsoid.
It is not necessary for you to implement the eForward() method 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() method will throw the exception IlvUnsupportedProjectionFeature. In this case, you can use any spherical ellipsoid or create an equivalent sphere using the appropriate conversion methods of the class IlvEllipsoid.
The eForward() method is slightly more complex than the sForward() method although their formulas are equivalent if getEllipsoid().getE() returns 0.
Before writing the inverse() method for the Mercator projection, you should be familiar with the IlvProjection.inverse() method.
The inverse() method prepares the data for inversion and processes it for the appropriate offset. In most cases, you should not have to override the IlvProjection.inverse() method.
This method does the following:
sInverse() or eInverse() depending on whether the ellipsoid is a sphere or not.
[-PI;PI] if longitude reduction is used (the default value).
The inverse projection onto a sphere is performed via the sInverse() method.
It is not necessary for you to implement the sInverse() method. If you call the IlvProjection.inverse() method for a projection that does not support the inverse() method, the exception IlvUnsupportedProjectionFeature will be thrown.
The sInverse() method can throw the exception IlvToleranceConditionException like all the forward methods. But since the inverse equation of the Mercator projection is defined for all the possible values, this method does not throw any exceptions.
As seen earlier with the sForward() method, the projection does not modify the x value, therefore, the inverse equation is applied only to the y value.
protected void sInverse(IlvCoordinate xy) { xy.y = Math.PI/2D - 2D * Math.atan(Math.exp(-xy.y)); } |
The inverse projection onto an ellipsoid is performed via the eInverse() method.
This method assumes that the value of the semi-major axis of the ellipsoid is 1.
In the particular case of the Mercator projection, the implementation of this method is more complex for an ellipsoid than for a sphere. It requires iterations and might fail, since there is no simple analytical inverse equation of the Mercator projection from a nonspherical ellipsoid.
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |