svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / Crs.java @ 28835
History | View | Annotate | Download (18.5 KB)
1 | 8878 | jlgomez | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
||
34 | * Campus Universitario s/n
|
||
35 | * 02071 Alabacete
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 967 599 200
|
||
39 | */
|
||
40 | |||
41 | 6813 | mgarcia | package org.gvsig.crs; |
42 | |||
43 | import java.awt.Color; |
||
44 | import java.awt.Graphics2D; |
||
45 | import java.awt.geom.Point2D; |
||
46 | 7404 | dguerrero | import java.awt.geom.Rectangle2D; |
47 | 6813 | mgarcia | |
48 | import org.cresques.cts.ICoordTrans; |
||
49 | import org.cresques.cts.IDatum; |
||
50 | import org.cresques.cts.IProjection; |
||
51 | import org.cresques.geo.ViewPortData; |
||
52 | 8405 | dguerrero | import org.gvsig.crs.proj.CrsProj; |
53 | 8650 | dguerrero | import org.gvsig.crs.proj.JNIBaseCrs; |
54 | 8405 | dguerrero | import org.gvsig.crs.proj.OperationCrsException; |
55 | 6813 | mgarcia | |
56 | 8878 | jlgomez | /**
|
57 | * Clase que construye el CRS a partir de la cadena WKT
|
||
58 | * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
|
||
59 | * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
||
60 | * @author Miguel Garc?a Jim?nez (garciajimenez.miguel@gmail.com)
|
||
61 | *
|
||
62 | */
|
||
63 | 6813 | mgarcia | public class Crs implements ICrs { |
64 | 7904 | dguerrero | private static final Color basicGridColor = new Color(64, 64, 64, 128); |
65 | 18340 | jlgomez | private Proj4 proj4;
|
66 | private String proj4String; |
||
67 | 6813 | mgarcia | private String trans; |
68 | 7183 | jlgomez | //private String transOrigin = "";
|
69 | 6813 | mgarcia | private String abrev; |
70 | private String name = ""; |
||
71 | 18340 | jlgomez | private CrsProj crsProj;
|
72 | 8405 | dguerrero | private CrsProj crsBase = null; |
73 | 6813 | mgarcia | private CrsWkt crsWkt;
|
74 | 6821 | jlgomez | private int epsg_code = 23030; |
75 | 11957 | dguerrero | String sourceTrParams = null; |
76 | String targetTrParams = null; |
||
77 | 7876 | jlgomez | String wkt = null; |
78 | 7904 | dguerrero | Color gridColor = basicGridColor;
|
79 | 12541 | jlgomez | CRSDatum datum = null;
|
80 | 6813 | mgarcia | |
81 | 11242 | jlgomez | public Crs(int epsgCode, int aut) throws CrsException |
82 | 11045 | jlgomez | { |
83 | 11242 | jlgomez | String strEpsgCode = ""; |
84 | if (aut == 1) { |
||
85 | strEpsgCode="EPSG:"+epsgCode;
|
||
86 | } else if (aut == 2){ |
||
87 | strEpsgCode="ESRI:"+epsgCode;
|
||
88 | } else if (aut == 3){ |
||
89 | strEpsgCode="IAU2000:"+epsgCode;
|
||
90 | 11281 | jlgomez | } else if (aut == 4) { |
91 | strEpsgCode="USR:"+epsgCode;
|
||
92 | 11242 | jlgomez | } else System.out.println("Error, autorithy err?neo"); |
93 | 11045 | jlgomez | crsWkt=new CrsWkt(strEpsgCode);
|
94 | setWKT(crsWkt.getWkt()); |
||
95 | } |
||
96 | |||
97 | |||
98 | 8426 | dguerrero | /**
|
99 | * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
||
100 | *
|
||
101 | * @param code
|
||
102 | * @throws CrsException
|
||
103 | */
|
||
104 | 6813 | mgarcia | public Crs(String code) throws CrsException { |
105 | String fullCode;
|
||
106 | 7876 | jlgomez | setWKT(code); |
107 | 6813 | mgarcia | if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
108 | fullCode = code; |
||
109 | else fullCode = "EPSG:"+code; |
||
110 | String cod = ""; |
||
111 | if(code.length() < 15 ) { |
||
112 | code = code.substring(code.indexOf(":")+1); |
||
113 | try {
|
||
114 | //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
||
115 | 18340 | jlgomez | crsWkt = new CrsWkt(fullCode);
|
116 | 6813 | mgarcia | setName(fullCode); |
117 | setAbrev(fullCode); |
||
118 | |||
119 | 10397 | dguerrero | } catch (NumberFormatException e) { |
120 | // TODO Auto-generated catch block
|
||
121 | e.printStackTrace(); |
||
122 | 6813 | mgarcia | } |
123 | }else {
|
||
124 | String aux;
|
||
125 | String code2 = ""; |
||
126 | for(int i = 0; i < code.length(); i++) { |
||
127 | aux = ""+code.charAt(i);
|
||
128 | if(!aux.equals(" ")) { |
||
129 | code2+=aux; |
||
130 | }else {
|
||
131 | code2 += "";
|
||
132 | } |
||
133 | } |
||
134 | crsWkt = new CrsWkt(code2);
|
||
135 | 18340 | jlgomez | |
136 | 12541 | jlgomez | setName(fullCode); |
137 | //setAbrev(crsWkt.getName());
|
||
138 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
139 | |||
140 | } |
||
141 | 8426 | dguerrero | // Asignar el datum y el crs base (en el caso de ser projectado):
|
142 | 7904 | dguerrero | if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
143 | double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
||
144 | double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
||
145 | datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
||
146 | 8001 | dguerrero | |
147 | //crs base (en el caso de ser projectado):
|
||
148 | 18340 | jlgomez | /*if(this.isProjected()){
|
149 | 8001 | dguerrero | String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
|
150 | 8405 | dguerrero | crsBase = new CrsProj(proj4Base);
|
151 | 18340 | jlgomez | }*/
|
152 | 7904 | dguerrero | } |
153 | 6820 | jlgomez | } |
154 | 6813 | mgarcia | |
155 | 8426 | dguerrero | /**
|
156 | *Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
||
157 | *
|
||
158 | * @param epsg_cod
|
||
159 | * @param code
|
||
160 | * @throws CrsException
|
||
161 | */
|
||
162 | 6820 | jlgomez | public Crs(int epsg_cod, String code) throws CrsException { |
163 | String fullCode;
|
||
164 | 7876 | jlgomez | setWKT(code); |
165 | 6820 | jlgomez | setCode(epsg_cod); |
166 | 7408 | jlgomez | if(code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
167 | 6820 | jlgomez | fullCode = code; |
168 | else fullCode = "EPSG:"+code; |
||
169 | String cod = ""; |
||
170 | if(code.length() < 15 ) { |
||
171 | code = code.substring(code.indexOf(":")+1); |
||
172 | try {
|
||
173 | //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
||
174 | 18340 | jlgomez | crsWkt = new CrsWkt(fullCode);
|
175 | 6820 | jlgomez | setName(fullCode); |
176 | setAbrev(fullCode); |
||
177 | |||
178 | 10397 | dguerrero | } catch (NumberFormatException e) { |
179 | // TODO Auto-generated catch block
|
||
180 | e.printStackTrace(); |
||
181 | 6820 | jlgomez | } |
182 | }else {
|
||
183 | String aux;
|
||
184 | String code2 = ""; |
||
185 | for(int i = 0; i < code.length(); i++) { |
||
186 | aux = ""+code.charAt(i);
|
||
187 | if(!aux.equals(" ")) { |
||
188 | code2+=aux; |
||
189 | }else {
|
||
190 | code2 += "";
|
||
191 | } |
||
192 | } |
||
193 | crsWkt = new CrsWkt(code2);
|
||
194 | 8489 | jlgomez | /*
|
195 | * Arreglo temporal para ver si funcionan de la iau2000 las proyecciones
|
||
196 | * cilindrica equidistante y oblicua cilindrica equidistante
|
||
197 | * que no estan en gdal, por lo que asignaremos directamente su cadena
|
||
198 | * en proj4 para trabajar con ellas
|
||
199 | */
|
||
200 | 18340 | jlgomez | if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){ |
201 | 12541 | jlgomez | setName(fullCode); |
202 | //setAbrev(crsWkt.getName());
|
||
203 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
204 | 8489 | jlgomez | } |
205 | else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){ |
||
206 | String spheroid1 = crsWkt.getSpheroid()[1]; |
||
207 | String spheroid2 = crsWkt.getSpheroid()[2]; |
||
208 | 8655 | jlgomez | String centralMeridian = ""; |
209 | String falseNorthing = ""; |
||
210 | String falseEasting = ""; |
||
211 | String standardParallel1 = "0.0"; |
||
212 | for (int i=0; i<crsWkt.getParam_name().length;i++){ |
||
213 | if (crsWkt.getParam_name()[i].equals("Central_Meridian")) |
||
214 | centralMeridian = crsWkt.getParam_value()[i]; |
||
215 | if (crsWkt.getParam_name()[i].equals("False_Easting")) |
||
216 | falseEasting = crsWkt.getParam_value()[i]; |
||
217 | if(crsWkt.getParam_name()[i].equals("False_Northing")) |
||
218 | falseNorthing = crsWkt.getParam_value()[i]; |
||
219 | if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1")) |
||
220 | standardParallel1 = crsWkt.getParam_value()[i]; |
||
221 | } |
||
222 | if (spheroid2.equals("0.0")){ |
||
223 | 18340 | jlgomez | proj4String = "+proj=eqc +a=" + spheroid1 +
|
224 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
225 | " +lat_ts="+standardParallel1;
|
||
226 | 8489 | jlgomez | } else {
|
227 | 18340 | jlgomez | proj4String = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 + |
228 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
229 | " +lat_ts="+standardParallel1;
|
||
230 | 18340 | jlgomez | } |
231 | setName(fullCode); |
||
232 | 8426 | dguerrero | //setAbrev(crsWkt.getName());
|
233 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
234 | 8489 | jlgomez | |
235 | 6820 | jlgomez | } |
236 | 8489 | jlgomez | else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){ |
237 | String spheroid1 = crsWkt.getSpheroid()[1]; |
||
238 | String spheroid2 = crsWkt.getSpheroid()[2]; |
||
239 | 8655 | jlgomez | String centralMeridian = ""; |
240 | String falseNorthing = ""; |
||
241 | String falseEasting = ""; |
||
242 | String standardParallel1 = ""; |
||
243 | String standardParallel2 = "0.0"; |
||
244 | for (int i=0; i<crsWkt.getParam_name().length;i++){ |
||
245 | if (crsWkt.getParam_name()[i].equals("Central_Meridian")) |
||
246 | centralMeridian = crsWkt.getParam_value()[i]; |
||
247 | if (crsWkt.getParam_name()[i].equals("False_Easting")) |
||
248 | falseEasting = crsWkt.getParam_value()[i]; |
||
249 | if(crsWkt.getParam_name()[i].equals("False_Northing")) |
||
250 | falseNorthing = crsWkt.getParam_value()[i]; |
||
251 | if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1")) |
||
252 | standardParallel1 = crsWkt.getParam_value()[i]; |
||
253 | if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2")) |
||
254 | standardParallel2 = crsWkt.getParam_value()[i]; |
||
255 | } |
||
256 | if (spheroid2.equals("0.0")){ |
||
257 | 18340 | jlgomez | proj4String = "+proj=ocea +a="+ spheroid1 +
|
258 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
259 | " +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" + |
||
260 | " +lon_2=long_2 +no_defs";
|
||
261 | 8489 | jlgomez | } else {
|
262 | 18340 | jlgomez | proj4String = "+proj=ocea +a="+ spheroid1 + " +rf=" + spheroid2 + |
263 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
264 | " +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" + |
||
265 | 8489 | jlgomez | " +lon_2=long_2 +no_defs";
|
266 | 18340 | jlgomez | } |
267 | setName(fullCode); |
||
268 | 8489 | jlgomez | //setAbrev(crsWkt.getName());
|
269 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
270 | } |
||
271 | 6820 | jlgomez | } |
272 | 7904 | dguerrero | // Asignar el datum:
|
273 | 8001 | dguerrero | if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
274 | double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
||
275 | double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
||
276 | datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
||
277 | |||
278 | // Crs base (en el caso de ser projectado):
|
||
279 | 18340 | jlgomez | /*if(this.isProjected()){
|
280 | 8001 | dguerrero | String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
|
281 | 8405 | dguerrero | crsBase = new CrsProj(proj4Base);
|
282 | 18340 | jlgomez | }*/
|
283 | 8001 | dguerrero | } |
284 | 6820 | jlgomez | } |
285 | |||
286 | 8426 | dguerrero | /**
|
287 | * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
||
288 | * En el caso de WKT le a?ade a la cadena proj4 el string params.
|
||
289 | *
|
||
290 | * @param epsg_cod
|
||
291 | * @param code
|
||
292 | * @param params
|
||
293 | * @throws CrsException
|
||
294 | */
|
||
295 | 6927 | mgarcia | public Crs(int epsg_cod, String code,String params) throws CrsException { |
296 | String fullCode;
|
||
297 | setCode(epsg_cod); |
||
298 | 7876 | jlgomez | setWKT(code); |
299 | 6927 | mgarcia | if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
300 | fullCode = code; |
||
301 | else fullCode = "EPSG:"+code; |
||
302 | String cod = ""; |
||
303 | if(code.length() < 15 ) { |
||
304 | code = code.substring(code.indexOf(":")+1); |
||
305 | try {
|
||
306 | //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
||
307 | crsWkt = new CrsWkt(fullCode);
|
||
308 | 18340 | jlgomez | |
309 | 6927 | mgarcia | setName(fullCode); |
310 | setAbrev(fullCode); |
||
311 | |||
312 | 10397 | dguerrero | } catch (NumberFormatException e) { |
313 | // TODO Auto-generated catch block
|
||
314 | e.printStackTrace(); |
||
315 | 6927 | mgarcia | } |
316 | }else {
|
||
317 | String aux;
|
||
318 | String code2 = ""; |
||
319 | for(int i = 0; i < code.length(); i++) { |
||
320 | aux = ""+code.charAt(i);
|
||
321 | if(!aux.equals(" ")) { |
||
322 | code2+=aux; |
||
323 | }else {
|
||
324 | code2 += "";
|
||
325 | } |
||
326 | } |
||
327 | crsWkt = new CrsWkt(code2);
|
||
328 | 12541 | jlgomez | |
329 | setName(fullCode); |
||
330 | //setAbrev(crsWkt.getName());
|
||
331 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
332 | |||
333 | 6927 | mgarcia | } |
334 | 7904 | dguerrero | // Asignar el datum:
|
335 | 8001 | dguerrero | if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
336 | double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
||
337 | double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
||
338 | datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
||
339 | |||
340 | // Crs base (en el caso de ser projectado):
|
||
341 | 18340 | jlgomez | /*if(this.isProjected()){
|
342 | 8001 | dguerrero | String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
|
343 | 8405 | dguerrero | crsBase = new CrsProj(proj4Base);
|
344 | 18340 | jlgomez | }*/
|
345 | 8001 | dguerrero | } |
346 | 6927 | mgarcia | } |
347 | 7876 | jlgomez | |
348 | 8029 | dguerrero | /* public Crs(CrsEpsg source) throws CrsException {
|
349 | 6813 | mgarcia | crsProj4 = source;
|
350 | 8029 | dguerrero | }*/
|
351 | 6813 | mgarcia | |
352 | 8911 | jlgomez | /**
|
353 | * @param code
|
||
354 | */
|
||
355 | 6813 | mgarcia | public void setTrans(String code) { |
356 | trans = code; |
||
357 | changeTrans(trans); |
||
358 | } |
||
359 | |||
360 | 8911 | jlgomez | /**
|
361 | *
|
||
362 | * @param code
|
||
363 | */
|
||
364 | 6813 | mgarcia | public void changeTrans(String code) { |
365 | 18340 | jlgomez | getCrsProj().changeStrCrs(code); |
366 | 6813 | mgarcia | } |
367 | |||
368 | 8911 | jlgomez | /**
|
369 | *
|
||
370 | */
|
||
371 | 6813 | mgarcia | public String getAbrev() { |
372 | return abrev;
|
||
373 | } |
||
374 | |||
375 | 8911 | jlgomez | /**
|
376 | *
|
||
377 | * @param code
|
||
378 | */
|
||
379 | 6813 | mgarcia | protected void setAbrev(String code) { |
380 | abrev = code; |
||
381 | } |
||
382 | |||
383 | 8911 | jlgomez | /**
|
384 | *
|
||
385 | * @param nom
|
||
386 | */
|
||
387 | 6813 | mgarcia | public void setName(String nom) { |
388 | name = nom; |
||
389 | } |
||
390 | |||
391 | 8911 | jlgomez | /**
|
392 | * @return
|
||
393 | */
|
||
394 | 6813 | mgarcia | public IDatum getDatum() {
|
395 | 11045 | jlgomez | |
396 | 7904 | dguerrero | return datum;
|
397 | 6813 | mgarcia | } |
398 | |||
399 | 8911 | jlgomez | /**
|
400 | * @return
|
||
401 | */
|
||
402 | 6813 | mgarcia | public CrsWkt getCrsWkt() {
|
403 | return crsWkt;
|
||
404 | } |
||
405 | |||
406 | 8911 | jlgomez | /**
|
407 | *
|
||
408 | * @param wkt
|
||
409 | */
|
||
410 | 7876 | jlgomez | public void setWKT(String wkt){ |
411 | this.wkt = wkt;
|
||
412 | 6813 | mgarcia | } |
413 | |||
414 | 8911 | jlgomez | /**
|
415 | * @return
|
||
416 | */
|
||
417 | 7876 | jlgomez | public String getWKT(){ |
418 | return this.wkt; |
||
419 | } |
||
420 | |||
421 | 8911 | jlgomez | /**
|
422 | *
|
||
423 | 11460 | jlgomez | * @param params
|
424 | 8911 | jlgomez | */
|
425 | 11957 | dguerrero | public void setTransformationParams(String sourceParams, String targetParams){ |
426 | this.sourceTrParams = sourceParams;
|
||
427 | this.targetTrParams = targetParams;
|
||
428 | 7876 | jlgomez | } |
429 | |||
430 | 8911 | jlgomez | /**
|
431 | 18139 | jlgomez | * Devuelve los parametros de la transformacion del crs fuente
|
432 | 8911 | jlgomez | * @return
|
433 | */
|
||
434 | 18139 | jlgomez | public String getSourceTransformationParams() { |
435 | return this.sourceTrParams; |
||
436 | } |
||
437 | |||
438 | /**
|
||
439 | * Devuelve los parametros de la transformacion del crs destino
|
||
440 | * @return
|
||
441 | */
|
||
442 | public String getTargetTransformationParams() { |
||
443 | return this.targetTrParams; |
||
444 | } |
||
445 | |||
446 | /**
|
||
447 | * @return
|
||
448 | */
|
||
449 | 11810 | dguerrero | public String getTransformationParams(){ |
450 | 11957 | dguerrero | return this.sourceTrParams; |
451 | 7876 | jlgomez | } |
452 | 11045 | jlgomez | |
453 | 8911 | jlgomez | /**
|
454 | *
|
||
455 | * @return
|
||
456 | */
|
||
457 | 11460 | jlgomez | public CrsProj getCrsProj() {
|
458 | 18340 | jlgomez | if (crsProj == null) |
459 | try {
|
||
460 | crsProj = new CrsProj(getProj4String());
|
||
461 | } catch (CrsException e) {
|
||
462 | // TODO Auto-generated catch block
|
||
463 | e.printStackTrace(); |
||
464 | } |
||
465 | return crsProj;
|
||
466 | 6813 | mgarcia | } |
467 | |||
468 | 8911 | jlgomez | /**
|
469 | * @param x
|
||
470 | * @param y
|
||
471 | * @return
|
||
472 | */
|
||
473 | 6813 | mgarcia | public Point2D createPoint(double x, double y) { |
474 | return new Point2D.Double(x,y); |
||
475 | } |
||
476 | |||
477 | 8911 | jlgomez | /**
|
478 | * @param g
|
||
479 | * @param vp
|
||
480 | */
|
||
481 | 6813 | mgarcia | public void drawGrid(Graphics2D g, ViewPortData vp) { |
482 | // TODO Auto-generated method stub
|
||
483 | |||
484 | } |
||
485 | |||
486 | 8911 | jlgomez | /**
|
487 | * @param c
|
||
488 | */
|
||
489 | 6813 | mgarcia | public void setGridColor(Color c) { |
490 | 7904 | dguerrero | gridColor = c; |
491 | 6813 | mgarcia | } |
492 | |||
493 | 8911 | jlgomez | /**
|
494 | * @return
|
||
495 | */
|
||
496 | 6813 | mgarcia | public Color getGridColor() { |
497 | 7904 | dguerrero | return gridColor;
|
498 | 6813 | mgarcia | } |
499 | |||
500 | 8911 | jlgomez | /**
|
501 | * @param dest
|
||
502 | * @return
|
||
503 | */
|
||
504 | 6813 | mgarcia | public ICoordTrans getCT(IProjection dest) {
|
505 | 11813 | dguerrero | |
506 | 11957 | dguerrero | |
507 | 6813 | mgarcia | try {
|
508 | 22496 | dguerrero | if (dest == this) |
509 | return null; |
||
510 | 18139 | jlgomez | COperation operation = null;
|
511 | if(((ICrs)dest).getSourceTransformationParams() != null || ((ICrs)dest).getTargetTransformationParams() != null) |
||
512 | operation = new COperation(this, (ICrs)dest,((ICrs)dest).getTargetTransformationParams(),((ICrs)dest).getSourceTransformationParams()); |
||
513 | else
|
||
514 | operation = new COperation(this, (ICrs)dest,sourceTrParams,targetTrParams); |
||
515 | 11813 | dguerrero | return operation;
|
516 | }catch (CrsException e) {
|
||
517 | // TODO Auto-generated catch block
|
||
518 | e.printStackTrace(); |
||
519 | return null; |
||
520 | } |
||
521 | |||
522 | /*
|
||
523 | try {
|
||
524 | 8676 | dguerrero | operation = new COperation(this, (ICrs)dest);
|
525 | } catch (CrsException e) {
|
||
526 | // TODO Auto-generated catch block
|
||
527 | e.printStackTrace();
|
||
528 | }
|
||
529 | |||
530 | 11813 | dguerrero | if (getTransformationParams()!=null){
|
531 | 11460 | jlgomez | if (isTargetParams())
|
532 | 11813 | dguerrero | operation.setParamsCrsProj(new CrsProj(crsDest.getProj4String()+getTransformationParams()), true);
|
533 | 8676 | dguerrero | else
|
534 | 11813 | dguerrero | operation.setParamsCrsProj(new CrsProj(getProj4String()+getTransformationParams()), false);
|
535 | 8676 | dguerrero | |
536 | return operation;
|
||
537 | }
|
||
538 | |||
539 | 11813 | dguerrero | return operation; */
|
540 | 6813 | mgarcia | } |
541 | 8001 | dguerrero | |
542 | 8911 | jlgomez | /**
|
543 | * @param pt
|
||
544 | * @return
|
||
545 | */
|
||
546 | 6813 | mgarcia | public Point2D toGeo(Point2D pt) { |
547 | 8001 | dguerrero | if (isProjected()){
|
548 | double x[] = {pt.getX()}; |
||
549 | double y[] = {pt.getY()}; |
||
550 | double z[] = {0D}; |
||
551 | try {
|
||
552 | 8650 | dguerrero | JNIBaseCrs.operate( x , y, z, |
553 | 18340 | jlgomez | getCrsProj(),crsBase); |
554 | 8001 | dguerrero | } catch (OperationCrsException e) {
|
555 | // TODO Auto-generated catch block
|
||
556 | e.printStackTrace(); |
||
557 | } |
||
558 | return new Point2D.Double(x[0],y[0]); |
||
559 | } |
||
560 | else
|
||
561 | return pt;
|
||
562 | 6813 | mgarcia | } |
563 | |||
564 | 8911 | jlgomez | /**
|
565 | * @param gPt
|
||
566 | * @param mPt
|
||
567 | * @return
|
||
568 | */
|
||
569 | 6813 | mgarcia | public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
570 | // TODO Auto-generated method stub
|
||
571 | return null; |
||
572 | } |
||
573 | |||
574 | 8911 | jlgomez | /**
|
575 | * @return
|
||
576 | */
|
||
577 | 6813 | mgarcia | public boolean isProjected() { |
578 | 18340 | jlgomez | return !getCrsProj().isLatlong();
|
579 | 6813 | mgarcia | } |
580 | |||
581 | 8911 | jlgomez | /**
|
582 | * @param minX
|
||
583 | * @param maxX
|
||
584 | * @param width
|
||
585 | * @param dpi
|
||
586 | * @return
|
||
587 | */
|
||
588 | 6813 | mgarcia | public double getScale(double minX, double maxX, double width, double dpi) { |
589 | 8001 | dguerrero | double scale = 0D; |
590 | if (!isProjected()) { // Es geogr?fico; calcula la escala. |
||
591 | scale = ((maxX - minX) * // grados
|
||
592 | |||
593 | // 1852.0 metros x minuto de meridiano
|
||
594 | (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro |
||
595 | width; // pixels
|
||
596 | } |
||
597 | else{
|
||
598 | scale = ((maxX - minX) * // metros
|
||
599 | (dpi / 2.54 * 100.0)) / // px / metro |
||
600 | width; // pixels
|
||
601 | } |
||
602 | return scale;
|
||
603 | 6813 | mgarcia | } |
604 | |||
605 | 12026 | dguerrero | public double getScale(double minX, double maxX, double minY, double maxY, double width, double dpi) { |
606 | |||
607 | double scale = 0D; |
||
608 | double incX = (maxX-minX);
|
||
609 | |||
610 | if (!isProjected()) {
|
||
611 | double a = getDatum().getESemiMajorAxis();
|
||
612 | double invF = getDatum().getEIFlattening();
|
||
613 | double meanY = (minY+maxY)/2.0; |
||
614 | double radius = 0.0; |
||
615 | |||
616 | |||
617 | if (invF == Double.POSITIVE_INFINITY){ |
||
618 | radius = a; |
||
619 | } |
||
620 | else{
|
||
621 | double e2 = 2.0/invF-Math.pow(1.0/invF,2.0); |
||
622 | radius = a/Math.sqrt(1.0-e2*Math.pow(Math.sin(meanY*Math.PI/180.0),2.0))*Math.cos(meanY*Math.PI/180.0); |
||
623 | } |
||
624 | incX *= Math.PI/180.0*radius; |
||
625 | } |
||
626 | |||
627 | scale = (incX * // metros
|
||
628 | (dpi / 2.54 * 100.0)) / // px / metro |
||
629 | width; // pixels
|
||
630 | |||
631 | return scale;
|
||
632 | } |
||
633 | |||
634 | 8911 | jlgomez | /**
|
635 | *
|
||
636 | * @param epsg_cod
|
||
637 | */
|
||
638 | 6820 | jlgomez | public void setCode(int epsg_cod){ |
639 | epsg_code = epsg_cod; |
||
640 | } |
||
641 | |||
642 | 8911 | jlgomez | /**
|
643 | * @return
|
||
644 | */
|
||
645 | 6820 | jlgomez | public int getCode() { |
646 | // TODO Auto-generated method stub
|
||
647 | return epsg_code;
|
||
648 | } |
||
649 | 7404 | dguerrero | |
650 | 12201 | dguerrero | public String getFullCode() { |
651 | 12406 | dguerrero | if (this.sourceTrParams == null && this.targetTrParams == null) |
652 | return getAbrev();
|
||
653 | String sourceParams = ""; |
||
654 | String targetParams = ""; |
||
655 | if (sourceTrParams != null) |
||
656 | sourceParams = sourceTrParams; |
||
657 | if (targetTrParams != null) |
||
658 | targetParams = targetTrParams; |
||
659 | |||
660 | return getAbrev()+":proj@"+sourceParams+"@"+targetParams; |
||
661 | 12201 | dguerrero | } |
662 | 18139 | jlgomez | |
663 | |||
664 | 28835 | vcaballero | public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi) { |
665 | double w =0; |
||
666 | double h =0; |
||
667 | double wExtent =0; |
||
668 | double hExtent =0; |
||
669 | if (isProjected()) {
|
||
670 | w = ((wImage / dpi) * 2.54);
|
||
671 | h = ((hImage / dpi) * 2.54);
|
||
672 | wExtent =w * scale*distanceUnits/ mapUnits; |
||
673 | hExtent =h * scale*distanceUnits/ mapUnits; |
||
674 | |||
675 | }else {
|
||
676 | w = ((wImage / dpi) * 2.54);
|
||
677 | h = ((hImage / dpi) * 2.54);
|
||
678 | wExtent =(w*scale*distanceUnits)/ (mapUnits*1852.0*60.0); |
||
679 | hExtent =(h*scale*distanceUnits)/ (mapUnits*1852.0*60.0); |
||
680 | } |
||
681 | double xExtent = extent.getCenterX() - wExtent/2; |
||
682 | double yExtent = extent.getCenterY() - hExtent/2; |
||
683 | Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent); |
||
684 | return rec;
|
||
685 | } |
||
686 | |||
687 | 18340 | jlgomez | private Proj4 getProj4() {
|
688 | if (proj4 == null) |
||
689 | try {
|
||
690 | proj4 = new Proj4();
|
||
691 | } catch (CrsException e) {
|
||
692 | // TODO Auto-generated catch block
|
||
693 | e.printStackTrace(); |
||
694 | } |
||
695 | return proj4;
|
||
696 | } |
||
697 | 7876 | jlgomez | |
698 | 18340 | jlgomez | /**
|
699 | *
|
||
700 | * @return Cadena proj4 Correspondiente al CRS.
|
||
701 | * @throws CrsException
|
||
702 | */
|
||
703 | public String getProj4String() throws CrsException { |
||
704 | if (proj4String == null) |
||
705 | proj4String = getProj4().exportToProj4(this);
|
||
706 | return proj4String;
|
||
707 | } |
||
708 | 6813 | mgarcia | } |