Changeset 27902 in osm
- Timestamp:
- 2012-02-20T11:47:27+01:00 (13 years ago)
- 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 8 8 * from a variety of ways 9 9 * of specifying them. 10 * This is the primary way of creating coordinate systems 11 * for carrying out projections transformations. 10 12 * <p> 11 13 * <tt>CoordinateReferenceSystem</tt>s can be used to … … 42 44 43 45 /** 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: 46 49 * <ul> 47 50 * <li><b><tt>authority</tt></b> is a code for a namespace supported by 48 51 * PROJ.4. 49 52 * 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. 52 59 * <li><b><tt>code</tt></b> is the id of a coordinate system in the authority namespace. 53 60 * For example, in the <tt>EPSG</tt> namespace a code is an integer value 54 61 * which identifies a CRS definition in the EPSG database. 62 * (Codes are read and handled as strings). 55 63 * </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> 58 66 * @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 60 68 * @throws UnsupportedParameterException if a PROJ.4 parameter is not supported 61 69 * @throws InvalidValueException if a parameter value is invalid … … 73 81 /** 74 82 * Creates a {@link CoordinateReferenceSystem} 75 * defined by a PROJ.4parameter string.83 * from a PROJ.4 projection parameter string. 76 84 * <p> 77 * An example of a valid PROJ.4 p arameter string is:85 * An example of a valid PROJ.4 projection parameter string is: 78 86 * <pre> 79 87 * +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 80 88 * </pre> 81 * @param name a name for this coordinate system (may be <tt>null</tt> )82 * @param paramStr a PROJ.4 p arameter string83 * @return a{@link CoordinateReferenceSystem}84 * @throws UnsupportedParameterException if a PROJ.4 parameter is not supported85 * @throws InvalidValueException if a parameter value is invalid89 * @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 86 94 */ 87 95 public CoordinateReferenceSystem createFromParameters(String name, String paramStr) … … 93 101 /** 94 102 * 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>". 96 106 * 97 107 * @param name a name for this coordinate system (may be null) 98 * @param args an array of PROJ.4parameters108 * @param params an array of PROJ.4 projection parameters 99 109 * @return a {@link CoordinateReferenceSystem} 100 110 * @throws UnsupportedParameterException if a PROJ.4 parameter is not supported 101 111 * @throws InvalidValueException if a parameter value is invalid 102 112 */ 103 public CoordinateReferenceSystem createFromParameters(String name, String[] args)113 public CoordinateReferenceSystem createFromParameters(String name, String[] params) 104 114 throws UnsupportedParameterException, InvalidValueException 105 115 { 106 if ( args == null)116 if (params == null) 107 117 return null; 108 118 109 119 Proj4Parser parser = new Proj4Parser(registry); 110 return parser.parse(name, args);120 return parser.parse(name, params); 111 121 } 112 122 -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/ProjCoordinate.java
r26409 r27902 1 1 package org.osgeo.proj4j; 2 3 import java.text.DecimalFormat; 2 4 3 5 /** … … 14 16 public class ProjCoordinate 15 17 { 18 public static String DECIMAL_FORMAT_PATTERN = "0.0###############"; 19 public static DecimalFormat DECIMAL_FORMAT = new DecimalFormat(DECIMAL_FORMAT_PATTERN); 20 16 21 /** 17 22 * The X ordinate for this point. … … 317 322 StringBuilder builder = new StringBuilder(); 318 323 builder.append("["); 319 builder.append( this.x);324 builder.append(DECIMAL_FORMAT.format(x)); 320 325 builder.append(", "); 321 builder.append( this.y);326 builder.append(DECIMAL_FORMAT.format(y)); 322 327 if (! Double.isNaN(z)) { 323 328 builder.append(", "); -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/ProjectionException.java
r26509 r27902 21 21 /** 22 22 * Signals that an erroneous situation has 23 * occur red during the computation of23 * occured during the computation of 24 24 * a projected coordinate system value. 25 25 * -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/Registry.java
r26409 r27902 9 9 10 10 /** 11 * Records predefined values for various library classes11 * Supplies predefined values for various library classes 12 12 * such as {@link Ellipsoid}, {@link Datum}, and {@link Projection}. 13 13 * … … 176 176 // register( "kav7", Projection.class, "Kavraisky VII" ); 177 177 // register( "labrd", Projection.class, "Laborde" ); 178 // register( "laea",Projection.class, "Lambert Azimuthal Equal Area" );178 register( "laea", LambertAzimuthalEqualAreaProjection.class, "Lambert Azimuthal Equal Area" ); 179 179 register( "lagrng", LagrangeProjection.class, "Lagrange" ); 180 180 register( "larr", LarriveeProjection.class, "Larrivee" ); … … 226 226 register( "rpoly", RectangularPolyconicProjection.class, "Rectangular Polyconic" ); 227 227 register( "sinu", SinusoidalProjection.class, "Sinusoidal (Sanson-Flamsteed)" ); 228 // register( "somerc", Projection.class, "Swiss. Obl.Mercator" );228 register( "somerc", SwissObliqueMercatorProjection.class, "Swiss Oblique Mercator" ); 229 229 register( "stere", StereographicAzimuthalProjection.class, "Stereographic" ); 230 230 register( "sterea", ObliqueStereographicAlternativeProjection.class, "Oblique Stereographic Alternative" ); -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/datum/Datum.java
r26409 r27902 36 36 * <li>A grid-shift conversion 37 37 * </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. 39 42 * <p> 40 43 * Notable datums in common use include {@link #NAD83} and {@link #WGS84}. … … 121 124 if (transform == null) return TYPE_WGS84; 122 125 123 if (is Zero(transform)) return TYPE_WGS84;126 if (isIdentity(transform)) return TYPE_WGS84; 124 127 125 128 if (transform.length == 3) return TYPE_3PARAM; 126 129 if (transform.length == 7) return TYPE_7PARAM; 130 127 131 return TYPE_WGS84; 128 132 } 129 133 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) 131 144 { 132 145 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; 134 152 } 135 153 return true; … … 138 156 public boolean hasTransformToWGS84() 139 157 { 140 return getTransformType() == TYPE_3PARAM || getTransformType() == TYPE_7PARAM; 158 int transformType = getTransformType(); 159 return transformType == TYPE_3PARAM || transformType == TYPE_7PARAM; 141 160 } 142 161 … … 187 206 } 188 207 189 190 208 public void transformFromGeocentricToWgs84(ProjCoordinate p) 191 209 { -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/io/Proj4FileReader.java
r26409 r27902 16 16 } 17 17 18 public String[] read File( String file, String name )18 public String[] readParametersFromFile( String authorityCode, String name ) 19 19 throws IOException 20 20 { … … 23 23 // TODO: parse CSes line-at-a-time (this allows preserving CS param string for later access) 24 24 25 String filename = "/nad/" + file.toLowerCase();25 String filename = "/nad/" + authorityCode.toLowerCase(); 26 26 InputStream inStr = Proj4FileReader.class.getResourceAsStream( filename ); 27 27 if (inStr == null) { 28 throw new IllegalStateException("Unable to access resource" + filename);28 throw new IllegalStateException("Unable to access CRS file: " + filename); 29 29 } 30 30 BufferedReader reader = new BufferedReader( … … 41 41 } 42 42 43 private String[] readFile( BufferedReader reader, String name) 44 throws IOException 43 private StreamTokenizer createTokenizer(BufferedReader reader) 45 44 { 46 45 StreamTokenizer t = new StreamTokenizer( reader ); … … 59 58 t.wordChars( ',', ',' ); 60 59 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 61 68 t.nextToken(); 62 69 while ( t.ttype == '<' ) { … … 64 71 if ( t.ttype != StreamTokenizer.TT_WORD ) 65 72 throw new IOException( t.lineno()+": Word expected after '<'" ); 66 String c name = t.sval;73 String crsName = t.sval; 67 74 t.nextToken(); 68 75 if ( t.ttype != '>' ) … … 99 106 throw new IOException( t.lineno()+": '<>' expected" ); 100 107 t.nextToken(); 101 if ( cname.equals( name ) ) { 108 109 // found requested CRS? 110 if ( crsName.equals( name ) ) { 102 111 String[] args = (String[]) v.toArray( new String[0] ); 103 112 return args; … … 117 126 else 118 127 v.add(plusKey); 119 120 121 128 } 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) { 123 138 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); 135 144 } 136 */137 }catch (IOException e) {145 } 146 catch (IOException e) { 138 147 e.printStackTrace(); 139 148 } -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/parser/DatumParameters.java
r26409 r27902 11 11 * This class also implements the policies for 12 12 * which parameters take precedence 13 * when multiple inconsis ent ones are present.13 * when multiple inconsistent ones are present. 14 14 * 15 15 * @author Martin Davis -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/parser/Proj4Parser.java
r26409 r27902 16 16 public class Proj4Parser 17 17 { 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 18 22 private Registry registry; 19 23 … … 169 173 String towgs84 = (String) params.get(Proj4Keyword.towgs84); 170 174 if (towgs84 != null) { 171 double[] datumConvParams = parse DatumTransform(towgs84);175 double[] datumConvParams = parseToWGS84(towgs84); 172 176 datumParam.setDatumTransform(datumConvParams); 173 177 } … … 183 187 } 184 188 185 private double[] parse DatumTransform(String paramList)189 private double[] parseToWGS84(String paramList) 186 190 { 187 191 String[] numStr = paramList.split(","); … … 195 199 param[i] = Double.parseDouble(numStr[i]); 196 200 } 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 197 224 return param; 198 225 } -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/proj/AlbersProjection.java
r26409 r27902 182 182 } 183 183 184 /*185 public String toString() {186 return "Lambert Equal Area Conic";187 }188 */189 184 } 190 185 -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/proj/TransverseMercatorProjection.java
r26410 r27902 17 17 /* 18 18 * 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 in21 * projectInverse, added isConformal.22 * 27 September 2010: added missing tests to forward spherical, removed23 * initialization code in constructor.24 19 */ 25 20 package org.osgeo.proj4j.proj; … … 160 155 public ProjCoordinate projectInverse(double x, double y, ProjCoordinate out) { 161 156 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); 180 164 } else { 181 165 double n, con, cosphi, d, ds, sinphi, t; … … 213 197 return true; 214 198 } 215 216 public boolean isConformal() {217 return true;218 }219 199 220 200 public String toString() { -
applications/editors/josm/plugins/proj4j/src/org/osgeo/proj4j/util/ProjectionMath.java
r26409 r27902 27 27 public final static double PI = Math.PI; 28 28 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; 30 31 public final static double TWOPI = Math.PI*2.0; 31 32 public final static double RTD = 180.0/Math.PI; … … 34 35 public final static Rectangle2D WORLD_BOUNDS = new Rectangle2D.Double(-180, -90, 360, 180); 35 36 37 public final static double EPS10 = 1.0e-10; 36 38 /** 37 39 * Degree versions of trigonometric functions
Note:
See TracChangeset
for help on using the changeset viewer.