svn-gvsig-desktop / tags / v1_1_Build_1013 / libraries / libJCRS / src / org / gvsig / crs / Crs.java @ 13521
History | View | Annotate | Download (18.7 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 | import org.gvsig.crs.ogr.CrsOgr; |
||
53 | import org.gvsig.crs.ogr.CrsOgrException; |
||
54 | import org.gvsig.crs.ogr.OGRException; |
||
55 | import org.gvsig.crs.ogr.OGRSpatialReference; |
||
56 | import org.gvsig.crs.ogr.crsgdalException; |
||
57 | 8405 | dguerrero | import org.gvsig.crs.proj.CrsProj; |
58 | 8650 | dguerrero | import org.gvsig.crs.proj.JNIBaseCrs; |
59 | 8405 | dguerrero | import org.gvsig.crs.proj.OperationCrsException; |
60 | 6813 | mgarcia | |
61 | 8878 | jlgomez | /**
|
62 | * Clase que construye el CRS a partir de la cadena WKT
|
||
63 | * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
|
||
64 | * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
||
65 | * @author Miguel Garc?a Jim?nez (garciajimenez.miguel@gmail.com)
|
||
66 | *
|
||
67 | */
|
||
68 | 6813 | mgarcia | public class Crs implements ICrs { |
69 | 7904 | dguerrero | private static final Color basicGridColor = new Color(64, 64, 64, 128); |
70 | 13345 | dguerrero | private String proj4; |
71 | private String proj4Base; |
||
72 | private String trans; |
||
73 | private String abrev; |
||
74 | private CrsProj crsProj4 = null; |
||
75 | private CrsProj crsBase = null; |
||
76 | private CrsWkt crsWkt;
|
||
77 | private int epsg_code = 23030; |
||
78 | boolean targetNad = false; |
||
79 | String TransParam = ""; |
||
80 | String wkt = null; |
||
81 | Color gridColor = basicGridColor;
|
||
82 | CRSDatum datum = null;
|
||
83 | 6813 | mgarcia | |
84 | 8426 | dguerrero | /**
|
85 | * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
||
86 | *
|
||
87 | * @param code
|
||
88 | * @throws CrsException
|
||
89 | */
|
||
90 | 6813 | mgarcia | public Crs(String code) throws CrsException { |
91 | String fullCode;
|
||
92 | 7876 | jlgomez | setWKT(code); |
93 | 6813 | mgarcia | if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
94 | fullCode = code; |
||
95 | else fullCode = "EPSG:"+code; |
||
96 | if(code.length() < 15 ) { |
||
97 | code = code.substring(code.indexOf(":")+1); |
||
98 | try {
|
||
99 | //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
||
100 | crsWkt = new CrsWkt(fullCode);
|
||
101 | OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
||
102 | CrsOgr.importFromEPSG(oSRSSource, |
||
103 | Integer.parseInt(code));
|
||
104 | proj4 = CrsOgr.exportToProj4(oSRSSource); |
||
105 | 13345 | dguerrero | oSRSSource.deleteOGRSpatialReference(); |
106 | 6813 | mgarcia | setAbrev(fullCode); |
107 | |||
108 | } catch (OGRException e) {
|
||
109 | throw new CrsException(e); |
||
110 | } catch (crsgdalException e) {
|
||
111 | throw new CrsException(e); |
||
112 | } catch (CrsOgrException e) {
|
||
113 | throw new CrsException(e); |
||
114 | } |
||
115 | }else {
|
||
116 | String aux;
|
||
117 | String code2 = ""; |
||
118 | for(int i = 0; i < code.length(); i++) { |
||
119 | aux = ""+code.charAt(i);
|
||
120 | if(!aux.equals(" ")) { |
||
121 | code2+=aux; |
||
122 | }else {
|
||
123 | code2 += "";
|
||
124 | } |
||
125 | } |
||
126 | crsWkt = new CrsWkt(code2);
|
||
127 | try {
|
||
128 | OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
||
129 | CrsOgr.importFromWkt(oSRSSource,code2); |
||
130 | proj4 =CrsOgr.exportToProj4(oSRSSource); |
||
131 | 13345 | dguerrero | oSRSSource.deleteOGRSpatialReference(); |
132 | 8433 | dguerrero | //setAbrev(crsWkt.getName());
|
133 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
134 | 6813 | mgarcia | } catch (OGRException e) {
|
135 | throw new CrsException(e); |
||
136 | } catch (crsgdalException e) {
|
||
137 | throw new CrsException(e); |
||
138 | } catch (CrsOgrException e) {
|
||
139 | throw new CrsException(e); |
||
140 | } |
||
141 | } |
||
142 | 8426 | dguerrero | // Asignar el datum y el crs base (en el caso de ser projectado):
|
143 | 7904 | dguerrero | if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
144 | double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
||
145 | double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
||
146 | datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
||
147 | 8001 | dguerrero | |
148 | //crs base (en el caso de ser projectado):
|
||
149 | if(this.isProjected()){ |
||
150 | 13345 | dguerrero | proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ; |
151 | 8001 | dguerrero | } |
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 | if(code.length() < 15 ) { |
||
170 | code = code.substring(code.indexOf(":")+1); |
||
171 | try {
|
||
172 | //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
||
173 | crsWkt = new CrsWkt(fullCode);
|
||
174 | OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
||
175 | CrsOgr.importFromEPSG(oSRSSource, |
||
176 | Integer.parseInt(code));
|
||
177 | proj4 = CrsOgr.exportToProj4(oSRSSource); |
||
178 | 13345 | dguerrero | oSRSSource.deleteOGRSpatialReference(); |
179 | 6820 | jlgomez | setAbrev(fullCode); |
180 | |||
181 | } catch (OGRException e) {
|
||
182 | throw new CrsException(e); |
||
183 | } catch (crsgdalException e) {
|
||
184 | throw new CrsException(e); |
||
185 | } catch (CrsOgrException e) {
|
||
186 | throw new CrsException(e); |
||
187 | } |
||
188 | }else {
|
||
189 | String aux;
|
||
190 | String code2 = ""; |
||
191 | for(int i = 0; i < code.length(); i++) { |
||
192 | aux = ""+code.charAt(i);
|
||
193 | if(!aux.equals(" ")) { |
||
194 | code2+=aux; |
||
195 | }else {
|
||
196 | code2 += "";
|
||
197 | } |
||
198 | } |
||
199 | crsWkt = new CrsWkt(code2);
|
||
200 | 8489 | jlgomez | /*
|
201 | * Arreglo temporal para ver si funcionan de la iau2000 las proyecciones
|
||
202 | * cilindrica equidistante y oblicua cilindrica equidistante
|
||
203 | * que no estan en gdal, por lo que asignaremos directamente su cadena
|
||
204 | * en proj4 para trabajar con ellas
|
||
205 | */
|
||
206 | if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){ |
||
207 | try {
|
||
208 | OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
||
209 | CrsOgr.importFromWkt(oSRSSource,code2); |
||
210 | proj4 = CrsOgr.exportToProj4(oSRSSource); |
||
211 | 13345 | dguerrero | oSRSSource.deleteOGRSpatialReference(); |
212 | 8489 | jlgomez | //setAbrev(crsWkt.getName());
|
213 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
214 | } catch (OGRException e) {
|
||
215 | throw new CrsException(e); |
||
216 | } catch (crsgdalException e) {
|
||
217 | throw new CrsException(e); |
||
218 | } catch (CrsOgrException e) {
|
||
219 | throw new CrsException(e); |
||
220 | } |
||
221 | } |
||
222 | else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){ |
||
223 | String spheroid1 = crsWkt.getSpheroid()[1]; |
||
224 | String spheroid2 = crsWkt.getSpheroid()[2]; |
||
225 | 8655 | jlgomez | String centralMeridian = ""; |
226 | String falseNorthing = ""; |
||
227 | String falseEasting = ""; |
||
228 | String standardParallel1 = "0.0"; |
||
229 | for (int i=0; i<crsWkt.getParam_name().length;i++){ |
||
230 | if (crsWkt.getParam_name()[i].equals("Central_Meridian")) |
||
231 | centralMeridian = crsWkt.getParam_value()[i]; |
||
232 | if (crsWkt.getParam_name()[i].equals("False_Easting")) |
||
233 | falseEasting = crsWkt.getParam_value()[i]; |
||
234 | if(crsWkt.getParam_name()[i].equals("False_Northing")) |
||
235 | falseNorthing = crsWkt.getParam_value()[i]; |
||
236 | if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1")) |
||
237 | standardParallel1 = crsWkt.getParam_value()[i]; |
||
238 | } |
||
239 | if (spheroid2.equals("0.0")){ |
||
240 | 8489 | jlgomez | proj4 = "+proj=eqc +a=" + spheroid1 +
|
241 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
242 | " +lat_ts="+standardParallel1;
|
||
243 | 8489 | jlgomez | } else {
|
244 | proj4 = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 + |
||
245 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
246 | " +lat_ts="+standardParallel1;
|
||
247 | 8489 | jlgomez | } |
248 | |||
249 | 8426 | dguerrero | //setAbrev(crsWkt.getName());
|
250 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
251 | 8489 | jlgomez | |
252 | 6820 | jlgomez | } |
253 | 8489 | jlgomez | else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){ |
254 | String spheroid1 = crsWkt.getSpheroid()[1]; |
||
255 | String spheroid2 = crsWkt.getSpheroid()[2]; |
||
256 | 8655 | jlgomez | String centralMeridian = ""; |
257 | String falseNorthing = ""; |
||
258 | String falseEasting = ""; |
||
259 | String standardParallel1 = ""; |
||
260 | String standardParallel2 = "0.0"; |
||
261 | for (int i=0; i<crsWkt.getParam_name().length;i++){ |
||
262 | if (crsWkt.getParam_name()[i].equals("Central_Meridian")) |
||
263 | centralMeridian = crsWkt.getParam_value()[i]; |
||
264 | if (crsWkt.getParam_name()[i].equals("False_Easting")) |
||
265 | falseEasting = crsWkt.getParam_value()[i]; |
||
266 | if(crsWkt.getParam_name()[i].equals("False_Northing")) |
||
267 | falseNorthing = crsWkt.getParam_value()[i]; |
||
268 | if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1")) |
||
269 | standardParallel1 = crsWkt.getParam_value()[i]; |
||
270 | if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2")) |
||
271 | standardParallel2 = crsWkt.getParam_value()[i]; |
||
272 | } |
||
273 | if (spheroid2.equals("0.0")){ |
||
274 | 8489 | jlgomez | proj4 = "+proj=ocea +a="+ spheroid1 +
|
275 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
276 | " +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" + |
||
277 | " +lon_2=long_2 +no_defs";
|
||
278 | 8489 | jlgomez | } else {
|
279 | proj4 = "+proj=ocea +a="+ spheroid1 + " +rf=" + spheroid2 + |
||
280 | 8655 | jlgomez | " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
281 | " +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" + |
||
282 | 8489 | jlgomez | " +lon_2=long_2 +no_defs";
|
283 | } |
||
284 | |||
285 | //setAbrev(crsWkt.getName());
|
||
286 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
287 | } |
||
288 | 6820 | jlgomez | } |
289 | 7904 | dguerrero | // Asignar el datum:
|
290 | 8001 | dguerrero | if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
291 | double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
||
292 | double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
||
293 | datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
||
294 | |||
295 | // Crs base (en el caso de ser projectado):
|
||
296 | if(this.isProjected()){ |
||
297 | 13345 | dguerrero | proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ; |
298 | 8001 | dguerrero | } |
299 | } |
||
300 | 6820 | jlgomez | } |
301 | |||
302 | 8426 | dguerrero | /**
|
303 | * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
||
304 | * En el caso de WKT le a?ade a la cadena proj4 el string params.
|
||
305 | *
|
||
306 | * @param epsg_cod
|
||
307 | * @param code
|
||
308 | * @param params
|
||
309 | * @throws CrsException
|
||
310 | */
|
||
311 | 6927 | mgarcia | public Crs(int epsg_cod, String code,String params) throws CrsException { |
312 | String fullCode;
|
||
313 | setCode(epsg_cod); |
||
314 | 7876 | jlgomez | setWKT(code); |
315 | 6927 | mgarcia | if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
316 | fullCode = code; |
||
317 | else fullCode = "EPSG:"+code; |
||
318 | if(code.length() < 15 ) { |
||
319 | code = code.substring(code.indexOf(":")+1); |
||
320 | try {
|
||
321 | //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
||
322 | crsWkt = new CrsWkt(fullCode);
|
||
323 | OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
||
324 | CrsOgr.importFromEPSG(oSRSSource, |
||
325 | Integer.parseInt(code));
|
||
326 | proj4 = CrsOgr.exportToProj4(oSRSSource); |
||
327 | 13345 | dguerrero | oSRSSource.deleteOGRSpatialReference(); |
328 | 6927 | mgarcia | setAbrev(fullCode); |
329 | |||
330 | } catch (OGRException e) {
|
||
331 | throw new CrsException(e); |
||
332 | } catch (crsgdalException e) {
|
||
333 | throw new CrsException(e); |
||
334 | } catch (CrsOgrException e) {
|
||
335 | throw new CrsException(e); |
||
336 | } |
||
337 | }else {
|
||
338 | String aux;
|
||
339 | String code2 = ""; |
||
340 | for(int i = 0; i < code.length(); i++) { |
||
341 | aux = ""+code.charAt(i);
|
||
342 | if(!aux.equals(" ")) { |
||
343 | code2+=aux; |
||
344 | }else {
|
||
345 | code2 += "";
|
||
346 | } |
||
347 | } |
||
348 | crsWkt = new CrsWkt(code2);
|
||
349 | try {
|
||
350 | OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
||
351 | CrsOgr.importFromWkt(oSRSSource,code2); |
||
352 | 7821 | jlgomez | proj4 =CrsOgr.exportToProj4(oSRSSource)+params+" ";
|
353 | 13345 | dguerrero | oSRSSource.deleteOGRSpatialReference(); |
354 | 8433 | dguerrero | //setAbrev(crsWkt.getName());
|
355 | setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
||
356 | 6927 | mgarcia | } catch (OGRException e) {
|
357 | throw new CrsException(e); |
||
358 | } catch (crsgdalException e) {
|
||
359 | throw new CrsException(e); |
||
360 | } catch (CrsOgrException e) {
|
||
361 | throw new CrsException(e); |
||
362 | } |
||
363 | } |
||
364 | 7904 | dguerrero | // Asignar el datum:
|
365 | 8001 | dguerrero | if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
366 | double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
||
367 | double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
||
368 | datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
||
369 | |||
370 | // Crs base (en el caso de ser projectado):
|
||
371 | if(this.isProjected()){ |
||
372 | 13345 | dguerrero | proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ; |
373 | 8001 | dguerrero | } |
374 | } |
||
375 | 6927 | mgarcia | } |
376 | 7876 | jlgomez | |
377 | 8029 | dguerrero | /* public Crs(CrsEpsg source) throws CrsException {
|
378 | 6813 | mgarcia | crsProj4 = source;
|
379 | 8029 | dguerrero | }*/
|
380 | 6813 | mgarcia | |
381 | 8911 | jlgomez | /**
|
382 | * @param code
|
||
383 | */
|
||
384 | 6813 | mgarcia | public void setTrans(String code) { |
385 | trans = code; |
||
386 | changeTrans(trans); |
||
387 | } |
||
388 | |||
389 | 8911 | jlgomez | /**
|
390 | *
|
||
391 | * @param code
|
||
392 | */
|
||
393 | 6813 | mgarcia | public void changeTrans(String code) { |
394 | 13345 | dguerrero | getCrsProj().changeStrCrs(code); |
395 | 6813 | mgarcia | } |
396 | |||
397 | 8911 | jlgomez | /**
|
398 | *
|
||
399 | */
|
||
400 | 6813 | mgarcia | public String getAbrev() { |
401 | return abrev;
|
||
402 | } |
||
403 | |||
404 | 8911 | jlgomez | /**
|
405 | *
|
||
406 | * @param code
|
||
407 | */
|
||
408 | 6813 | mgarcia | protected void setAbrev(String code) { |
409 | abrev = code; |
||
410 | } |
||
411 | |||
412 | |||
413 | 8911 | jlgomez | /**
|
414 | * @return
|
||
415 | */
|
||
416 | 6813 | mgarcia | public IDatum getDatum() {
|
417 | 7904 | dguerrero | /*CSDatum datum = new CSDatum();
|
418 | try {
|
||
419 | datum.fromWKT(getWKT());
|
||
420 | } catch (FactoryException e) {
|
||
421 | // TODO Auto-generated catch block
|
||
422 | e.printStackTrace();
|
||
423 | }*/
|
||
424 | return datum;
|
||
425 | 6813 | mgarcia | } |
426 | |||
427 | 8911 | jlgomez | /**
|
428 | * @return
|
||
429 | */
|
||
430 | 6813 | mgarcia | public CrsWkt getCrsWkt() {
|
431 | return crsWkt;
|
||
432 | } |
||
433 | |||
434 | 8911 | jlgomez | /**
|
435 | *
|
||
436 | * @param wkt
|
||
437 | */
|
||
438 | 7876 | jlgomez | public void setWKT(String wkt){ |
439 | this.wkt = wkt;
|
||
440 | 6813 | mgarcia | } |
441 | |||
442 | 8911 | jlgomez | /**
|
443 | * @return
|
||
444 | */
|
||
445 | 7876 | jlgomez | public String getWKT(){ |
446 | return this.wkt; |
||
447 | } |
||
448 | |||
449 | 8911 | jlgomez | /**
|
450 | *
|
||
451 | 11374 | dguerrero | * @param param
|
452 | 8911 | jlgomez | */
|
453 | 11374 | dguerrero | public void setTransParam(String param){ |
454 | this.TransParam = param;
|
||
455 | 7876 | jlgomez | } |
456 | |||
457 | 8911 | jlgomez | /**
|
458 | * @return
|
||
459 | */
|
||
460 | 11374 | dguerrero | public String getTransParam(){ |
461 | return this.TransParam; |
||
462 | 7876 | jlgomez | } |
463 | |||
464 | 8911 | jlgomez | /**
|
465 | * @param target
|
||
466 | * @return
|
||
467 | */
|
||
468 | 7876 | jlgomez | public ICOperation getCOp(ICrs target) throws CrsException { |
469 | 11374 | dguerrero | if (!this.getTransParam().equals("")) { |
470 | ICrs crs = new Crs(target.getCode(), target.getWKT(), this.getTransParam()); |
||
471 | 7876 | jlgomez | return new COperation(this, crs); |
472 | } |
||
473 | else return new COperation(this, target); |
||
474 | } |
||
475 | |||
476 | 8911 | jlgomez | /**
|
477 | *
|
||
478 | * @return
|
||
479 | */
|
||
480 | 8676 | dguerrero | protected CrsProj getCrsProj() {
|
481 | 13345 | dguerrero | if (crsProj4 ==null){ |
482 | crsProj4 = new CrsProj(getProj4());
|
||
483 | } |
||
484 | 6813 | mgarcia | return crsProj4;
|
485 | } |
||
486 | |||
487 | 8911 | jlgomez | /**
|
488 | * @param x
|
||
489 | * @param y
|
||
490 | * @return
|
||
491 | */
|
||
492 | 6813 | mgarcia | public Point2D createPoint(double x, double y) { |
493 | return new Point2D.Double(x,y); |
||
494 | } |
||
495 | |||
496 | 8911 | jlgomez | /**
|
497 | * @param g
|
||
498 | * @param vp
|
||
499 | */
|
||
500 | 6813 | mgarcia | public void drawGrid(Graphics2D g, ViewPortData vp) { |
501 | // TODO Auto-generated method stub
|
||
502 | |||
503 | } |
||
504 | |||
505 | 8911 | jlgomez | /**
|
506 | * @param c
|
||
507 | */
|
||
508 | 6813 | mgarcia | public void setGridColor(Color c) { |
509 | 7904 | dguerrero | gridColor = c; |
510 | 6813 | mgarcia | } |
511 | |||
512 | 8911 | jlgomez | /**
|
513 | * @return
|
||
514 | */
|
||
515 | 6813 | mgarcia | public Color getGridColor() { |
516 | 7904 | dguerrero | return gridColor;
|
517 | 6813 | mgarcia | } |
518 | |||
519 | 8911 | jlgomez | /**
|
520 | * @param dest
|
||
521 | * @return
|
||
522 | */
|
||
523 | 6813 | mgarcia | public ICoordTrans getCT(IProjection dest) {
|
524 | 8676 | dguerrero | COperation operation = null;
|
525 | Crs crsDest = (Crs)dest; |
||
526 | 6813 | mgarcia | try {
|
527 | 8676 | dguerrero | operation = new COperation(this, (ICrs)dest); |
528 | } catch (CrsException e) {
|
||
529 | // TODO Auto-generated catch block
|
||
530 | e.printStackTrace(); |
||
531 | } |
||
532 | |||
533 | 11374 | dguerrero | if (!getTransParam().equals("")){ |
534 | if (isTransInTarget())
|
||
535 | operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getTransParam()), true); |
||
536 | 8676 | dguerrero | else
|
537 | 11374 | dguerrero | operation.setNadCrsProj(new CrsProj(getProj4()+getTransParam()), false); |
538 | 8676 | dguerrero | |
539 | return operation;
|
||
540 | } |
||
541 | |||
542 | return operation;
|
||
543 | |||
544 | /*ICrs crs = (ICrs) dest;
|
||
545 | try {
|
||
546 | if (!this.getNadGrid().equals("")) {
|
||
547 | crs = new Crs(crs.getCode(), crs.getWKT(), this.getNadGrid());
|
||
548 | 7876 | jlgomez | return new COperation(this, crs);
|
549 | }
|
||
550 | else return new COperation(this, crs);
|
||
551 | 6813 | mgarcia | } catch (CrsException e) {
|
552 | // TODO Auto-generated catch block
|
||
553 | e.printStackTrace();
|
||
554 | }
|
||
555 | 8676 | dguerrero | return null;*/
|
556 | 6813 | mgarcia | } |
557 | 8001 | dguerrero | |
558 | 8911 | jlgomez | /**
|
559 | * @param pt
|
||
560 | * @return
|
||
561 | */
|
||
562 | 6813 | mgarcia | public Point2D toGeo(Point2D pt) { |
563 | 8001 | dguerrero | if (isProjected()){
|
564 | double x[] = {pt.getX()}; |
||
565 | double y[] = {pt.getY()}; |
||
566 | double z[] = {0D}; |
||
567 | try {
|
||
568 | 8650 | dguerrero | JNIBaseCrs.operate( x , y, z, |
569 | 13345 | dguerrero | getCrsProj(),getCrsBase()); |
570 | 8001 | dguerrero | } catch (OperationCrsException e) {
|
571 | // TODO Auto-generated catch block
|
||
572 | e.printStackTrace(); |
||
573 | } |
||
574 | return new Point2D.Double(x[0],y[0]); |
||
575 | } |
||
576 | else
|
||
577 | return pt;
|
||
578 | 6813 | mgarcia | } |
579 | |||
580 | 8911 | jlgomez | /**
|
581 | * @param gPt
|
||
582 | * @param mPt
|
||
583 | * @return
|
||
584 | */
|
||
585 | 6813 | mgarcia | public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
586 | // TODO Auto-generated method stub
|
||
587 | return null; |
||
588 | } |
||
589 | |||
590 | 8911 | jlgomez | /**
|
591 | * @return
|
||
592 | */
|
||
593 | 6813 | mgarcia | public boolean isProjected() { |
594 | 13345 | dguerrero | return !getCrsProj().isLatlong();
|
595 | 6813 | mgarcia | } |
596 | |||
597 | 8911 | jlgomez | /**
|
598 | * @param minX
|
||
599 | * @param maxX
|
||
600 | * @param width
|
||
601 | * @param dpi
|
||
602 | * @return
|
||
603 | */
|
||
604 | 6813 | mgarcia | public double getScale(double minX, double maxX, double width, double dpi) { |
605 | 8001 | dguerrero | double scale = 0D; |
606 | if (!isProjected()) { // Es geogr?fico; calcula la escala. |
||
607 | scale = ((maxX - minX) * // grados
|
||
608 | |||
609 | // 1852.0 metros x minuto de meridiano
|
||
610 | (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro |
||
611 | width; // pixels
|
||
612 | } |
||
613 | else{
|
||
614 | scale = ((maxX - minX) * // metros
|
||
615 | (dpi / 2.54 * 100.0)) / // px / metro |
||
616 | width; // pixels
|
||
617 | } |
||
618 | return scale;
|
||
619 | 6813 | mgarcia | } |
620 | |||
621 | 8911 | jlgomez | /**
|
622 | *
|
||
623 | * @param epsg_cod
|
||
624 | */
|
||
625 | 6820 | jlgomez | public void setCode(int epsg_cod){ |
626 | epsg_code = epsg_cod; |
||
627 | } |
||
628 | |||
629 | 8911 | jlgomez | /**
|
630 | * @return
|
||
631 | */
|
||
632 | 6820 | jlgomez | public int getCode() { |
633 | // TODO Auto-generated method stub
|
||
634 | return epsg_code;
|
||
635 | } |
||
636 | 7404 | dguerrero | |
637 | 8911 | jlgomez | /**
|
638 | *
|
||
639 | */
|
||
640 | 7404 | dguerrero | public Rectangle2D getExtent(Rectangle2D extent, double scale, double wImage, double hImage, double changeUnits, double dpi) { |
641 | 10346 | jlgomez | double w =0; |
642 | double h =0; |
||
643 | double wExtent =0; |
||
644 | double hExtent =0; |
||
645 | if (isProjected()) {
|
||
646 | w = ((wImage / dpi) * 2.54);
|
||
647 | h = ((hImage / dpi) * 2.54);
|
||
648 | wExtent =w * scale/ changeUnits; |
||
649 | hExtent =h * scale/ changeUnits; |
||
650 | |||
651 | }else {
|
||
652 | w = ((wImage / dpi) * 2.54);
|
||
653 | h = ((hImage / dpi) * 2.54);
|
||
654 | wExtent =(w*scale)/ (changeUnits*1852.0*60.0); |
||
655 | hExtent =(h*scale)/ (changeUnits*1852.0*60.0); |
||
656 | } |
||
657 | double xExtent = extent.getCenterX() - wExtent/2; |
||
658 | double yExtent = extent.getCenterY() - hExtent/2; |
||
659 | Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent); |
||
660 | return rec;
|
||
661 | 7404 | dguerrero | } |
662 | 8676 | dguerrero | |
663 | 8911 | jlgomez | /**
|
664 | * @return
|
||
665 | */
|
||
666 | 11374 | dguerrero | public boolean isTransInTarget() { |
667 | 8676 | dguerrero | return targetNad;
|
668 | } |
||
669 | |||
670 | 8911 | jlgomez | /**
|
671 | * @param targetNad
|
||
672 | */
|
||
673 | 11374 | dguerrero | public void setTransInTarget(boolean targetNad) { |
674 | 8676 | dguerrero | this.targetNad = targetNad;
|
675 | } |
||
676 | |||
677 | 8911 | jlgomez | /**
|
678 | *
|
||
679 | * @return
|
||
680 | */
|
||
681 | 8676 | dguerrero | public String getProj4() { |
682 | return proj4;
|
||
683 | } |
||
684 | 11374 | dguerrero | |
685 | public String getFullCode() { |
||
686 | if (!TransParam.equals("")) |
||
687 | if(isTransInTarget())
|
||
688 | return getAbrev()+":"+"proj@"+TransParam+"@1"; |
||
689 | else
|
||
690 | return getAbrev()+":"+"proj@"+TransParam+"@0"; |
||
691 | else
|
||
692 | return getAbrev();
|
||
693 | } |
||
694 | 13345 | dguerrero | |
695 | public String getProj4Base() { |
||
696 | return proj4Base;
|
||
697 | } |
||
698 | |||
699 | public CrsProj getCrsBase() {
|
||
700 | if (crsBase==null) |
||
701 | crsBase = new CrsProj(getProj4Base());
|
||
702 | return crsBase;
|
||
703 | } |
||
704 | 6813 | mgarcia | } |