Changeset 27902 in osm


Ignore:
Timestamp:
2012-02-20T11:47:27+01:00 (13 years ago)
Author:
bastik
Message:

update to proj4j rev. 2150 (fixes datum conversion)

Location:
applications/editors/josm/plugins/proj4j
Files:
2 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/CRSFactory.java

    r26409 r27902  
    88 * from a variety of ways
    99 * of specifying them.
     10 * This is the primary way of creating coordinate systems
     11 * for carrying out projections transformations.
    1012 * <p>
    1113 * <tt>CoordinateReferenceSystem</tt>s can be used to
     
    4244 
    4345  /**
    44    * Creates a {@link CoordinateReferenceSystem} from a well-known name.
    45    * Names are of the form: <tt>"authority:code"</tt>.
     46   * Creates a {@link CoordinateReferenceSystem} (CRS) from a well-known name.
     47   * CRS names are of the form: "<tt>authority:code</tt>",
     48   * with the components being:
    4649   * <ul>
    4750   * <li><b><tt>authority</tt></b> is a code for a namespace supported by
    4851   * PROJ.4. 
    4952   * Currently supported values are
    50    * <tt>EPSG</tt>, <tt>ESRI</tt>, <tt>WORLD</tt>, <tt>NA83</tt>, <tt>NAD27</tt>.
    51    * If no authority is provided, <tt>EPSG</tt> is assumed.
     53   * <tt>EPSG</tt>,
     54   * <tt>ESRI</tt>,
     55   * <tt>WORLD</tt>,
     56   * <tt>NA83</tt>,
     57   * <tt>NAD27</tt>.
     58   * If no authority is provided, the <tt>EPSG</tt> namespace is assumed.
    5259   * <li><b><tt>code</tt></b> is the id of a coordinate system in the authority namespace.
    5360   * For example, in the <tt>EPSG</tt> namespace a code is an integer value
    5461   * which identifies a CRS definition in the EPSG database.
     62   * (Codes are read and handled as strings).
    5563   * </ul>
    56    * An example of a valid name is <tt>EPSG:3005</tt>.
    57    *
     64   * An example of a valid CRS name is <tt>EPSG:3005</tt>.
     65   * <p>
    5866   * @param name the name of a coordinate system, with optional authority prefix
    59    * @return a {@link CoordinateReferenceSystem}
     67   * @return the {@link CoordinateReferenceSystem} corresponding to the given name
    6068   * @throws UnsupportedParameterException if a PROJ.4 parameter is not supported
    6169   * @throws InvalidValueException if a parameter value is invalid
     
    7381  /**
    7482   * Creates a {@link CoordinateReferenceSystem}
    75    * defined by a PROJ.4 parameter string.
     83   * from a PROJ.4 projection parameter string.
    7684   * <p>
    77    * An example of a valid PROJ.4 parameter string is:
     85   * An example of a valid PROJ.4 projection parameter string is:
    7886   * <pre>
    7987   * +proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +units=m
    8088   * </pre>
    81    * @param name a name for this coordinate system (may be <tt>null</tt>)
    82    * @param paramStr a PROJ.4 parameter string
    83    * @return a {@link CoordinateReferenceSystem}
    84    * @throws UnsupportedParameterException if a PROJ.4 parameter is not supported
    85    * @throws InvalidValueException if a parameter value is invalid
     89   * @param name a name for this coordinate system (may be <tt>null</tt> for an anonymous coordinate system)
     90   * @param paramStr a PROJ.4 projection parameter string
     91   * @return the specified {@link CoordinateReferenceSystem}
     92   * @throws UnsupportedParameterException if a given PROJ.4 parameter is not supported
     93   * @throws InvalidValueException if a supplied parameter value is invalid
    8694   */
    8795  public CoordinateReferenceSystem createFromParameters(String name, String paramStr)
     
    93101  /**
    94102   * Creates a {@link CoordinateReferenceSystem}
    95    * defined by an array of PROJ.4 parameters.
     103   * defined by an array of PROJ.4 projection parameters.
     104   * PROJ.4 parameters are generally of the form
     105   * "<tt>+name=value</tt>".
    96106   *
    97107   * @param name a name for this coordinate system (may be null)
    98    * @param args an array of PROJ.4 parameters
     108   * @param params an array of PROJ.4 projection parameters
    99109   * @return a {@link CoordinateReferenceSystem}
    100110   * @throws UnsupportedParameterException if a PROJ.4 parameter is not supported
    101111   * @throws InvalidValueException if a parameter value is invalid
    102112  */
    103   public CoordinateReferenceSystem createFromParameters(String name, String[] args)
     113  public CoordinateReferenceSystem createFromParameters(String name, String[] params)
    104114  throws UnsupportedParameterException, InvalidValueException
    105115  {
    106     if (args == null)
     116    if (params == null)
    107117      return null;
    108118   
    109119    Proj4Parser parser = new Proj4Parser(registry);
    110     return parser.parse(name, args);
     120    return parser.parse(name, params);
    111121  }
    112122
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/ProjCoordinate.java

    r26409 r27902  
    11package org.osgeo.proj4j;
     2
     3import java.text.DecimalFormat;
    24
    35/**
     
    1416public class ProjCoordinate
    1517{
     18  public static String DECIMAL_FORMAT_PATTERN = "0.0###############";
     19  public static DecimalFormat DECIMAL_FORMAT = new DecimalFormat(DECIMAL_FORMAT_PATTERN);
     20
    1621        /**
    1722         * The X ordinate for this point.
     
    317322                StringBuilder builder = new StringBuilder();
    318323                builder.append("[");
    319                 builder.append(this.x);
     324                builder.append(DECIMAL_FORMAT.format(x));
    320325                builder.append(", ");
    321                 builder.append(this.y);
     326                builder.append(DECIMAL_FORMAT.format(y));
    322327                if (! Double.isNaN(z)) {
    323328                        builder.append(", ");
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/ProjectionException.java

    r26509 r27902  
    2121/**
    2222 * Signals that an erroneous situation has
    23  * occurred during the computation of
     23 * occured during the computation of
    2424 * a projected coordinate system value.
    2525 *
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/Registry.java

    r26409 r27902  
    99
    1010/**
    11  * Records predefined values for various library classes
     11 * Supplies predefined values for various library classes
    1212 * such as {@link Ellipsoid}, {@link Datum}, and {@link Projection}.
    1313 *
     
    176176//    register( "kav7", Projection.class, "Kavraisky VII" );
    177177//    register( "labrd", Projection.class, "Laborde" );
    178 //    register( "laea", Projection.class, "Lambert Azimuthal Equal Area" );
     178    register( "laea", LambertAzimuthalEqualAreaProjection.class, "Lambert Azimuthal Equal Area" );
    179179    register( "lagrng", LagrangeProjection.class, "Lagrange" );
    180180    register( "larr", LarriveeProjection.class, "Larrivee" );
     
    226226    register( "rpoly", RectangularPolyconicProjection.class, "Rectangular Polyconic" );
    227227    register( "sinu", SinusoidalProjection.class, "Sinusoidal (Sanson-Flamsteed)" );
    228 //    register( "somerc", Projection.class, "Swiss. Obl. Mercator" );
     228    register( "somerc", SwissObliqueMercatorProjection.class, "Swiss Oblique Mercator" );
    229229    register( "stere", StereographicAzimuthalProjection.class, "Stereographic" );
    230230    register( "sterea", ObliqueStereographicAlternativeProjection.class, "Oblique Stereographic Alternative" );
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/datum/Datum.java

    r26409 r27902  
    3636 * <li>A grid-shift conversion
    3737 * </ul>
    38  *
     38 * In order to be able to transform between any two datums,
     39 * the parameter-based transforms are provided as a transform to
     40 * the common WGS84 datum.  The WGS transforms of two arbitrary datum transforms can
     41 * be concatenated to provide a transform between the two datums.
    3942 * <p>
    4043 * Notable datums in common use include {@link #NAD83} and {@link #WGS84}.
     
    121124    if (transform  == null) return TYPE_WGS84;
    122125   
    123     if (isZero(transform)) return TYPE_WGS84;
     126    if (isIdentity(transform)) return TYPE_WGS84;
    124127   
    125128    if (transform.length  == 3) return TYPE_3PARAM;
    126129    if (transform.length  == 7) return TYPE_7PARAM;
     130   
    127131    return TYPE_WGS84;
    128132  }
    129133 
    130   private static boolean isZero(double[] transform)
     134  /**
     135   * Tests whether the datum parameter-based transform
     136   * is the identity transform
     137   * (in which case datum transformation can be short-circuited,
     138   * thus avoiding some loss of numerical precision).
     139   *
     140   * @param transform
     141   * @return
     142   */
     143  private static boolean isIdentity(double[] transform)
    131144  {
    132145    for (int i = 0; i < transform.length; i++) {
    133       if (transform[i] != 0.0) return false;
     146      // scale factor will normally be 1 for an identity transform
     147      if (i == 6) {
     148        if (transform[i] != 1.0 && transform[i] != 0.0)
     149          return false;
     150      }
     151      else if (transform[i] != 0.0) return false;
    134152    }
    135153    return true;
     
    138156  public boolean hasTransformToWGS84()
    139157  {
    140     return getTransformType() == TYPE_3PARAM || getTransformType() == TYPE_7PARAM;
     158    int transformType = getTransformType();
     159    return transformType == TYPE_3PARAM || transformType == TYPE_7PARAM;
    141160  }
    142161 
     
    187206  }
    188207
    189  
    190208  public void transformFromGeocentricToWgs84(ProjCoordinate p)
    191209  {
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/io/Proj4FileReader.java

    r26409 r27902  
    1616  }
    1717
    18   public String[] readFile( String file, String name )
     18  public String[] readParametersFromFile( String authorityCode, String name )
    1919  throws IOException
    2020  {
     
    2323    // TODO: parse CSes line-at-a-time (this allows preserving CS param string for later access)
    2424   
    25         String filename = "/nad/" + file.toLowerCase();
     25        String filename = "/nad/" + authorityCode.toLowerCase();
    2626        InputStream inStr = Proj4FileReader.class.getResourceAsStream( filename );
    2727        if (inStr == null) {
    28                 throw new IllegalStateException("Unable to access resource " + filename);
     28                throw new IllegalStateException("Unable to access CRS file: " + filename);
    2929        }
    3030    BufferedReader reader = new BufferedReader(
     
    4141  }
    4242 
    43   private String[] readFile( BufferedReader reader, String name)
    44   throws IOException
     43  private StreamTokenizer createTokenizer(BufferedReader reader)
    4544  {
    4645    StreamTokenizer t = new StreamTokenizer( reader );
     
    5958    t.wordChars( ',', ',' );
    6059    t.wordChars( '@', '@' );
     60    return t;
     61  }
     62 
     63  private String[] readFile( BufferedReader reader, String name)
     64  throws IOException
     65  {
     66    StreamTokenizer t = createTokenizer(reader);
     67   
    6168    t.nextToken();
    6269    while ( t.ttype == '<' ) {
     
    6471      if ( t.ttype != StreamTokenizer.TT_WORD )
    6572        throw new IOException( t.lineno()+": Word expected after '<'" );
    66       String cname = t.sval;
     73      String crsName = t.sval;
    6774      t.nextToken();
    6875      if ( t.ttype != '>' )
     
    99106        throw new IOException( t.lineno()+": '<>' expected" );
    100107      t.nextToken();
    101       if ( cname.equals( name ) ) {
     108     
     109      // found requested CRS?
     110      if ( crsName.equals( name ) ) {
    102111        String[] args = (String[]) v.toArray( new String[0] );
    103112        return args;
     
    117126    else
    118127      v.add(plusKey);
    119 
    120 
    121128  }
    122   public String[] getParameters(String name) {
     129 
     130  /**
     131   * Gets the list of PROJ.4 parameters which define
     132   * the coordinate system specified by <tt>name</tt>.
     133   *
     134   * @param crsName the name of the coordinate system
     135   * @return the PROJ.4 projection parameters which define the coordinate system
     136   */
     137  public String[] getParameters(String crsName) {
    123138    try {
    124       int p = name.indexOf(':');
    125       if (p >= 0)
    126         return readFile(name.substring(0, p), name.substring(p + 1));
    127      
    128       /*
    129        // not sure this is needed or a good idea
    130         String[] files = { "world", "nad83", "nad27", "esri", "epsg", };
    131       for (int i = 0; i < files.length; i++) {
    132         Projection projection = readProjectionFile(files[i], name);
    133         if (projection != null)
    134           return projection;
     139      int p = crsName.indexOf(':');
     140      if (p >= 0) {
     141        String auth = crsName.substring(0, p);
     142        String id = crsName.substring(p + 1);
     143        return readParametersFromFile(auth, id);
    135144      }
    136       */
    137     } catch (IOException e) {
     145    }
     146    catch (IOException e) {
    138147      e.printStackTrace();
    139148    }
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/parser/DatumParameters.java

    r26409 r27902  
    1111 * This class also implements the policies for
    1212 * which parameters take precedence
    13  * when multiple inconsisent ones are present.
     13 * when multiple inconsistent ones are present.
    1414 *
    1515 * @author Martin Davis
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/parser/Proj4Parser.java

    r26409 r27902  
    1616public class Proj4Parser
    1717{
     18  /* SECONDS_TO_RAD = Pi/180/3600 */
     19  private static final double SECONDS_TO_RAD = 4.84813681109535993589914102357e-6;
     20  private static final double MILLION = 1000000.0;
     21 
    1822  private Registry registry;
    1923 
     
    169173   String towgs84 = (String) params.get(Proj4Keyword.towgs84);
    170174   if (towgs84 != null) {
    171      double[] datumConvParams = parseDatumTransform(towgs84);
     175     double[] datumConvParams = parseToWGS84(towgs84);
    172176     datumParam.setDatumTransform(datumConvParams);
    173177   }
     
    183187 }
    184188 
    185  private double[] parseDatumTransform(String paramList)
     189 private double[] parseToWGS84(String paramList)
    186190 {
    187191   String[] numStr = paramList.split(",");
     
    195199     param[i] = Double.parseDouble(numStr[i]);
    196200   }
     201   
     202   // optimization to detect 3-parameter transform
     203   if (param[3] == 0.0
     204       && param[4] == 0.0
     205       && param[5] == 0.0
     206       && param[6] == 0.0
     207       ) {
     208     param = new double[] { param[0], param[1], param[2] };
     209   }
     210   
     211   /**
     212    * PROJ4 towgs84 7-parameter transform uses
     213    * units of arc-seconds for the rotation factors,
     214    * and parts-per-million for the scale factor.
     215    * These need to be converted to radians and a scale factor.
     216    */
     217   if (param.length > 3) {
     218     param[3] *= SECONDS_TO_RAD;
     219     param[4] *= SECONDS_TO_RAD;
     220     param[5] *= SECONDS_TO_RAD;
     221     param[6] = (param[6]/MILLION) + 1;
     222   }
     223   
    197224   return param;
    198225 }
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/proj/AlbersProjection.java

    r26409 r27902  
    182182        }
    183183
    184 /*
    185         public String toString() {
    186                 return "Lambert Equal Area Conic";
    187         }
    188 */
    189184}
    190185
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/proj/TransverseMercatorProjection.java

    r26410 r27902  
    1717/*
    1818 * This file was semi-automatically converted from the public-domain USGS PROJ source.
    19  *
    20  * Bernhard Jenny, February 2 2010: Corrected code for spherical case in
    21  * projectInverse, added isConformal.
    22  * 27 September 2010: added missing tests to forward spherical, removed
    23  * initialization code in constructor.
    2419 */
    2520package org.osgeo.proj4j.proj;
     
    160155        public ProjCoordinate projectInverse(double x, double y, ProjCoordinate out) {
    161156                if (spherical) {
    162                         /*
    163                         Original code
    164                         x = Math.exp(x / scaleFactor);
    165                         y = .5 * (x - 1. / x);
    166                         x = Math.cos(projectionLatitude + y / scaleFactor);
    167                         out.y = MapMath.asin(Math.sqrt((1. - x * x) / (1. + y * y)));
    168                         if (y < 0) {
    169                         out.y = -out.y;
    170                         }
    171                         out.x = Math.atan2(y, x);
    172                          */
    173 
    174                         // new code by Bernhard Jenny, February 2 2010
    175                         double D = y / scaleFactor + projectionLatitude;
    176                         double xp = x / scaleFactor;
    177 
    178                         out.y = Math.asin(Math.sin(D) / Math.cosh(xp));
    179                         out.x = Math.atan2(Math.sinh(xp), Math.cos(D));
     157                        double h = Math.exp(x / scaleFactor);
     158                        double g = .5 * (h - 1. / h);
     159                        h = Math.cos(projectionLatitude + y / scaleFactor);
     160                        out.y = ProjectionMath.asin(Math.sqrt((1. - h*h) / (1. + g*g)));
     161                        if (y < 0)
     162                                out.y = -out.y;
     163                        out.x = Math.atan2(g, h);
    180164                } else {
    181165                        double n, con, cosphi, d, ds, sinphi, t;
     
    213197                return true;
    214198        }
    215        
    216         public boolean isConformal() {
    217                 return true;
    218         }
    219199
    220200        public String toString() {
  • applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/util/ProjectionMath.java

    r26409 r27902  
    2727  public final static double PI = Math.PI;
    2828  public final static double HALFPI = Math.PI/2.0;
    29         public final static double QUARTERPI = Math.PI/4.0;
     29  public final static double QUARTERPI = Math.PI/4.0;
     30  public final static double FORTPI = QUARTERPI;
    3031        public final static double TWOPI = Math.PI*2.0;
    3132        public final static double RTD = 180.0/Math.PI;
     
    3435        public final static Rectangle2D WORLD_BOUNDS = new Rectangle2D.Double(-180, -90, 360, 180);
    3536
     37        public final static double  EPS10 = 1.0e-10;
    3638        /**
    3739         * Degree versions of trigonometric functions
Note: See TracChangeset for help on using the changeset viewer.