Statistics
| Revision:

svn-gvsig-desktop / branches / F2 / libraries / libJCRS / src / org / gvsig / crs / Crs.java @ 11281

History | View | Annotate | Download (18.7 KB)

1
/* 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
package org.gvsig.crs;
42

    
43
import java.awt.Color;
44
import java.awt.Graphics2D;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47

    
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.geotools.referencing.CRS;
53
import org.gvsig.crs.proj.CrsProj;
54
import org.gvsig.crs.proj.CrsProjException;
55
import org.gvsig.crs.proj.JNIBaseCrs;
56
import org.gvsig.crs.proj.OperationCrsException;
57
import org.opengis.referencing.FactoryException;
58
import org.opengis.referencing.NoSuchAuthorityCodeException;
59
import org.opengis.referencing.crs.CoordinateReferenceSystem;
60

    
61
import es.gva.cit.jogr.CrsGdalException;
62
import es.gva.cit.jogr.CrsOgrException;
63
import es.gva.cit.jogr.OGRException;
64
import es.gva.cit.jogr.OGRSpatialReference;
65

    
66
/**
67
 * Clase que construye el CRS a partir de la cadena WKT
68
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
69
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
70
 * @author Miguel Garc?a Jim?nez (garciajimenez.miguel@gmail.com)
71
 *
72
 */
73
public class Crs implements ICrs {
74
        private static final Color basicGridColor = new Color(64, 64, 64, 128);
75
        private String proj4;
76
        private String trans;
77
        //private String transOrigin = "";
78
        private String abrev;
79
        private String name = "";
80
        private CrsProj crsProj4;
81
        private CrsProj crsBase = null;
82
        private CrsWkt crsWkt;
83
        private int epsg_code = 23030;
84
        boolean targetNad = false;
85
        String nad = "";
86
        String wkt = null;
87
        Color gridColor = basicGridColor;
88
        CRSDatum datum = null;
89
        private CoordinateReferenceSystem gtCrs;
90

    
91
        public Crs(int epsgCode, int aut) throws CrsException
92
        {
93
                String strEpsgCode = "";
94
                if (aut == 1) {
95
                        strEpsgCode="EPSG:"+epsgCode;                        
96
                } else if (aut == 2){
97
                        strEpsgCode="ESRI:"+epsgCode;
98
                } else if (aut == 3){
99
                        strEpsgCode="IAU2000:"+epsgCode;
100
                } else if (aut == 4) {
101
                        strEpsgCode="USR:"+epsgCode;
102
                } else System.out.println("Error, autorithy err?neo");
103
                crsWkt=new CrsWkt(strEpsgCode);
104
                setWKT(crsWkt.getWkt());
105
        }
106
        
107
        
108
        /**
109
         * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
110
         * 
111
         * @param code
112
         * @throws CrsException
113
         */
114
        public Crs(String code) throws CrsException {
115
                String fullCode;
116
                setWKT(code);
117
                if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
118
                        fullCode = code;
119
                else fullCode = "EPSG:"+code;
120
                String cod = "";
121
                if(code.length() < 15 ) {
122
                        code = code.substring(code.indexOf(":")+1);
123
                        try {
124
                                //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
125
                                crsWkt = new CrsWkt(fullCode);
126
                                OGRSpatialReference oSRSSource = new OGRSpatialReference();
127
                                oSRSSource.importFromEPSG(oSRSSource, 
128
                                                Integer.parseInt(code));
129
                                //Guardamos la cadena Proj4 devuelva por la OGRSpatialReference
130
                                proj4 = oSRSSource.exportToProj4(oSRSSource);
131
                                crsProj4 = new CrsProj(proj4);
132
                                setName(fullCode);
133
                                setAbrev(fullCode);
134
                                
135
                        } catch (OGRException e) {
136
                                throw new CrsException(e);
137
                        }  catch (CrsOgrException e) {
138
                                throw new CrsException(e);
139
                        } catch (NumberFormatException e) {
140
                                // TODO Auto-generated catch block
141
                                e.printStackTrace();
142
                        } catch (CrsGdalException e) {
143
                                // TODO Auto-generated catch block
144
                                e.printStackTrace();
145
                        }
146
                }else {
147
                        String aux;
148
                        String code2 = "";
149
                        for(int i = 0; i < code.length(); i++) {
150
                                aux = ""+code.charAt(i);
151
                                if(!aux.equals(" ")) {
152
                                        code2+=aux;
153
                                }else {
154
                                        code2 += "";
155
                                }
156
                        }
157
                        crsWkt = new CrsWkt(code2);
158
                    try {
159
                            OGRSpatialReference oSRSSource = new OGRSpatialReference();
160
                            oSRSSource.importFromWkt(oSRSSource,code2);
161
                            proj4 =oSRSSource.exportToProj4(oSRSSource);
162
                                crsProj4 = new CrsProj(proj4);
163
                            setName(fullCode);
164
                            //setAbrev(crsWkt.getName());
165
                            setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
166
                    } catch (OGRException e) {
167
                                throw new CrsException(e);
168
                        } catch (CrsOgrException e) {
169
                                throw new CrsException(e);
170
                        } catch (CrsGdalException e) {
171
                                // TODO Auto-generated catch block
172
                                e.printStackTrace();
173
                        }
174
                }
175
                //        Asignar el datum y el crs base (en el caso de ser projectado):
176
                if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
177
                        double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
178
                        double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
179
                        datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
180
                        
181
                        //crs base (en el caso de ser projectado):
182
                        if(this.isProjected()){
183
                                String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
184
                                crsBase = new CrsProj(proj4Base);
185
                        }
186
                }
187
        }        
188
        
189
        /**
190
         *Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
191
         * 
192
         * @param epsg_cod
193
         * @param code
194
         * @throws CrsException
195
         */
196
        public Crs(int epsg_cod, String code) throws CrsException {
197
                String fullCode;
198
                setWKT(code);
199
                setCode(epsg_cod);
200
                if(code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
201
                        fullCode = code;
202
                else fullCode = "EPSG:"+code;
203
                String cod = "";
204
                if(code.length() < 15 ) {
205
                        code = code.substring(code.indexOf(":")+1);
206
                        try {
207
                                //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
208
                                crsWkt = new CrsWkt(fullCode);
209
                                OGRSpatialReference oSRSSource = new OGRSpatialReference();
210
                                oSRSSource.importFromEPSG(oSRSSource, 
211
                                                Integer.parseInt(code));
212
                                //Guardamos la cadena Proj4 devuelva por la OGRSpatialReference
213
                                proj4 = oSRSSource.exportToProj4(oSRSSource);
214
                                crsProj4 = new CrsProj(proj4);
215
                                setName(fullCode);
216
                                setAbrev(fullCode);
217
                                
218
                        } catch (OGRException e) {
219
                                throw new CrsException(e);
220
                        } catch (CrsOgrException e) {
221
                                throw new CrsException(e);
222
                        } catch (NumberFormatException e) {
223
                                // TODO Auto-generated catch block
224
                                e.printStackTrace();
225
                        } catch (CrsGdalException e) {
226
                                // TODO Auto-generated catch block
227
                                e.printStackTrace();
228
                        }
229
                }else {
230
                        String aux;
231
                        String code2 = "";
232
                        for(int i = 0; i < code.length(); i++) {
233
                                aux = ""+code.charAt(i);
234
                                if(!aux.equals(" ")) {
235
                                        code2+=aux;
236
                                }else {
237
                                        code2 += "";
238
                                }
239
                        }
240
                        crsWkt = new CrsWkt(code2);
241
                        /*
242
                         * Arreglo temporal para ver si funcionan de la iau2000 las proyecciones
243
                         * cilindrica equidistante y oblicua cilindrica equidistante
244
                         * que no estan en gdal, por lo que asignaremos directamente su cadena
245
                         * en proj4 para trabajar con ellas
246
                         */
247
                        if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
248
                            try {
249
                                    OGRSpatialReference oSRSSource = new OGRSpatialReference();
250
                                    oSRSSource.importFromWkt(oSRSSource,code2);
251
                                    proj4 = oSRSSource.exportToProj4(oSRSSource);
252
                                        crsProj4 = new CrsProj(proj4);
253
                                    setName(fullCode);
254
                                    //setAbrev(crsWkt.getName());
255
                                    setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
256
                            } catch (OGRException e) {
257
                                        throw new CrsException(e);
258
                                } catch (CrsOgrException e) {
259
                                        throw new CrsException(e);
260
                                } catch (CrsGdalException e) {
261
                                        // TODO Auto-generated catch block
262
                                        e.printStackTrace();
263
                                }
264
                        }
265
                        else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){
266
                                String spheroid1 = crsWkt.getSpheroid()[1];
267
                                String spheroid2 = crsWkt.getSpheroid()[2];
268
                                String centralMeridian = "";
269
                                String falseNorthing = "";
270
                                String falseEasting = "";
271
                                String standardParallel1 = "0.0";
272
                                for (int i=0; i<crsWkt.getParam_name().length;i++){
273
                                        if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
274
                                                centralMeridian = crsWkt.getParam_value()[i];        
275
                                        if (crsWkt.getParam_name()[i].equals("False_Easting"))
276
                                                falseEasting = crsWkt.getParam_value()[i];                                        
277
                                        if(crsWkt.getParam_name()[i].equals("False_Northing"))
278
                                                falseNorthing = crsWkt.getParam_value()[i];                                        
279
                                        if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
280
                                                standardParallel1 = crsWkt.getParam_value()[i];                                        
281
                                }
282
                                if (spheroid2.equals("0.0")){
283
                                        proj4 = "+proj=eqc +a=" + spheroid1 +
284
                                        " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
285
                                        " +lat_ts="+standardParallel1;
286
                                } else {
287
                                        proj4 = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 +
288
                                        " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
289
                                        " +lat_ts="+standardParallel1;
290
                                }
291
                                
292
                                crsProj4 = new CrsProj(proj4);
293
                            setName(fullCode);
294
                            //setAbrev(crsWkt.getName());
295
                            setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
296
                                
297
                        }
298
                        else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
299
                                String spheroid1 = crsWkt.getSpheroid()[1];
300
                                String spheroid2 = crsWkt.getSpheroid()[2];
301
                                String centralMeridian = "";
302
                                String falseNorthing = "";
303
                                String falseEasting = "";
304
                                String standardParallel1 = "";
305
                                String standardParallel2 = "0.0";
306
                                for (int i=0; i<crsWkt.getParam_name().length;i++){                                        
307
                                        if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
308
                                                centralMeridian = crsWkt.getParam_value()[i];        
309
                                        if (crsWkt.getParam_name()[i].equals("False_Easting"))
310
                                                falseEasting = crsWkt.getParam_value()[i];                                        
311
                                        if(crsWkt.getParam_name()[i].equals("False_Northing"))
312
                                                falseNorthing = crsWkt.getParam_value()[i];                                        
313
                                        if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
314
                                                standardParallel1 = crsWkt.getParam_value()[i];
315
                                        if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2"))
316
                                                standardParallel2 = crsWkt.getParam_value()[i];                
317
                                }
318
                                if (spheroid2.equals("0.0")){
319
                                        proj4 = "+proj=ocea +a="+ spheroid1  +
320
                                        " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
321
                                        " +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
322
                                        " +lon_2=long_2 +no_defs";
323
                                } else {
324
                                        proj4 = "+proj=ocea +a="+ spheroid1 + " +rf=" + spheroid2 +
325
                                        " +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
326
                                        " +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
327
                                        " +lon_2=long_2 +no_defs";
328
                                }
329
                                
330
                                crsProj4 = new CrsProj(proj4);
331
                            setName(fullCode);
332
                            //setAbrev(crsWkt.getName());
333
                            setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
334
                        }
335
                }
336
                //        Asignar el datum:
337
                if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
338
                        double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
339
                        double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
340
                        datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
341
                        
342
                        // Crs base (en el caso de ser projectado):
343
                        if(this.isProjected()){
344
                                String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
345
                                crsBase = new CrsProj(proj4Base);
346
                        }
347
                }
348
        }
349
        
350
        /**
351
         * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
352
         * En el caso de WKT le a?ade a la cadena proj4 el string params.
353
         * 
354
         * @param epsg_cod
355
         * @param code
356
         * @param params
357
         * @throws CrsException
358
         */
359
        public Crs(int epsg_cod, String code,String params) throws CrsException {
360
                String fullCode;
361
                setCode(epsg_cod);
362
                setWKT(code);
363
                if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
364
                        fullCode = code;
365
                else fullCode = "EPSG:"+code;
366
                String cod = "";
367
                if(code.length() < 15 ) {
368
                        code = code.substring(code.indexOf(":")+1);
369
                        try {
370
                                //Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
371
                                crsWkt = new CrsWkt(fullCode);
372
                                OGRSpatialReference oSRSSource = new OGRSpatialReference();
373
                                oSRSSource.importFromEPSG(oSRSSource, 
374
                                                Integer.parseInt(code));
375
                                //Guardamos la cadena Proj4 devuelva por la OGRSpatialReference
376
                                proj4 = oSRSSource.exportToProj4(oSRSSource);
377
                                crsProj4 = new CrsProj(proj4);
378
                                setName(fullCode);
379
                                setAbrev(fullCode);
380
                                
381
                        } catch (OGRException e) {
382
                                throw new CrsException(e);
383
                        } catch (CrsOgrException e) {
384
                                throw new CrsException(e);
385
                        } catch (NumberFormatException e) {
386
                                // TODO Auto-generated catch block
387
                                e.printStackTrace();
388
                        } catch (CrsGdalException e) {
389
                                // TODO Auto-generated catch block
390
                                e.printStackTrace();
391
                        }
392
                }else {
393
                        String aux;
394
                        String code2 = "";
395
                        for(int i = 0; i < code.length(); i++) {
396
                                aux = ""+code.charAt(i);
397
                                if(!aux.equals(" ")) {
398
                                        code2+=aux;
399
                                }else {
400
                                        code2 += "";
401
                                }
402
                        }
403
                        crsWkt = new CrsWkt(code2);
404
                    try {
405
                            OGRSpatialReference oSRSSource = new OGRSpatialReference();
406
                            oSRSSource.importFromWkt(oSRSSource,code2);
407
                            proj4 =oSRSSource.exportToProj4(oSRSSource)+params+" ";
408
                                crsProj4 = new CrsProj(proj4);
409
                            setName(fullCode);
410
                            //setAbrev(crsWkt.getName());
411
                            setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
412
                    } catch (OGRException e) {
413
                                throw new CrsException(e);
414
                        } catch (CrsOgrException e) {
415
                                throw new CrsException(e);
416
                        } catch (CrsGdalException e) {
417
                                // TODO Auto-generated catch block
418
                                e.printStackTrace();
419
                        }
420
                }
421
                //        Asignar el datum:
422
                if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
423
                        double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
424
                        double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
425
                        datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
426
                        
427
                        // Crs base (en el caso de ser projectado):
428
                        if(this.isProjected()){
429
                                String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
430
                                crsBase = new CrsProj(proj4Base);
431
                        }
432
                }
433
        }
434
                
435
/*        public Crs(CrsEpsg source) throws CrsException {
436
                crsProj4 = source;
437
        }*/
438
        
439
        /**
440
         * @param code 
441
         */
442
        public void setTrans(String code) {
443
                trans = code;
444
                changeTrans(trans);
445
        }
446
        
447
        /**
448
         * 
449
         * @param code
450
         */
451
        public void changeTrans(String code) {
452
                crsProj4.changeStrCrs(code);
453
        }
454
        
455
        /**
456
         * 
457
         */
458
        public String getAbrev() {
459
                return abrev;
460
        }
461
        
462
        /**
463
         * 
464
         * @param code
465
         */
466
        protected void setAbrev(String code) {
467
                abrev = code;
468
        }
469
        
470
        /**
471
         * 
472
         * @param nom
473
         */
474
        public void setName(String nom) {
475
                name = nom;
476
        }
477
        
478
        /**
479
         * @return
480
         */
481
        public IDatum getDatum() {
482
                
483
                return datum;
484
        }
485
        
486
        /**
487
         * @return
488
         */
489
        public CrsWkt getCrsWkt() {
490
                return crsWkt;
491
        }
492
        
493
        /**
494
         * 
495
         * @param wkt
496
         */
497
        public void setWKT(String wkt){
498
                this.wkt = wkt;
499
        }
500
        
501
        /**
502
         * @return
503
         */
504
        public String getWKT(){
505
                return this.wkt;
506
        }
507
        
508
        /**
509
         * 
510
         * @param nad
511
         */
512
        public void setNadGrid(String nad){
513
                this.nad = nad;
514
        }
515
        
516
        /**
517
         * @return
518
         */
519
        public String getNadGrid(){
520
                return this.nad;
521
        }
522
                
523
        /**
524
         * 
525
         * @return
526
         */
527
        protected CrsProj getCrsProj() {
528
                return crsProj4;
529
        }
530

    
531
        /**
532
         * @param x
533
         * @param y
534
         * @return
535
         */
536
        public Point2D createPoint(double x, double y) {
537
                return new Point2D.Double(x,y);
538
        }
539

    
540
        /**
541
         * @param g
542
         * @param vp
543
         */
544
        public void drawGrid(Graphics2D g, ViewPortData vp) {
545
                // TODO Auto-generated method stub
546
                
547
        }
548

    
549
        /**
550
         * @param c
551
         */
552
        public void setGridColor(Color c) {
553
                gridColor = c;
554
        }
555

    
556
        /**
557
         * @return
558
         */
559
        public Color getGridColor() {
560
                return gridColor;
561
        }
562

    
563
        /**
564
         * @param dest
565
         * @return
566
         */
567
        public ICoordTrans getCT(IProjection dest) {
568
                COperation operation = null;
569
                Crs crsDest = (Crs)dest;
570
                try {
571
                        operation = new COperation(this, (ICrs)dest);
572
                } catch (CrsException e) {
573
                        // TODO Auto-generated catch block
574
                        e.printStackTrace();
575
                }
576
                
577
                if (!getNadGrid().equals("")){
578
                        if (isTargetNad())
579
                                operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getNadGrid()), true);
580
                        else
581
                                operation.setNadCrsProj(new CrsProj(getProj4()+getNadGrid()), false);
582
                        
583
                        return operation;
584
                }
585
                
586
                return operation;                
587
        }
588
        
589
        /**
590
         * @param pt
591
         * @return
592
         */
593
        public Point2D toGeo(Point2D pt) {
594
                if (isProjected()){
595
                        double x[] = {pt.getX()};
596
                        double y[] = {pt.getY()};
597
                        double z[] = {0D};
598
                        try {
599
                                JNIBaseCrs.operate( x , y, z,
600
                                                crsProj4,crsBase);
601
                        } catch (OperationCrsException e) {
602
                                // TODO Auto-generated catch block
603
                                e.printStackTrace();
604
                        } catch (CrsProjException e) {
605
                                // TODO Auto-generated catch block
606
                                e.printStackTrace();
607
                        }
608
                        return new Point2D.Double(x[0],y[0]);
609
                }
610
                else
611
                        return pt;
612
        }
613

    
614
        /**
615
         * @param gPt
616
         * @param mPt
617
         * @return
618
         */
619
        public Point2D fromGeo(Point2D gPt, Point2D mPt) {
620
                // TODO Auto-generated method stub
621
                return null;
622
        }
623

    
624
        /**
625
         * @return
626
         */
627
        public boolean isProjected() {
628
                return !crsProj4.isLatlong();                
629
        }
630

    
631
        /**
632
         * @param minX
633
         * @param maxX
634
         * @param width
635
         * @param dpi
636
         * @return
637
         */
638
        public double getScale(double minX, double maxX, double width, double dpi) {
639
                double scale = 0D;
640
        if (!isProjected()) { // Es geogr?fico; calcula la escala.
641
            scale = ((maxX - minX) * // grados
642

    
643
            // 1852.0 metros x minuto de meridiano
644
            (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro
645
                    width; // pixels
646
        }
647
        else{
648
                 scale = ((maxX - minX) * // metros
649
                    (dpi / 2.54 * 100.0)) / // px / metro
650
                    width; // pixels
651
        }
652
        return scale;
653
        }
654
        
655
        /**
656
         * 
657
         * @param epsg_cod
658
         */
659
        public void setCode(int epsg_cod){
660
                epsg_code = epsg_cod;
661
        }
662

    
663
        /**
664
         * @return
665
         */
666
        public int getCode() {
667
                // TODO Auto-generated method stub
668
                return epsg_code;
669
        }
670

    
671
        /**
672
         * 
673
         */
674
        public Rectangle2D getExtent(Rectangle2D extent, double scale, double wImage, double hImage, double changeUnits, double dpi) {
675
                // TODO Auto-generated method stub
676
                return null;
677
        }
678

    
679
        /**
680
         * @return
681
         */
682
        public boolean isTargetNad() {
683
                return targetNad;
684
        }
685

    
686
        /**
687
         * @param targetNad
688
         */
689
        public void setNadInTarget(boolean targetNad) {
690
                this.targetNad = targetNad;
691
        }
692

    
693
        /**
694
         * 
695
         * @return
696
         */
697
        public String getProj4() {
698
                return proj4;
699
        }
700
        
701
}