Statistics
| Revision:

root / branches / F2 / libraries / libJCRS / src / org / gvsig / crs / CrsWkt.java @ 11105

History | View | Annotate | Download (18.4 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.util.ArrayList;
44

    
45
import javax.units.ConversionException;
46
import javax.units.Unit;
47

    
48
import org.geotools.referencing.CRS;
49
import org.geotools.referencing.crs.DefaultGeographicCRS;
50
import org.geotools.referencing.crs.DefaultProjectedCRS;
51
import org.geotools.referencing.datum.DefaultEllipsoid;
52
import org.geotools.referencing.datum.DefaultGeodeticDatum;
53
import org.geotools.referencing.datum.DefaultPrimeMeridian;
54

    
55
import org.opengis.referencing.FactoryException;
56
import org.opengis.referencing.NoSuchAuthorityCodeException;
57
import org.opengis.referencing.NoSuchIdentifierException;
58
import org.opengis.referencing.crs.CoordinateReferenceSystem;
59
import org.opengis.referencing.datum.Ellipsoid;
60
import org.opengis.referencing.datum.PrimeMeridian;
61

    
62
/**
63
 * Clase que parsea una cadena wkt y consigue todos sus par?metros
64
 * de manera independiente para poder ser utilizados
65
 * en distintas funciones
66
 * 
67
 * @author Jos? Luis G?mez Mart?nez
68
 *
69
 */
70

    
71
public class CrsWkt {
72
        private String wkt;
73
        private String projcs = "";
74
        private String geogcs = "";
75
        private String datum = "";
76
        private String[] spheroid = {"" ,"",""};
77
        private String[] primem = {"",""};
78
        private String[] unit = {"",""};
79
        private String[] unit_p = {"",""}; //unidades de la projeccion (final de la cadena wkt)
80
        private String projection = "";
81
        private String[] param_name;
82
        private String[] param_value;
83
        private int contador = 0;
84
        private String[] authority = {"",""};
85
        
86
        int divider=10000;
87
        
88
        /**
89
     * Small tolerance factor for rounding errors.
90
     */
91
    private static final double EPS = 1E-8;
92
        
93
        public CrsWkt(String wkt_spaces) {
94
                String aux;
95
                String wkt = "";
96
                for(int i = 0; i < wkt_spaces.length(); i++) {
97
                        aux = ""+wkt_spaces.charAt(i);
98
                        if(!aux.equals(" ")) {
99
                                wkt+=aux;
100
                        }else {
101
                                wkt += "";
102
                        }
103
                }
104
                if (wkt.length()>15) {
105
                        fromWKT(wkt, false);
106
                } else {
107
                        fromCode(wkt);
108
                }
109
        }
110
        
111
        /**
112
         * Acepta la cadena wkt y si es un CRS proyectado para conseguir el parser
113
         * de los dos modelos de cadena wkt que se utilizan, una cuando es base
114
         * y otra cuando es proyectado
115
         * @param wkt
116
         * @param isProj
117
         */
118
        private void fromWKT(String wkt, boolean isProj) {
119
                
120
                String res = new String();
121
                if(!wkt.startsWith("EPSG:")) {
122
                        res = "";
123
                        for(; wkt.charAt(contador) != '"'; contador++) {
124
                                res += wkt.charAt(contador);
125
                        }
126
                        if(res.equals("GEOGCS[")) {
127
                                
128
                                contador++;
129
                                for(; wkt.charAt(contador) != '"'; contador++) {
130
                                        geogcs += wkt.charAt(contador);
131
                                }
132
                                
133
                                res = "";
134
                                contador++;
135
                                for(; wkt.charAt(contador) != '"'; contador++) {
136
                                        res += wkt.charAt(contador);
137
                                }
138
                                if(res.equals(",DATUM[")) {
139
                                        contador++;
140
                                        for(; wkt.charAt(contador) != '"'; contador++) {
141
                                                datum += wkt.charAt(contador);
142
                                        }
143
                                }
144
                                res = "";
145
                                contador++;
146
                                for(; wkt.charAt(contador) != '"'; contador++) {
147
                                        res += wkt.charAt(contador);
148
                                }
149
                                if(res.equals(",SPHEROID[")) {
150
                                        contador++;
151
                                        for(; wkt.charAt(contador) != ']'; contador++) {
152
                                                while(wkt.charAt(contador) != '"' ) {
153
                                                        spheroid[0] += wkt.charAt(contador);
154
                                                        contador++;
155
                                                }
156
                                                contador +=2;
157
                                                while(wkt.charAt(contador) != ',') {
158
                                                        spheroid[1] += wkt.charAt(contador);
159
                                                        contador++;
160
                                                }
161
                                                contador++;
162
                                                while(wkt.charAt(contador) != ']') {
163
                                                        spheroid[2] += wkt.charAt(contador);
164
                                                        contador++;
165
                                                }
166
                                        }
167
                                }
168
                                contador++;
169
                                res = "";
170
                                for(; wkt.charAt(contador) != '"'; contador++) {
171
                                        res += wkt.charAt(contador);
172
                                }
173
                                if(res.equals(",PRIMEM[")) {
174
                                        contador++;
175
                                        for(; wkt.charAt(contador) != ','; contador++) {
176
                                                while(wkt.charAt(contador) != '"' ){
177
                                                        primem[0] += wkt.charAt(contador);
178
                                                        contador ++;
179
                                                }
180
                                                contador +=2;
181
                                                while(wkt.charAt(contador) != ']') {
182
                                                        primem[1] += wkt.charAt(contador);
183
                                                        contador ++;
184
                                                }
185
                                        }
186
                                }
187
                                contador++;
188
                                res = "";
189
                                for(; wkt.charAt(contador) != '"'; contador++) {
190
                                        res += wkt.charAt(contador);
191
                                }
192
                                if(res.equals("UNIT[")) {
193
                                        contador++;
194
                                        for(; wkt.charAt(contador) != ','; contador++) {
195
                                                while(wkt.charAt(contador) != '"' ){
196
                                                        unit[0] += wkt.charAt(contador);
197
                                                        contador ++;
198
                                                }
199
                                                contador +=2;
200
                                                while(wkt.charAt(contador) != ']') {
201
                                                        unit[1] += wkt.charAt(contador);
202
                                                        contador ++;
203
                                                }
204
                                        }
205
                                }
206
                                contador++;
207
                                res = "";
208
                                for(; wkt.charAt(contador) != '"'; contador++) {
209
                                        res += wkt.charAt(contador);
210
                                }
211
                                if(res.equals("AUTHORITY[")) {
212
                                        contador++;
213
                                        for(; wkt.charAt(contador) != ']'; contador++) {
214
                                                while(wkt.charAt(contador) != '"' ){
215
                                                        authority[0] += wkt.charAt(contador);
216
                                                        contador ++;
217
                                                }
218
                                                contador +=2;
219
                                                while(wkt.charAt(contador) != ']') {
220
                                                        authority[1] += wkt.charAt(contador);
221
                                                        contador ++;
222
                                                }
223
                                        }
224
                                }
225
                        }else if (res.equals("PROJCS[")) {
226
                                contador++;
227
                                for(; wkt.charAt(contador) != '"'; contador++) {
228
                                        projcs += wkt.charAt(contador);
229
                                }
230
                                contador++;
231
                                res = "";
232
                                for(; wkt.charAt(contador) != '"'; contador++) {
233
                                        res += wkt.charAt(contador);
234
                                }
235
                                if(res.equals(",GEOGCS[")) {
236
                                        contador++;
237
                                        for(; wkt.charAt(contador) != '"'; contador++) {
238
                                                geogcs += wkt.charAt(contador);
239
                                        }
240
                                }
241
                                                                
242
                                res = "";
243
                                contador++;
244
                                for(; wkt.charAt(contador) != '"'; contador++) {
245
                                        res += wkt.charAt(contador);
246
                                }
247
                                if(res.equals(",DATUM[")) {
248
                                        contador++;
249
                                        for(; wkt.charAt(contador) != '"'; contador++) {
250
                                                datum += wkt.charAt(contador);
251
                                        }
252
                                }
253
                                res = "";
254
                                contador++;
255
                                for(; wkt.charAt(contador) != '"'; contador++) {
256
                                        res += wkt.charAt(contador);
257
                                }
258
                                if(res.equals(",SPHEROID[")) {
259
                                        contador++;
260
                                        for(; wkt.charAt(contador) != ']'; contador++) {
261
                                                while(wkt.charAt(contador) != '"' ) {
262
                                                        spheroid[0] += wkt.charAt(contador);
263
                                                        contador++;
264
                                                }
265
                                                contador +=2;
266
                                                while(wkt.charAt(contador) != ',') {
267
                                                        spheroid[1] += wkt.charAt(contador);
268
                                                        contador++;
269
                                                }
270
                                                contador++;
271
                                                while(wkt.charAt(contador) != ']') {
272
                                                        spheroid[2] += wkt.charAt(contador);
273
                                                        contador++;
274
                                                }
275
                                        }
276
                                }
277
                                contador++;
278
                                res = "";
279
                                for(; wkt.charAt(contador) != '"'; contador++) {
280
                                        res += wkt.charAt(contador);
281
                                }
282
                                if(res.equals(",PRIMEM[")) {
283
                                        contador++;
284
                                        for(; wkt.charAt(contador) != ','; contador++) {
285
                                                while(wkt.charAt(contador) != '"' ){
286
                                                        primem[0] += wkt.charAt(contador);
287
                                                        contador ++;
288
                                                }
289
                                                contador +=2;
290
                                                while(wkt.charAt(contador) != ']') {
291
                                                        primem[1] += wkt.charAt(contador);
292
                                                        contador ++;
293
                                                }
294
                                        }
295
                                }
296
                                contador++;
297
                                res = "";
298
                                for(; wkt.charAt(contador) != '"'; contador++) {
299
                                        res += wkt.charAt(contador);
300
                                }
301
                                if(res.equals("UNIT[")) {
302
                                        contador++;
303
                                        for(; wkt.charAt(contador) != ']'; contador++) {
304
                                                while(wkt.charAt(contador) != '"' ){
305
                                                        unit[0] += wkt.charAt(contador);
306
                                                        contador ++;
307
                                                }
308
                                                contador +=2;
309
                                                while(wkt.charAt(contador) != ']') {
310
                                                        unit[1] += wkt.charAt(contador);
311
                                                        contador ++;
312
                                                }
313
                                        }
314
                                }
315
                                contador++;
316
                                res = "";
317
                                for(; wkt.charAt(contador) != '"'; contador++) {
318
                                        res += wkt.charAt(contador);
319
                                }
320
                                if(res.equals(",PROJECTION[")) {
321
                                        contador++;
322
                                        for(; wkt.charAt(contador) != '"'; contador++) {
323
                                                projection += wkt.charAt(contador);
324
                                        }
325
                                }
326
                                contador = contador+2;
327
                                res = "";
328
                                for(; wkt.charAt(contador) != '"'; contador++) {
329
                                        res += wkt.charAt(contador);
330
                                }
331
                                //Hallamos el numero de parametros que tiene la cadena wkt
332
                                int i = 0;
333
                                
334
                                int copiacontador = contador;
335
                                if(res.equals(",PARAMETER[")) {
336
                                        do{
337
                                                for(; wkt.charAt(copiacontador) != ']'; copiacontador++) {
338
                                                        while(wkt.charAt(copiacontador) != '"' )
339
                                                                copiacontador++;
340
                                                        copiacontador += 2;
341
                                                        while(wkt.charAt(copiacontador) != ']' )
342
                                                                copiacontador++;
343
                                                        copiacontador--;
344
                                                }
345
                                                i++;
346
                                                copiacontador++;
347
                                                res = "";
348
                                                for(; wkt.charAt(copiacontador) != '"'; copiacontador++) {
349
                                                        res += wkt.charAt(copiacontador);
350
                                                }
351
                                        } while (res.equals(",PARAMETER["));
352
                                        res = ",PARAMETER[";
353
                                }
354
                                // Inicializamos los parametros
355
                                param_name = new String[i];
356
                                param_value = new String[i];
357
                                for(int j = 0 ;j < i; j++ ){
358
                                        param_name[j] = "";
359
                                        param_value[j] = "";
360
                                }
361
                                i = 0;
362
                                if(res.equals(",PARAMETER[")) {
363
                                        do{
364
                                                contador++;
365
                                                for(; wkt.charAt(contador) != ']'; contador++) {
366
                                                        while(wkt.charAt(contador) != '"' ){
367
                                                                param_name[i] += wkt.charAt(contador);
368
                                                                contador++;
369
                                                        }
370
                                                        contador += 2;
371
                                                        while(wkt.charAt(contador) != ']' ){
372
                                                                param_value[i] += wkt.charAt(contador);
373
                                                                contador++;
374
                                                        }
375
                                                        contador--;
376
                                                }
377
                                                i++;
378
                                                contador++;
379
                                                res = "";
380
                                                for(; wkt.charAt(contador) != '"'; contador++) {
381
                                                        res += wkt.charAt(contador);
382
                                                }
383
                                        } while (res.equals(",PARAMETER["));                                        
384
                                }
385
                                
386
                                if (res.equals(",UNIT[")){
387
                                        contador++;
388
                                        for(; wkt.charAt(contador) != ','; contador++) {
389
                                                while(wkt.charAt(contador) != '"' ){
390
                                                        unit_p[0] += wkt.charAt(contador);
391
                                                        contador ++;
392
                                                }
393
                                                contador +=2;
394
                                                while(wkt.charAt(contador) != ']') {
395
                                                        unit_p[1] += wkt.charAt(contador);
396
                                                        contador ++;
397
                                                }
398
                                        }
399
                                }
400
                                contador++;
401
                                res = "";
402
                                for(; wkt.charAt(contador) != '"'; contador++) {
403
                                        res += wkt.charAt(contador);
404
                                }
405
                                if(res.equals("AUTHORITY[")) {
406
                                        contador++;
407
                                        for(; wkt.charAt(contador) != ']'; contador++) {
408
                                                while(wkt.charAt(contador) != '"' ){
409
                                                        authority[0] += wkt.charAt(contador);
410
                                                        contador ++;
411
                                                }
412
                                                contador +=2;
413
                                                while(wkt.charAt(contador) != ']') {
414
                                                        authority[1] += wkt.charAt(contador);
415
                                                        contador ++;
416
                                                }
417
                                        }
418
                                }
419
                        }
420
                        else if (res.equals("GEOCCS[")){
421
                                /*
422
                                 * parte necesaria para capturar la cadena geocentrica...
423
                                 */
424
                                
425
                        }
426
                }else
427
                        geogcs = wkt;
428
        }
429
        
430
        public String getProjection() {
431
                return projection;
432
        }
433
        
434
        public String getProjcs() {
435
                return projcs;
436
        }
437
        
438
        public String getGeogcs() {
439
                return geogcs;
440
        }
441
        
442
        public String getDatumName() {
443
                return datum;
444
        }
445
        
446
        public String[] getSpheroid() {
447
                return spheroid;
448
        }
449
        
450
        public String[] getPrimen() {
451
                return primem;
452
        }
453
        
454
        public String getName() {
455
                if(projcs == "") 
456
                        return geogcs;
457
                return projcs;
458
        }
459
        
460
        public String[] getUnit() {
461
                return unit;
462
        }
463
        
464
        public String[] getUnit_p() {
465
                return unit_p;
466
        }
467
        
468
        public String[] getParam_name() {
469
                return param_name;
470
        }
471
        
472
        public String[] getParam_value() {
473
                return param_value;
474
        }
475
        
476
        public String[] getAuthority(){
477
                return authority;
478
        }
479
        
480
        /*
481
         * Parser a medio hacer, orientado a objeto y recursivo.
482
         * by LWS.
483
         */
484
        
485
        public static class WKT {
486
                public class Param {
487
                        String key;
488
                        ArrayList values = new ArrayList();
489
                        ArrayList params = new ArrayList();
490
                        public int pos = 0;
491
                        public Param(String key) {
492
                                this.key = key;
493
                        }
494
                        public void addValue(String name) {
495
                                values.add(name);
496
                        }
497
                        public void addParam(Param p) {
498
                                params.add(p);
499
                        }
500
                }
501
                String data;
502
                public WKT(String data) {
503
                        this.data = data;
504
                        WKT.Param param = parseParam(0);
505
                }
506
                private WKT.Param parseParam(int pos) {
507
                        WKT.Param param = null;
508
                        String key, name;
509
                        
510
                        int l = data.length();
511
                        for (int i = pos; i<l;) {
512
                                int nextParam = data.indexOf(",", i);
513
                                if (nextParam == i) {
514
                                        nextParam = data.indexOf(",", ++i);
515
                                }
516
                                int cierra = data.indexOf("]", i);
517
                                int abre = data.indexOf("[", i);
518
                                if (cierra < abre) { // Esta mal
519
                                        pinta(" =>");
520
                                        param.pos = cierra;
521
                                        return param;
522
                                }
523
                                if (param == null) {
524
                                        if (abre > 0) { //hay claves
525
                                                key = data.substring(i, data.indexOf("[", i));
526
                                                pinta(key+ " <= ");
527
                                                i = abre+1;
528
                                                param = new WKT.Param(key);
529
                                        }
530
                                } else {
531
                                        if (data.substring(i).startsWith("\"")) {
532
                                                name = data.substring(i+1, data.indexOf("\"", i+1));
533
                                                i+=name.length()+2;
534
                                                pinta("|"+name+"|,");
535
                                                param.addValue(name);
536
                                        } else if (nextParam<abre) {
537
                                                name = data.substring(i, data.indexOf(",", i));
538
                                                i+=name.length();
539
                                                pinta(name+",");
540
                                                param.addValue(name);
541
                                        } else {
542
                                                Param p = parseParam(i);
543
                                                i = p.pos+1;
544
                                        }
545
                                }
546
                        }
547
                        return param;
548
                }
549
                static int cnt=0;
550
                public static void pinta(String str) {
551
                        cnt++;
552
                        if (cnt>60)
553
                                System.exit(1);
554
                        System.out.println(str);
555
                }
556
        }
557
        
558
        private void fromCode(String code) {
559
                CoordinateReferenceSystem source;
560
                setAuthority(code);
561
                try {
562
                        source = CRS.decode(code);
563
                        setWkt(source.toWKT());
564
                        
565
                        if (source instanceof DefaultProjectedCRS) {
566
                                DefaultProjectedCRS sour = (DefaultProjectedCRS) source;
567
                                setProjcs(sour.getName().toString().split(":")[1]);
568
                                
569
                                setGeogcs(sour.getBaseCRS().getName().toString().split(":")[1]);
570
                                
571
                                DefaultGeodeticDatum d = (DefaultGeodeticDatum) sour.getDatum();
572
                                setDatumName(d.getName().toString().split(":")[1]);
573
                                setSpheroid((DefaultEllipsoid)d.getEllipsoid());                                
574
                                setPrimen(d.getPrimeMeridian());
575
                                
576
                                setProjection(sour.getConversionFromBase().getMethod().getName().toString().split(":")[1]);
577
                                String str;
578
                                param_name = new String[sour.getConversionFromBase().getParameterValues().values().size()];
579
                                param_value= new String[sour.getConversionFromBase().getParameterValues().values().size()];
580
                                for (int i=0; i< sour.getConversionFromBase().getParameterValues().values().size();i++) {
581
                                        str = sour.getConversionFromBase().getParameterValues().values().get(i).toString();
582
                                        Unit u = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).getUnit();
583
                                        double value = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).doubleValue();
584
                                        value = convert(value, u.toString());
585
                                        param_name[i] = str.split("=")[0];
586
                                        param_value [i] = String.valueOf(value);
587
                                }
588
                                
589
                        }
590
                        
591
                        if (source instanceof DefaultGeographicCRS) {
592
                                DefaultGeographicCRS sour = (DefaultGeographicCRS) source;
593
                                
594
                                setGeogcs(sour.getName().toString().split(":")[1]);
595
                                
596
                                DefaultGeodeticDatum d = (DefaultGeodeticDatum) sour.getDatum();
597
                                setDatumName(d.getName().toString().split(":")[1]);
598
                                setSpheroid((DefaultEllipsoid)d.getEllipsoid());                                
599
                                setPrimen(d.getPrimeMeridian());
600
                                
601
                        }
602
                } catch (NoSuchIdentifierException e) {
603
                        //System.out.println("Noooo: "+e);
604
                } catch (NoSuchAuthorityCodeException e) {
605
                        //System.out.println("Hola: 1");
606
                        // TODO Auto-generated catch block
607
                        e.printStackTrace();
608
                } catch (FactoryException e) {
609
                        //System.out.println("Hola: 2 ");
610
                        // TODO Auto-generated catch block
611
                        e.printStackTrace();
612
                } 
613
                
614
        }
615
        
616
        private void parseWKT(String data) {
617
                WKT wkt = new WKT(data);
618
        }
619
        
620
        public void setProjcs (String proj) {
621
                this.projcs = proj;
622
        }
623
        
624
        public void setProjection (String projection) {
625
                this.projection = projection;
626
        }
627
        public void setGeogcs (String geo) {
628
                this.geogcs = geo;
629
        }
630
        
631
        public void setDatumName (String dat) {
632
                this.datum = dat;
633
        }
634
        
635
        public void setSpheroid (DefaultEllipsoid ellips) {
636
                Unit u = ellips.getAxisUnit();
637
                double semi_major = convert( ellips.getSemiMajorAxis(), u.toString());
638
                double inv_f = convert( ellips.getInverseFlattening(), u.toString());
639
                                
640
                this.spheroid[0] = ellips.getName().toString().split(":")[1];
641
                this.spheroid[1] = String.valueOf(semi_major);
642
                this.spheroid[2] = String.valueOf(inv_f);
643
        }
644
        
645
        public void setPrimen (PrimeMeridian prim) {
646
                DefaultPrimeMeridian pm = new DefaultPrimeMeridian(prim);
647
                Unit u = pm.getAngularUnit();
648
                double value = convert( pm.getGreenwichLongitude(), u.toString());
649
                                
650
                this.primem[0] = pm.getName().toString().split(":")[1];
651
                this.primem[1] = String.valueOf(value);
652
        }
653
        
654
        public void setUnit () {
655
                
656
        }
657
        
658
        public void setUnit_p () {
659
                
660
        }
661
        
662
        public void setParam_name () {
663
                
664
        }
665
        
666
        public void setParam_value () {
667
                        
668
        }
669
        
670
        public void setAuthority (String aut) {
671
                this.authority = aut.split(":");                
672
        }
673
        
674
        public void setWkt(String wkt){
675
                this.wkt = wkt;
676
        }
677
        
678
        public String getWkt() {
679
                return wkt;
680
        }
681
        
682
        public double convert(double value, String measure) throws ConversionException {
683
                if (measure.equals("D.MS")) {                
684
                        value *= this.divider;
685
                int deg,min;
686
                deg = (int) (value/10000); value -= 10000*deg;
687
                min = (int) (value/  100); value -=   100*min;
688
                if (min<=-60 || min>=60) {  // Accepts NaN
689
                    if (Math.abs(Math.abs(min) - 100) <= EPS) {
690
                        if (min >= 0) deg++; else deg--;
691
                        min = 0;
692
                    } else {
693
                        throw new ConversionException("Invalid minutes: "+min);
694
                    }
695
                }
696
                if (value<=-60 || value>=60) { // Accepts NaN
697
                    if (Math.abs(Math.abs(value) - 100) <= EPS) {
698
                        if (value >= 0) min++; else min--;
699
                        value = 0;
700
                    } else {
701
                        throw new ConversionException("Invalid secondes: "+value);
702
                    }
703
                }
704
                value = ((value/60) + min)/60 + deg;
705
                return value;
706
                }
707
                if (measure.equals("grad") || measure.equals("grade")) 
708
                        return ((value * 180.0) / 200.0);                        
709
                if (measure.equals(""+(char)176)) 
710
                        return value;                
711
                if (measure.equals("DMS") ) 
712
                        return value;                
713
                if (measure.equals("m")) 
714
                        return value;                
715
                
716
                throw new ConversionException("Conversion no contemplada: "+measure);
717
    }
718
}