Statistics
| Revision:

root / branches / F2 / libraries / libJCRS / src / org / gvsig / crs / Crs.java @ 11242

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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