com.jhlabs.map.proj
Class Projection

java.lang.Object
  extended by com.jhlabs.map.proj.Projection
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
Apian1Projection, AugustProjection, AzimuthalProjection, BaconProjection, BipolarProjection, ConicProjection, CylindricalProjection, HatanoProjection, LagrangeProjection, LandsatProjection, LarriveeProjection, LaskowskiProjection, LinearProjection, ModifiedAzimuthalProjection, NicolosiProjection, NullProjection, OrteliusProjection, PerspectiveProjection, PolyconicProjection, PseudoCylindricalProjection, RectangularPolyconicProjection, VanDerGrintenProjection

public abstract class Projection
extends Object
implements Cloneable, Serializable

The superclass for all map projections Changes by Bernhard Jenny 18 May 2010: Added Serializable interface, added abstract keyword, added binarySearchInverse, added transform and inverseTransform with lon/lat as doubles. 25 October 2010: Made all setters and getters dealing with degrees final and calling the versions using radians. Derived classes now only need to overwrite a single getter or setter (if overwriting is at all necessary).

See Also:
Serialized Form

Field Summary
protected  double a
          The equator radius
protected static double DTR
           
protected  double e
          The eccentricity
protected  Ellipsoid ellipsoid
          The ellipsoid used by this projection
protected static double EPS10
           
protected  double es
          The eccentricity squared
protected  double falseEasting
          The false Easting of this projection
protected  double falseNorthing
          The false Northing of this projection
protected  double fromMetres
          Conversion factor from metres to whatever units the projection uses.
protected  boolean geocentric
          True if this projection is geocentric
protected  double maxLatitude
          The maximum latitude of the bounds of this projection
protected  double maxLongitude
          The maximum longitude of the bounds of this projection.
protected  double minLatitude
          The minimum latitude of the bounds of this projection
protected  double minLongitude
          The minimum longitude of the bounds of this projection.
protected  String name
          The name of this projection
protected  double one_es
          1-(eccentricity squared)
protected  double projectionLatitude
          The latitude of the centre of projection
protected  double projectionLongitude
          The longitude of the centre of projection
protected  double rone_es
          1/(1-(eccentricity squared))
protected static double RTD
           
protected  double scaleFactor
          The projection scale factor
protected  boolean spherical
          True if this projection is using a sphere (es == 0)
protected  double trueScaleLatitude
          The latitude of true scale.
 
Constructor Summary
protected Projection()
           
 
Method Summary
protected  void binarySearchInverse(double x, double y, double lon, double lat, Point2D.Double lp)
          Compute the inverse projection by a binary search.
protected  void binarySearchInverse(double x, double y, Point2D.Double lp)
          Compute the inverse projection by a binary search.
 Object clone()
           
 Ellipsoid getEllipsoid()
           
 int getEPSGCode()
          Returns the ESPG code for this projection, or 0 if unknown.
 double getEquatorRadius()
           
 double getFalseEasting()
           
 double getFalseNorthing()
           
 double getFromMetres()
           
 double getMaxLatitude()
           
 double getMaxLatitudeDegrees()
           
 double getMaxLongitude()
           
 double getMaxLongitudeDegrees()
           
 double getMinLatitude()
           
 double getMinLatitudeDegrees()
           
 double getMinLongitude()
           
 double getMinLongitudeDegrees()
           
 String getName()
           
 String getPROJ4Description()
          Get a string which describes this projection in PROJ.4 format.
 String getProjectionDescription()
          Returns a human readable description of this projection in telegram style.
 double getProjectionLatitude()
           
 double getProjectionLatitudeDegrees()
           
 double getProjectionLongitude()
           
 double getProjectionLongitudeDegrees()
           
 double getScaleFactor()
           
 double getTrueScaleLatitude()
           
 double getTrueScaleLatitudeDegrees()
           
 boolean hasInverse()
          Returns true if this projection has an inverse
 void initialize()
          Initialize the projection.
 boolean inside(double lon, double lat)
          Returns true if the given lat/lon point is visible in this projection.
 void inverseTransform(double[] srcPoints, int srcOffset, double[] dstPoints, int dstOffset, int numPoints)
          Inverse-project a number of points (in metres), producing a lat/long result in degrees
 Point2D.Double inverseTransform(Point2D.Double src, Point2D.Double dst)
          Inverse-project a point (in metres), producing a lat/long result in degrees
 Rectangle2D inverseTransform(Rectangle2D r)
          Finds the smallest lat/long rectangle wholly inside the given view rectangle.
 void inverseTransformRadians(double[] srcPoints, int srcOffset, double[] dstPoints, int dstOffset, int numPoints)
          Inverse-project a number of points (in metres), producing a lat/long result in radians
 void inverseTransformRadians(double srcX, double srcY, Point2D.Double dst)
          Inverse-project a point (in meters), producing a lat/long result in radians.
 Point2D.Double inverseTransformRadians(Point2D.Double src, Point2D.Double dst)
          Inverse-project a point (in metres), producing a lat/long result in radians
 boolean isConformal()
          Returns true if this projection is conformal
 boolean isEqualArea()
          Returns true if this projection is equal area
 boolean isRectilinear()
          Returns true if lat/long lines form a rectangular grid for this projection.
static void main(String[] args)
           
 boolean parallelsAreParallel()
          Returns true if latitude lines are parallel for this projection
 Point2D.Double project(double x, double y, Point2D.Double dst)
          The method which actually does the projection.
 Point2D.Double projectInverse(double x, double y, Point2D.Double dst)
          The method which actually does the inverse projection.
 void setEllipsoid(Ellipsoid ellipsoid)
           
 void setFalseEasting(double falseEasting)
          Set the false Easting in projected units.
 void setFalseNorthing(double falseNorthing)
          Set the false Northing in projected units.
 void setFromMetres(double fromMetres)
          Set the conversion factor from metres to projected units.
 void setMaxLatitude(double maxLatitude)
          Set the maximum latitude.
 void setMaxLongitude(double maxLongitude)
           
 void setMaxLongitudeDegrees(double maxLongitude)
           
 void setMinLatitude(double minLatitude)
          Set the minimum latitude.
 void setMinLongitude(double minLongitude)
           
 void setMinLongitudeDegrees(double minLongitude)
           
 void setName(String name)
          Set the name of this projection.
 void setProjectionLatitude(double projectionLatitude)
          Set the projection latitude in radians.
 void setProjectionLatitudeDegrees(double projectionLatitude)
          Set the projection latitude in degrees.
 void setProjectionLongitude(double projectionLongitude)
          Set the projection longitude in radians.
 void setProjectionLongitudeDegrees(double projectionLongitude)
          Set the projection longitude in degrees.
 void setScaleFactor(double scaleFactor)
          Set the projection scale factor.
 void setTrueScaleLatitude(double trueScaleLatitude)
          Set the latitude of true scale in radians.
 void setTrueScaleLatitudeDegrees(double trueScaleLatitude)
          Set the latitude of true scale in degrees.
 void testBinarySearchInverse()
           
 String toString()
           
 void transform(double[] srcPoints, int srcOffset, double[] dstPoints, int dstOffset, int numPoints)
          Project a number of lat/long points (in degrees), producing a result in metres
 Point2D.Double transform(double lon, double lat, Point2D.Double dst)
          Project a lon/lat point (in degrees), producing a result in metres.
 Point2D.Double transform(Point2D.Double src, Point2D.Double dst)
          Project a lat/long point (in degrees), producing a result in metres
 Rectangle2D transform(Rectangle2D r)
          Transform a bounding box.
 void transformRadians(double[] srcPoints, int srcOffset, double[] dstPoints, int dstOffset, int numPoints)
          Project a number of lat/long points (in radians), producing a result in metres
 Point2D.Double transformRadians(double lon, double lat, Point2D.Double dst)
          Project a lon/lat point (in degrees), producing a result in metres.
 Point2D.Double transformRadians(Point2D.Double src, Point2D.Double dst)
          Project a lat/long point, producing a result in metres
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

minLatitude

protected double minLatitude
The minimum latitude of the bounds of this projection


minLongitude

protected double minLongitude
The minimum longitude of the bounds of this projection. This is relative to the projection centre.


maxLatitude

protected double maxLatitude
The maximum latitude of the bounds of this projection


maxLongitude

protected double maxLongitude
The maximum longitude of the bounds of this projection. This is relative to the projection centre.


projectionLatitude

protected double projectionLatitude
The latitude of the centre of projection


projectionLongitude

protected double projectionLongitude
The longitude of the centre of projection


scaleFactor

protected double scaleFactor
The projection scale factor


falseEasting

protected double falseEasting
The false Easting of this projection


falseNorthing

protected double falseNorthing
The false Northing of this projection


trueScaleLatitude

protected double trueScaleLatitude
The latitude of true scale. Only used by specific projections.


a

protected double a
The equator radius


e

protected double e
The eccentricity


es

protected double es
The eccentricity squared


one_es

protected double one_es
1-(eccentricity squared)


rone_es

protected double rone_es
1/(1-(eccentricity squared))


ellipsoid

protected Ellipsoid ellipsoid
The ellipsoid used by this projection


spherical

protected boolean spherical
True if this projection is using a sphere (es == 0)


geocentric

protected boolean geocentric
True if this projection is geocentric


name

protected String name
The name of this projection


fromMetres

protected double fromMetres
Conversion factor from metres to whatever units the projection uses.


EPS10

protected static final double EPS10
See Also:
Constant Field Values

RTD

protected static final double RTD
See Also:
Constant Field Values

DTR

protected static final double DTR
See Also:
Constant Field Values
Constructor Detail

Projection

protected Projection()
Method Detail

clone

public Object clone()
Overrides:
clone in class Object

transform

public Point2D.Double transform(Point2D.Double src,
                                Point2D.Double dst)
Project a lat/long point (in degrees), producing a result in metres


transform

public final Point2D.Double transform(double lon,
                                      double lat,
                                      Point2D.Double dst)
Project a lon/lat point (in degrees), producing a result in metres. Important: unlike the other variations of tansform, this implementation always normalizes the longitude, even if projectionLongitude is 0. This is useful for projecting line features crossing +/180 degree of longitude. Bernhard Jenny, May 2010.


transformRadians

public Point2D.Double transformRadians(Point2D.Double src,
                                       Point2D.Double dst)
Project a lat/long point, producing a result in metres


transformRadians

public final Point2D.Double transformRadians(double lon,
                                             double lat,
                                             Point2D.Double dst)
Project a lon/lat point (in degrees), producing a result in metres. Important: unlike the other variations of tansform, this implementation always normalizes the longitude, even if projectionLongitude is 0. This is useful for projecting line features crossing +/180 degree of longitude. Bernhard Jenny, May 2010.


project

public Point2D.Double project(double x,
                              double y,
                              Point2D.Double dst)
The method which actually does the projection. This should be overridden for all projections.

Parameters:
x - Longitude in radians.
y - Latitude in radians.
dst - The projected point.
Returns:
The projected point, identical to parameter dst.

transform

public void transform(double[] srcPoints,
                      int srcOffset,
                      double[] dstPoints,
                      int dstOffset,
                      int numPoints)
Project a number of lat/long points (in degrees), producing a result in metres


transformRadians

public void transformRadians(double[] srcPoints,
                             int srcOffset,
                             double[] dstPoints,
                             int dstOffset,
                             int numPoints)
Project a number of lat/long points (in radians), producing a result in metres


inverseTransform

public Point2D.Double inverseTransform(Point2D.Double src,
                                       Point2D.Double dst)
Inverse-project a point (in metres), producing a lat/long result in degrees


inverseTransformRadians

public Point2D.Double inverseTransformRadians(Point2D.Double src,
                                              Point2D.Double dst)
Inverse-project a point (in metres), producing a lat/long result in radians


inverseTransformRadians

public void inverseTransformRadians(double srcX,
                                    double srcY,
                                    Point2D.Double dst)
Inverse-project a point (in meters), producing a lat/long result in radians. Added by Bernhard Jenny, May 2007.


projectInverse

public Point2D.Double projectInverse(double x,
                                     double y,
                                     Point2D.Double dst)
The method which actually does the inverse projection. This should be overridden for all projections.


inverseTransform

public void inverseTransform(double[] srcPoints,
                             int srcOffset,
                             double[] dstPoints,
                             int dstOffset,
                             int numPoints)
Inverse-project a number of points (in metres), producing a lat/long result in degrees


inverseTransformRadians

public void inverseTransformRadians(double[] srcPoints,
                                    int srcOffset,
                                    double[] dstPoints,
                                    int dstOffset,
                                    int numPoints)
Inverse-project a number of points (in metres), producing a lat/long result in radians


inverseTransform

public Rectangle2D inverseTransform(Rectangle2D r)
Finds the smallest lat/long rectangle wholly inside the given view rectangle. This is only a rough estimate.


main

public static void main(String[] args)

testBinarySearchInverse

public void testBinarySearchInverse()

binarySearchInverse

protected void binarySearchInverse(double x,
                                   double y,
                                   Point2D.Double lp)
Compute the inverse projection by a binary search. Use this method carefully! It is slow and only an approximation for projections that do not provide their own projectInverse method. Added by Bernhard Jenny, 18 May 2010.

Parameters:
x - The projected x coordinate relative to the unary sphere.
y - The projected y coordinate relative to the unary sphere.
lp - A point that will receive the result.

binarySearchInverse

protected void binarySearchInverse(double x,
                                   double y,
                                   double lon,
                                   double lat,
                                   Point2D.Double lp)
Compute the inverse projection by a binary search. Use this method carfully! It is slow and only an approximation for projections that do not provide their own projectInverse method. Added by Bernhard Jenny, 18 May 2010.

Parameters:
x - The projected x coordinate relative to the unary sphere.
y - The projected y coordinate relative to the unary sphere.
lon - An approximation of the longitude in radians.
lat - An approximation of the latitude in radians.
lp - A point that will receive the result.

transform

public Rectangle2D transform(Rectangle2D r)
Transform a bounding box. This is only a rough estimate.


isConformal

public boolean isConformal()
Returns true if this projection is conformal


isEqualArea

public boolean isEqualArea()
Returns true if this projection is equal area


hasInverse

public boolean hasInverse()
Returns true if this projection has an inverse


isRectilinear

public boolean isRectilinear()
Returns true if lat/long lines form a rectangular grid for this projection. This is generally only the case for cylindrical projections, but not for oblique cylindrical projections.


parallelsAreParallel

public boolean parallelsAreParallel()
Returns true if latitude lines are parallel for this projection


inside

public boolean inside(double lon,
                      double lat)
Returns true if the given lat/lon point is visible in this projection.

Parameters:
x - longitude in degrees.
y - latitude in degrees.
Returns:

setName

public void setName(String name)
Set the name of this projection.


getName

public String getName()

getProjectionDescription

public String getProjectionDescription()
Returns a human readable description of this projection in telegram style.

Returns:

getPROJ4Description

public String getPROJ4Description()
Get a string which describes this projection in PROJ.4 format.


toString

public String toString()
Overrides:
toString in class Object

setMinLatitude

public void setMinLatitude(double minLatitude)
Set the minimum latitude. This is only used for Shape clipping and doesn't affect projection.


getMinLatitude

public double getMinLatitude()

setMaxLatitude

public void setMaxLatitude(double maxLatitude)
Set the maximum latitude. This is only used for Shape clipping and doesn't affect projection.


getMaxLatitude

public double getMaxLatitude()

getMaxLatitudeDegrees

public final double getMaxLatitudeDegrees()

getMinLatitudeDegrees

public final double getMinLatitudeDegrees()

setMinLongitude

public void setMinLongitude(double minLongitude)

getMinLongitude

public double getMinLongitude()

setMinLongitudeDegrees

public final void setMinLongitudeDegrees(double minLongitude)

getMinLongitudeDegrees

public final double getMinLongitudeDegrees()

setMaxLongitude

public void setMaxLongitude(double maxLongitude)

getMaxLongitude

public double getMaxLongitude()

setMaxLongitudeDegrees

public final void setMaxLongitudeDegrees(double maxLongitude)

getMaxLongitudeDegrees

public final double getMaxLongitudeDegrees()

setProjectionLatitude

public void setProjectionLatitude(double projectionLatitude)
Set the projection latitude in radians.


getProjectionLatitude

public double getProjectionLatitude()

setProjectionLatitudeDegrees

public final void setProjectionLatitudeDegrees(double projectionLatitude)
Set the projection latitude in degrees.


getProjectionLatitudeDegrees

public final double getProjectionLatitudeDegrees()

setProjectionLongitude

public void setProjectionLongitude(double projectionLongitude)
Set the projection longitude in radians.


getProjectionLongitude

public double getProjectionLongitude()

setProjectionLongitudeDegrees

public final void setProjectionLongitudeDegrees(double projectionLongitude)
Set the projection longitude in degrees.


getProjectionLongitudeDegrees

public double getProjectionLongitudeDegrees()

setTrueScaleLatitude

public void setTrueScaleLatitude(double trueScaleLatitude)
Set the latitude of true scale in radians. This is only used by certain projections.


getTrueScaleLatitude

public double getTrueScaleLatitude()

setTrueScaleLatitudeDegrees

public final void setTrueScaleLatitudeDegrees(double trueScaleLatitude)
Set the latitude of true scale in degrees. This is only used by certain projections.


getTrueScaleLatitudeDegrees

public final double getTrueScaleLatitudeDegrees()

setFalseNorthing

public void setFalseNorthing(double falseNorthing)
Set the false Northing in projected units.


getFalseNorthing

public double getFalseNorthing()

setFalseEasting

public void setFalseEasting(double falseEasting)
Set the false Easting in projected units.


getFalseEasting

public double getFalseEasting()

setScaleFactor

public void setScaleFactor(double scaleFactor)
Set the projection scale factor. This is set to 1 by default.


getScaleFactor

public double getScaleFactor()

getEquatorRadius

public double getEquatorRadius()

setFromMetres

public void setFromMetres(double fromMetres)
Set the conversion factor from metres to projected units. This is set to 1 by default.


getFromMetres

public double getFromMetres()

setEllipsoid

public void setEllipsoid(Ellipsoid ellipsoid)

getEllipsoid

public Ellipsoid getEllipsoid()

getEPSGCode

public int getEPSGCode()
Returns the ESPG code for this projection, or 0 if unknown.


initialize

public void initialize()
Initialize the projection. This should be called after setting parameters and before using the projection. This is for performance reasons as initialization may be expensive.



Copyright © 2011. All Rights Reserved.