Revision 436

View differences:

org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.lin.x86/pom.xml
7 7
 	<parent>
8 8
		<groupId>org.gvsig</groupId>
9 9
		<artifactId>org.gvsig.projection.app.jcrs</artifactId>
10
		<version>2.1.26-SNAPSHOT</version>
10
		<version>2.1.31-SNAPSHOT</version>
11 11
	</parent>
12 12

  
13 13
  <properties>
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.lin.x86_64/pom.xml
7 7
 	<parent>
8 8
		<groupId>org.gvsig</groupId>
9 9
		<artifactId>org.gvsig.projection.app.jcrs</artifactId>
10
		<version>2.1.26-SNAPSHOT</version>
10
		<version>2.1.31-SNAPSHOT</version>
11 11
	</parent>
12 12

  
13 13
  <properties>
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.win.x86/pom.xml
7 7
 	<parent>
8 8
		<groupId>org.gvsig</groupId>
9 9
		<artifactId>org.gvsig.projection.app.jcrs</artifactId>
10
		<version>2.1.26-SNAPSHOT</version>
10
		<version>2.1.31-SNAPSHOT</version>
11 11
	</parent>
12 12

  
13 13
  <properties>
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/proj/CrsProj.java
140 140
    }
141 141

  
142 142
    public String getUnits() {
143
        return spatialReference.GetAttrValue("UNIT");
143
        return spatialReference.GetAttrValue("UNIT",0);
144 144
    }
145 145

  
146 146
    public double getConversionFactorToMeters() {
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsWkt.java
45 45
import javax.units.ConversionException;
46 46
import javax.units.Unit;
47 47

  
48
import org.gdal.osr.SpatialReference;
48 49
import org.geotools.referencing.CRS;
49 50
import org.geotools.referencing.crs.AbstractSingleCRS;
50 51
import org.geotools.referencing.crs.DefaultGeographicCRS;
......
63 64
 * Clase que parsea una cadena wkt y consigue todos sus par?metros
64 65
 * de manera independiente para poder ser utilizados
65 66
 * en distintas funciones
66
 * 
67
 *
67 68
 * @author Jos? Luis G?mez Mart?nez (JoseLuis.Gomez@uclm.es)
68 69
 *
69 70
 */
70 71

  
71 72
public class CrsWkt {
72
	private static final Logger logger = LoggerFactory.getLogger(CrsWkt.class); 
73
	private static final Logger logger = LoggerFactory.getLogger(CrsWkt.class);
73 74

  
74 75
	private String wkt;
75 76
	private String projcs = "";
......
84 85
	private String[] param_value;
85 86
	private int contador = 0;
86 87
	private String[] authority = {"",""};
87
	
88

  
88 89
	int divider=10000;
89
	
90

  
90 91
	/**
91 92
     * Small tolerance factor for rounding errors.
92 93
     */
93 94
    private static final double EPS = 1E-8;
94
	
95

  
96

  
97
    /**
98
 *
99
 */
100
    public CrsWkt(SpatialReference spatialReference) {
101
        wkt = spatialReference.ExportToWkt();
102
        projcs = spatialReference.GetAttrValue("PROJCS",0);
103
        if(projcs==null){
104
            projcs = "";
105
        } else {
106
            unit_p[0] = spatialReference.GetAttrValue("UNIT",0);
107
            unit_p[1] = spatialReference.GetAttrValue("UNIT",1);
108
            projection = spatialReference.GetAttrValue("PROJECTION");
109
        }
110
        geogcs = spatialReference.GetAttrValue("GEOGCS",0);
111
        datum = spatialReference.GetAttrValue("DATUM",0);
112

  
113
        CRSDatum crsDatum = new CRSDatum(spatialReference.GetSemiMajor(), spatialReference.GetInvFlattening());
114

  
115
        spheroid[0] = String.valueOf(spatialReference.GetSemiMinor()); //.GetAttrValue("SPHEROID",0);
116
        spheroid[1] = String.valueOf(spatialReference.GetSemiMajor()); //GetAttrValue("SPHEROID",1);
117
        spheroid[2] = String.valueOf(spatialReference.GetInvFlattening()); //.GetAttrValue("SPHEROID",2);
118
        primem[0] = spatialReference.GetAttrValue("PRIMEM",0);
119
        primem[1] = spatialReference.GetAttrValue("PRIMEM",1);
120
        double toRadians = spatialReference.GetAngularUnits();
121
        unit[1] = String.valueOf(toRadians);
122
        if(toRadians==1){
123
            unit[0] = org.gdal.osr.osr.SRS_UA_RADIAN;
124
        } else {
125
            unit[0] = org.gdal.osr.osr.SRS_UA_DEGREE;
126
        }
127

  
128
        authority[0] = spatialReference.GetAuthorityName(null);
129
        authority[1] = spatialReference.GetAuthorityCode(null);
130

  
131
    }
132

  
95 133
	public CrsWkt(String wkt_spaces) {
96 134
		String aux;
97 135
		String wkt = "";
......
109 147
			fromCode(wkt);
110 148
		}
111 149
	}
112
	
150

  
113 151
	public CrsWkt(CoordinateReferenceSystem crsGT) {
114 152
		AbstractSingleCRS crs = (AbstractSingleCRS)crsGT;
115 153
		String authority = crs.getName().toString().split(":")[0];
116 154
		setAuthority(((AbstractSingleCRS)crsGT).getIdentifiers().iterator().next().toString());
117 155
		setWkt(crsGT.toWKT());
118
		
156

  
119 157
		if (crsGT instanceof DefaultProjectedCRS) {
120 158
			DefaultProjectedCRS sour = (DefaultProjectedCRS) crsGT;
121 159
			setProjcs(sour.getName().toString().split(":")[1]);
......
130 168
				setDatumName(d.getName().toString().split(":")[0]);
131 169
			else
132 170
				setDatumName(d.getName().toString().split(":")[1]);
133
			setSpheroid((DefaultEllipsoid)d.getEllipsoid());				
171
			setSpheroid((DefaultEllipsoid)d.getEllipsoid());
134 172
			setPrimen(d.getPrimeMeridian());
135 173
			val = sour.getConversionFromBase().getMethod().getName().toString().split(":");
136 174
			if (val.length<2)
......
148 186
				param_name[i] = str.split("=")[0];
149 187
				param_value [i] = String.valueOf(value);
150 188
			}
151
			
189

  
152 190
		}
153
		
191

  
154 192
		if (crsGT instanceof DefaultGeographicCRS) {
155 193
			DefaultGeographicCRS sour = (DefaultGeographicCRS) crsGT;
156 194
			String[] val = sour.getName().toString().split(":");
......
158 196
				setGeogcs(sour.getName().toString().split(":")[0]);
159 197
			else
160 198
				setGeogcs(sour.getName().toString().split(":")[1]);
161
			
199

  
162 200
			DefaultGeodeticDatum d = (DefaultGeodeticDatum) sour.getDatum();
163 201
			val = d.getName().toString().split(":");
164 202
			if (val.length<2)
165 203
				setDatumName(d.getName().toString().split(":")[0]);
166 204
			else
167 205
				setDatumName(d.getName().toString().split(":")[1]);
168
			setSpheroid((DefaultEllipsoid)d.getEllipsoid());				
206
			setSpheroid((DefaultEllipsoid)d.getEllipsoid());
169 207
			setPrimen(d.getPrimeMeridian());
170
			
171
		} 
208

  
209
		}
172 210
	}
173
	
211

  
174 212
	/**
175 213
	 * Acepta la cadena wkt y si es un CRS proyectado para conseguir el parser
176 214
	 * de los dos modelos de cadena wkt que se utilizan, una cuando es base
......
179 217
	 * @param isProj
180 218
	 */
181 219
	private void fromWKT(String wkt, boolean isProj) {
182
		
220

  
183 221
		String res = new String();
184 222
		if(!wkt.startsWith("EPSG:")) {
185 223
			res = "";
......
187 225
				res += wkt.charAt(contador);
188 226
			}
189 227
			if(res.equals("GEOGCS[")) {
190
				
228

  
191 229
				contador++;
192 230
				for(; wkt.charAt(contador) != '"'; contador++) {
193 231
					geogcs += wkt.charAt(contador);
194 232
				}
195
				
233

  
196 234
				res = "";
197 235
				contador++;
198 236
				for(; wkt.charAt(contador) != '"'; contador++) {
......
301 339
						geogcs += wkt.charAt(contador);
302 340
					}
303 341
				}
304
								
342

  
305 343
				res = "";
306 344
				contador++;
307 345
				for(; wkt.charAt(contador) != '"'; contador++) {
......
393 431
				}
394 432
				//Hallamos el numero de parametros que tiene la cadena wkt
395 433
				int i = 0;
396
				
434

  
397 435
				int copiacontador = contador;
398 436
				if(res.equals(",PARAMETER[")) {
399 437
					do{
......
443 481
						for(; wkt.charAt(contador) != '"'; contador++) {
444 482
							res += wkt.charAt(contador);
445 483
						}
446
					} while (res.equals(",PARAMETER["));					
484
					} while (res.equals(",PARAMETER["));
447 485
				}
448
				
486

  
449 487
				if (res.equals(",UNIT[")){
450 488
					contador++;
451 489
					for(; wkt.charAt(contador) != ','; contador++) {
......
484 522
				/*
485 523
				 * parte necesaria para capturar la cadena geocentrica...
486 524
				 */
487
				
525

  
488 526
			}
489 527
		}else
490 528
			geogcs = wkt;
491 529
	}
492
	
530

  
493 531
	public String getProjection() {
494 532
		return projection;
495 533
	}
496
	
534

  
497 535
	public String getProjcs() {
498 536
		return projcs;
499 537
	}
500
	
538

  
501 539
	public String getGeogcs() {
502 540
		return geogcs;
503 541
	}
504
	
542

  
505 543
	public String getDatumName() {
506 544
		return datum;
507 545
	}
508
	
546

  
509 547
	public String[] getSpheroid() {
510 548
		return spheroid;
511 549
	}
512
	
550

  
513 551
	public String[] getPrimen() {
514 552
		return primem;
515 553
	}
516
	
554

  
517 555
	public String getName() {
518
		if(projcs == "") 
556
		if(projcs == "")
519 557
			return geogcs;
520 558
		return projcs;
521 559
	}
522
	
560

  
523 561
	public String[] getUnit() {
524 562
		return unit;
525 563
	}
526
	
564

  
527 565
	public String[] getUnit_p() {
528 566
		return unit_p;
529 567
	}
530
	
568

  
531 569
	public String[] getParam_name() {
532 570
		return param_name;
533 571
	}
534
	
572

  
535 573
	public String[] getParam_value() {
536 574
		return param_value;
537 575
	}
538
	
576

  
539 577
	public String[] getAuthority(){
540 578
		return authority;
541 579
	}
542
	
580

  
543 581
	/*
544 582
	 * Parser a medio hacer, orientado a objeto y recursivo.
545 583
	 * by LWS.
546 584
	 */
547
	
585

  
548 586
	public static class WKT {
549 587
		public class Param {
550 588
			String key;
......
569 607
		private WKT.Param parseParam(int pos) {
570 608
			WKT.Param param = null;
571 609
			String key, name;
572
			
610

  
573 611
			int l = data.length();
574 612
			for (int i = pos; i<l;) {
575 613
				int nextParam = data.indexOf(",", i);
......
617 655
			System.out.println(str);
618 656
		}
619 657
	}
620
	
658

  
621 659
	private void fromCode(String code) {
622 660
		CoordinateReferenceSystem source;
623 661
		setAuthority(code);
624 662
		try {
625 663
			source = CRS.decode(code);
626 664
			setWkt(source.toWKT());
627
			
665

  
628 666
			if (source instanceof DefaultProjectedCRS) {
629 667
				DefaultProjectedCRS sour = (DefaultProjectedCRS) source;
630 668
				setProjcs(sour.getName().toString().split(":")[1]);
......
639 677
					setDatumName(d.getName().toString().split(":")[0]);
640 678
				else
641 679
					setDatumName(d.getName().toString().split(":")[1]);
642
				setSpheroid((DefaultEllipsoid)d.getEllipsoid());				
680
				setSpheroid((DefaultEllipsoid)d.getEllipsoid());
643 681
				setPrimen(d.getPrimeMeridian());
644 682
				val = sour.getConversionFromBase().getMethod().getName().toString().split(":");
645 683
				if (val.length<2)
......
657 695
					param_name[i] = str.split("=")[0];
658 696
					param_value [i] = String.valueOf(value);
659 697
				}
660
				
698

  
661 699
			}
662
			
700

  
663 701
			if (source instanceof DefaultGeographicCRS) {
664 702
				DefaultGeographicCRS sour = (DefaultGeographicCRS) source;
665 703
				String[] val = sour.getName().toString().split(":");
......
667 705
					setGeogcs(sour.getName().toString().split(":")[0]);
668 706
				else
669 707
					setGeogcs(sour.getName().toString().split(":")[1]);
670
				
708

  
671 709
				DefaultGeodeticDatum d = (DefaultGeodeticDatum) sour.getDatum();
672 710
				val = d.getName().toString().split(":");
673 711
				if (val.length<2)
674 712
					setDatumName(d.getName().toString().split(":")[0]);
675 713
				else
676 714
					setDatumName(d.getName().toString().split(":")[1]);
677
				setSpheroid((DefaultEllipsoid)d.getEllipsoid());				
715
				setSpheroid((DefaultEllipsoid)d.getEllipsoid());
678 716
				setPrimen(d.getPrimeMeridian());
679
				
717

  
680 718
			}
681 719
		} catch (NoSuchAuthorityCodeException e) { //Pertenece a CRS
682 720
			logger.error("Can't create CRS from code '"+code+"'.",e);
683 721
		} catch (FactoryException e) { //Pertenece a CRS
684 722
			logger.error("Can't create CRS from code '"+code+"'.",e);
685
		} 
686
		
723
		}
724

  
687 725
	}
688
	
726

  
689 727
	private void parseWKT(String data) {
690 728
		WKT wkt = new WKT(data);
691 729
	}
692
	
730

  
693 731
	public void setProjcs (String proj) {
694 732
		this.projcs = proj;
695 733
	}
696
	
734

  
697 735
	public void setProjection (String projection) {
698 736
		this.projection = projection;
699 737
	}
700 738
	public void setGeogcs (String geo) {
701 739
		this.geogcs = geo;
702 740
	}
703
	
741

  
704 742
	public void setDatumName (String dat) {
705 743
		this.datum = dat;
706 744
	}
707
	
745

  
708 746
	public void setSpheroid (DefaultEllipsoid ellips) {
709 747
		Unit u = ellips.getAxisUnit();
710 748
		double semi_major = convert( ellips.getSemiMajorAxis(), u.toString());
......
717 755
		this.spheroid[1] = String.valueOf(semi_major);
718 756
		this.spheroid[2] = String.valueOf(inv_f);
719 757
	}
720
	
758

  
721 759
	public void setPrimen (PrimeMeridian prim) {
722 760
		DefaultPrimeMeridian pm = (DefaultPrimeMeridian)(prim);
723 761
		Unit u = pm.getAngularUnit();
......
729 767
			this.primem[0] = pm.getName().toString().split(":")[1];
730 768
		this.primem[1] = String.valueOf(value);
731 769
	}
732
		
770

  
733 771
	public void setAuthority (String aut) {
734
		this.authority = aut.split(":");		
772
		this.authority = aut.split(":");
735 773
	}
736
	
774

  
737 775
	public void setWkt(String wkt){
738 776
		this.wkt = wkt;
739 777
	}
740
	
778

  
741 779
	public String getWkt() {
742 780
		return wkt;
743 781
	}
744
	
782

  
745 783
	public double convert(double value, String measure) throws ConversionException {
746
		if (measure.equals("D.MS")) {		
784
		if (measure.equals("D.MS")) {
747 785
			value *= this.divider;
748 786
	        int deg,min;
749 787
	        deg = (int) (value/10000); value -= 10000*deg;
......
767 805
	        value = ((value/60) + min)/60 + deg;
768 806
	        return value;
769 807
		}
770
		if (measure.equals("grad") || measure.equals("grade")) 
771
			return ((value * 180.0) / 200.0);			
772
		if (measure.equals(""+(char)176)) 
773
			return value;		
774
		if (measure.equals("DMS") ) 
775
			return value;		
776
		if (measure.equals("m")) 
808
		if (measure.equals("grad") || measure.equals("grade"))
809
			return ((value * 180.0) / 200.0);
810
		if (measure.equals(""+(char)176))
777 811
			return value;
812
		if (measure.equals("DMS") )
813
			return value;
814
		if (measure.equals("m"))
815
			return value;
778 816
		//TODO revisar este if, y ver si seria correcto...
779 817
		if (measure.startsWith("[m*")) {
780 818
			return value*Double.parseDouble(measure.substring(3,measure.length()-1));
781 819
		}
782
		if (measure.equals("")) 
820
		if (measure.equals(""))
783 821
			return value;
784
		if (measure.equalsIgnoreCase("ft")||measure.equalsIgnoreCase("foot")||measure.equalsIgnoreCase("feet")) 
822
		if (measure.equalsIgnoreCase("ft")||measure.equalsIgnoreCase("foot")||measure.equalsIgnoreCase("feet"))
785 823
			return (value*0.3048/1.0);
786
		
824

  
787 825
		throw new ConversionException("Conversion no contemplada: "+measure);
788 826
    }
789 827
}
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsFactory.java
20 20

  
21 21
import java.io.File;
22 22
import java.util.TreeMap;
23
import java.util.Vector;
23 24

  
24 25
import org.cresques.cts.ICRSFactory;
25 26
import org.cresques.cts.IProjection;
27
import org.gdal.osr.SpatialReference;
28

  
26 29
import org.gvsig.crs.repository.EpsgRepository;
27 30
import org.gvsig.crs.repository.EpsgRepositoryGT;
28 31
import org.gvsig.crs.repository.EsriRepository;
......
35 38
import org.gvsig.crs.repository.UsrRepository;
36 39
import org.gvsig.crs.repository.UsrRepositoryGT;
37 40
import org.gvsig.tools.dispose.Disposable;
41

  
38 42
import org.slf4j.Logger;
39 43
import org.slf4j.LoggerFactory;
40 44

  
......
43 47
 * la cadena WKT
44 48
 *
45 49
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
50
 * @param <E>
46 51
 *
47 52
 */
48
public class CrsFactory implements ICRSFactory {
53
public class CrsFactory<E> implements ICRSFactory {
49 54

  
50 55
    private static Logger logger = LoggerFactory.getLogger(CrsFactory.class);
51 56
    static TreeMap data = new TreeMap();
......
270 275
            epsgDatabaseFile = new File(getDataBaseFolder(), epsgDatabaseFile.getPath());
271 276
        }
272 277
    }
278

  
279
    public IProjection get(String format, String value) {
280
        if(ICRSFactory.FORMAT_WKT_ESRI.equalsIgnoreCase(format)){
281
        SpatialReference sr = new SpatialReference();
282
        Vector<String> vector = new Vector<String>();
283
        vector.add(value);
284
        sr.ImportFromESRI(vector);
285
        sr.MorphFromESRI();
286
//        try {
287
//            String authorityCode = sr.GetAuthorityCode(null);
288
//            String authorityName = sr.GetAuthorityName(null);
289
//
290
//            int code = 0;
291
//            if( "EPSG".equalsIgnoreCase(authorityName) ){
292
//                code = 1;
293
//            } else if( "ESRI".equalsIgnoreCase(authorityName) ){
294
//                code = 2;
295
//
296
//            } else if( "IAU2000".equalsIgnoreCase(authorityName) ){
297
//                code = 3;
298
//
299
//            } else if( "USR".equalsIgnoreCase(authorityName) ){
300
//                code = 4;
301
//
302
//            } else {
303
//                logger.warn("Can't get CRS format '" + format + "' and value '"+value+"', unknow authorityName '"+authorityName+"'.");
304
//            }
305
//            return new Crs(Integer.parseInt(authorityCode), code);
306
            return new Crs(sr);
307
//        } catch (CrsException e) {
308
//            logger.warn("Can't get CRS format '" + format + "' and value '"+value+"'.", e);
309
//        }
310
//        return null;
311
        } else if (ICRSFactory.FORMAT_WKT.equalsIgnoreCase(format)) {
312

  
313
            return null;
314

  
315
        } else if (ICRSFactory.FORMAT_PROJ4.equalsIgnoreCase(format)) {
316

  
317
            return null;
318

  
319
        }
320
        return null;
321
    }
322

  
323
    /* (non-Javadoc)
324
     * @see org.cresques.cts.ICRSFactory#export(java.lang.String, org.cresques.cts.IProjection)
325
     */
326
    public String export(String format, IProjection proj) {
327
        // TODO Auto-generated method stub
328
        return null;
329
    }
273 330
}
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/repository/EpsgRepository.java
45 45

  
46 46
import es.idr.teledeteccion.connection.EpsgConnection;
47 47
import es.idr.teledeteccion.connection.Query;
48

  
48 49
import java.util.logging.Level;
49 50

  
51
import org.gdal.osr.SpatialReference;
50 52
import org.slf4j.Logger;
51 53
import org.slf4j.LoggerFactory;
52 54

  
......
58 60
import org.gvsig.tools.dispose.Disposable;
59 61
/**
60 62
 * Repositorio de CRSs de EPSG
61
 * 
63
 *
62 64
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
63 65
 *
64 66
 */
65
public class EpsgRepository implements ICrsRepository, Disposable {
67
public class EpsgRepository implements ICrsRepository {
66 68
	private static final Logger logger =
67 69
        LoggerFactory.getLogger(EpsgRepository.class);
68
	
70

  
69 71
	public EpsgConnection connection = null;
70
	
72

  
71 73
	public EpsgRepository() {
72 74
		connection = new EpsgConnection();
73 75
	}
74 76

  
75 77
	/**
76 78
	 * Obtiene un CRS a partir de su c?digo EPSG.
77
	 * 
78
	 * @param code Codigo EPSG del CRS. 
79
	 * @return ICrs 
79
	 *
80
	 * @param code Codigo EPSG del CRS.
81
	 * @return ICrs
80 82
	 */
81 83
	public ICrs getCrs(String code) {
82
		int epsg_code  = Integer.parseInt(code);
83
		boolean source_yn = false;
84
		int source_cod = 0;
85
		int datum_code = 0;
86
		int projection_conv_code = 0;
87
		String crs_kind = null;
88
		
89
		Epsg2wkt wkt = null;
90
		
91
		Crs crs = null;
92
		
93
		ResultSet result = null;
94
		String sentence = "SELECT source_geogcrs_code, projection_conv_code, "
95
			+ "coord_ref_sys_kind, datum_code "
96
			+ "FROM epsg_coordinatereferencesystem "
97
			+ "WHERE coord_ref_sys_code = " + code;
98
						
99
		connection.setConnectionEPSG();
100
		result = Query.select(sentence,connection.getConnection());	
101
		
102
		/*try {
103
			connection.shutdown();
104
		} catch (SQLException e) {
105
			// TODO Auto-generated catch block
106
			logger....
107
		}*/
108
		
109
		try {
110
			if (!result.next())
111
				return null;
112
			source_cod = result.getInt("source_geogcrs_code");
113
			projection_conv_code = result.getInt("projection_conv_code");
114
			crs_kind = result.getString("coord_ref_sys_kind");
115
			datum_code = result.getInt("datum_code");
116
		} catch (SQLException e1) {
117
		    logger.warn("Error executing the SQL", e1);
118
		    return null;
119
		}
120
		
121
		if (datum_code != 0){
122
			source_yn = true;
123
		}
124
		else if (source_cod != 0){
125
			source_yn = false;
126
		}
127
		else source_yn = true;
128
		
129
		CrsEPSG ep = new CrsEPSG(epsg_code, source_yn, source_cod, projection_conv_code, connection);
130
		
131
		if (crs_kind.equals("geographic 2D") || crs_kind.equals("geographic 3D")){
132
			wkt = new Epsg2wkt(ep , "geog");			
133
		}
134
		else if (crs_kind.equals("projected")){
135
			wkt = new Epsg2wkt(ep, "proj");
136
		}
137
		else if (crs_kind.equals("compound")){
138
			wkt = new Epsg2wkt(ep,"comp");
139
		}
140
		else if (crs_kind.equals("geocentric")){
141
			wkt = new Epsg2wkt(ep,"geoc");
142
		}
143
		
144
		try {
145
			crs = new Crs(Integer.parseInt(code),wkt.getWKT());
146
		} catch (CrsException e) {
147
		    logger.warn("Impossible to parse the CRS", e);
148
		    return null;
149
		}
150
		return crs;
84
	    int epsg_code  = Integer.parseInt(code);
85

  
86
	    Crs crs;
87
	    SpatialReference spatialReference = new SpatialReference();
88
	    try {
89
	        spatialReference.ImportFromEPSG(epsg_code);
90
	        crs = new Crs(spatialReference);
91
	    } catch(RuntimeException e) {
92
	        logger.warn("Can't create ESPG Crs from "+code+".", e);
93
	        throw e;
94
	    }
95
	    return crs;
151 96
	}
152 97

  
153
        public void dispose() {
154
            try {
155
                this.connection.close();
156
                this.connection = null;
157
            } catch (SQLException ex) {
158
                logger.warn("Can't shutdown the connection.",ex);
159
            }
160
        }
98
//        public void dispose() {
99
//            try {
100
//                this.connection.close();
101
//                this.connection = null;
102
//            } catch (SQLException ex) {
103
//                logger.warn("Can't shutdown the connection.",ex);
104
//            }
105
//        }
161 106
}
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsGT.java
45 45
import java.awt.geom.Point2D;
46 46
import java.awt.geom.Rectangle2D;
47 47

  
48
import org.cresques.cts.ICRSFactory;
48 49
import org.cresques.cts.ICoordTrans;
49 50
import org.cresques.cts.IDatum;
50 51
import org.cresques.cts.IProjection;
51 52
import org.cresques.geo.ViewPortData;
53
import org.gdal.osr.SpatialReference;
52 54
import org.geotools.referencing.crs.AbstractDerivedCRS;
53 55
import org.geotools.referencing.crs.AbstractSingleCRS;
54 56
import org.geotools.referencing.datum.DefaultGeodeticDatum;
......
398 400
        return CRSFactory.getCRS( this.getFullCode() );
399 401
     }
400 402

  
403
    /* (non-Javadoc)
404
     * @see org.cresques.cts.IProjection#export(java.lang.String)
405
     */
406
    public String export(String format) {
407
        SpatialReference spatialReference = getCrsProj().getSpatialReference();
408
        if(format.equalsIgnoreCase(ICRSFactory.FORMAT_PROJ4)){
409
            return spatialReference.ExportToProj4();
410
        } else if(format.equalsIgnoreCase(ICRSFactory.FORMAT_WKT_ESRI)){
411
            if(spatialReference.MorphToESRI() == 0){
412
                return spatialReference.ExportToWkt();
413
            }
414
            return null;
415
        }
416
            return spatialReference.ExportToWkt();
417
    }
418

  
401 419
}
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/COperation.java
43 43
import java.awt.geom.Point2D;
44 44
import java.awt.geom.Rectangle2D;
45 45

  
46
import org.cresques.cts.CoordTransRuntimeException;
46 47
import org.cresques.cts.ICoordTrans;
47 48
import org.cresques.cts.IProjection;
48 49
import org.gdal.gdal.gdal;
......
167 168

  
168 169
        double[] transformed = { 0, 0, 0 };
169 170
        initializeCoordinateTransformation();
170
        if (coordinateTransformation != null) {
171
            transformed = coordinateTransformation.TransformPoint(x, y);
171
        gdal.PushErrorHandler( "CPLQuietErrorHandler" );
172
        gdal.ErrorReset();
173
        if (coordinateTransformation != null) { // && inverseCoordinateTransformation != null) {
174
            coordinateTransformation.TransformPoint(transformed, x, y, 0);
172 175
        }
173 176

  
177
        gdal.PopErrorHandler();
174 178
        errno = gdal.GetLastErrorNo();
175 179
        msg = gdal.GetLastErrorMsg();
176 180
        errtype = gdal.GetLastErrorType();
177 181

  
178 182
        Point2D.Double result = null;
179
        if (errno != 0 && errtype != 0) {
180
            //FIXME:
183
        if (errno != 0 || errtype != 0 || !msg.isEmpty()) {
184
            // FIXME:
181 185
            // gdal no devuelve m?s de 20 errores por transformaci?n,
182 186
            // si queremos de los devuelva todos tenemos que anular la
183 187
            // transformaci?n cada vez que se produce un error
184
//            coordinateTransformation = null;
185
            // Adem?s, no podemos hacer nada por los puntos que devuelve
186
            // la transformaci?n cuando ha tenido un error.
187
            // Lo suyo ser?a elevar una excepci?n y quien la recoja que decida qu? dabe hacer con el punto,
188
            // por ejemplo, si se est? dibujando una geometr?a, tal vez, no habr?a que dibujarla o saltarse los
189
            // puntos que no se pueden transformar.
188
            if (msg
189
                .equalsIgnoreCase("Reprojection failed, err = -14, further errors will be supressed on the transform object.")) {
190
                resetCoordinateTransformation();
191
            }
190 192

  
191
            gdal.ErrorReset();
192

  
193
            throw new CoordTransRuntimeException(sourceCrs, targetCrs, x, y);
193 194
        }
194 195
        result = new Point2D.Double(transformed[0], transformed[1]);
195 196
        return result;
......
197 198

  
198 199
    private void initializeCoordinateTransformation() {
199 200
        if (coordinateTransformation == null) {
201

  
202
            int errno = 0;
203
            String msg = "";
204
            int errtype = 0;
205

  
206
            gdal.ErrorReset();
207
            gdal.PushErrorHandler( "CPLQuietErrorHandler" );
200 208
            coordinateTransformation =
201 209
                CoordinateTransformation.CreateCoordinateTransformation(source.getSpatialReference(),
202 210
                    target.getSpatialReference());
211
            gdal.PopErrorHandler();
212
            errno = gdal.GetLastErrorNo();
213
            msg = gdal.GetLastErrorMsg();
214
            errtype = gdal.GetLastErrorType();
215
            if (errno != 0 || errtype != 0 || !msg.isEmpty()) {
216
                logger.warn("Can't initialize coordinate transformation from "+sourceCrs.getAbrev()+" to "+targetCrs.getAbrev()+" "+errno + " "+errtype+" "+msg+".");
217
            }
203 218
        }
204 219
    }
205 220

  
221
    private void resetCoordinateTransformation() {
222
        coordinateTransformation = null;
223
        initializeCoordinateTransformation();
224
    }
225

  
206 226
    public IProjection getPOrig() {
207 227
        return (IProjection) sourceCrs;
208 228
    }
......
211 231
        return (IProjection) targetCrs;
212 232
    }
213 233

  
214
    public Point2D convert(Point2D ptOrig, Point2D ptDest) {
234
    public Point2D convert(Point2D ptOrig, Point2D ptDest) throws CoordTransRuntimeException {
215 235
        try {
216 236
            ptDest = operate(ptOrig);
217 237
        } catch (CrsException e) {
......
224 244
        return ptDest;
225 245
    }
226 246

  
227
    public Rectangle2D convert(Rectangle2D rect) {
247
    public Rectangle2D convert(Rectangle2D rect) throws CoordTransRuntimeException {
228 248
        Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY());
229 249
        Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
230 250
        Point2D pt3 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/Crs.java
45 45
import java.awt.geom.Point2D;
46 46
import java.awt.geom.Rectangle2D;
47 47
import java.text.MessageFormat;
48
import java.util.Vector;
48 49

  
50
import org.apache.commons.lang3.StringUtils;
51
import org.cresques.cts.ICRSFactory;
49 52
import org.cresques.cts.ICoordTrans;
50 53
import org.cresques.cts.IDatum;
51 54
import org.cresques.cts.IProjection;
52 55
import org.cresques.geo.ViewPortData;
56
import org.gdal.osr.SpatialReference;
53 57
import org.slf4j.Logger;
54 58
import org.slf4j.LoggerFactory;
55 59

  
......
65 69
 *
66 70
 */
67 71
public class Crs implements ICrs {
68
	private static final Logger logger = LoggerFactory.getLogger(Crs.class);
69 72

  
70
	private static final Color basicGridColor = new Color(64, 64, 64, 128);
71
	private Proj4 proj4;
72
	private String proj4String;
73
	private String trans;
74
	//private String transOrigin = "";
75
	private String abrev;
76
	private String name = "";
77
	private CrsProj crsProj;
78
	private CrsProj crsBase = null;
79
	private CrsWkt crsWkt;
80
	private int epsg_code = 23030;
81
	String sourceTrParams = null;
82
	String targetTrParams = null;
83
	String wkt = null;
84
	Color gridColor = basicGridColor;
85
	CRSDatum datum = null;
73
    private static final Logger logger = LoggerFactory.getLogger(Crs.class);
86 74

  
87
	public Crs(int epsgCode, int aut) throws CrsException
88
	{
89
		String strEpsgCode = "";
90
		if (aut == 1) {
91
			strEpsgCode="EPSG:"+epsgCode;
92
		} else if (aut == 2){
93
			strEpsgCode="ESRI:"+epsgCode;
94
		} else if (aut == 3){
95
			strEpsgCode="IAU2000:"+epsgCode;
96
		} else if (aut == 4) {
97
			strEpsgCode="USR:"+epsgCode;
98
		} else System.out.println("Error, autorithy err?neo");
99
		crsWkt=new CrsWkt(strEpsgCode);
100
		setWKT(crsWkt.getWkt());
101
	}
75
    private static final Color basicGridColor = new Color(64, 64, 64, 128);
76
    private Proj4 proj4;
77
    private String proj4String;
78
    private String trans;
79
    // private String transOrigin = "";
80
    private String abrev;
81
    private String name = "";
82
    private CrsProj crsProj;
83
    private CrsProj crsBase = null;
84
    private CrsWkt crsWkt;
85
    private int epsg_code = 23030;
86
    String sourceTrParams = null;
87
    String targetTrParams = null;
88
    String wkt = null;
89
    Color gridColor = basicGridColor;
90
    CRSDatum datum = null;
102 91

  
103 92

  
104
	/**
105
	 * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
106
	 *
107
	 * @param code
108
	 * @throws CrsException
109
	 */
110
	public Crs(String code) throws CrsException {
111
		String fullCode;
112
		setWKT(code);
113
		if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
114
			fullCode = code;
115
		else fullCode = "EPSG:"+code;
116
		String cod = "";
117
		if(code.length() < 15 ) {
118
			code = code.substring(code.indexOf(":")+1);
119
			try {
120
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
121
				crsWkt = new CrsWkt(fullCode);
122
				setName(fullCode);
123
				setAbrev(fullCode);
93
    /**
94
     *
95
     */
96
    public Crs(SpatialReference spatialReference) {
97
            initFromSpatialReference(spatialReference);
98
    }
124 99

  
125
			} catch (NumberFormatException e) {
126
				logger.error("Can't Wkt.",e);
127
			}
128
		}else {
129
			String aux;
130
			String code2 = "";
131
			for(int i = 0; i < code.length(); i++) {
132
				aux = ""+code.charAt(i);
133
				if(!aux.equals(" ")) {
134
					code2+=aux;
135
				}else {
136
					code2 += "";
137
				}
138
			}
139
			crsWkt = new CrsWkt(code2);
100
    /**
101
     * @param spatialReference
102
     */
103
    private void initFromSpatialReference(SpatialReference spatialReference) {
104
        String authorityCode = spatialReference.GetAuthorityCode(null);
105
        String authorityName = spatialReference.GetAuthorityName(null);
106
        spatialReference.Fixup();
107
        if(authorityCode==null || authorityName==null){
108
            try {
109
                spatialReference.AutoIdentifyEPSG();
110
                authorityCode = spatialReference.GetAuthorityCode(null);
111
                authorityName = spatialReference.GetAuthorityName(null);
112
            } catch (Exception e) {
113
                logger.error("Can't autoidentifyEPSG.", e);
114
            }
115
        }
116
        if(!StringUtils.isEmpty(authorityCode) && !StringUtils.isEmpty(authorityName)){
117
            name = authorityName+":"+authorityCode;
118
        }
119
        abrev = name;
120
        epsg_code = Integer.parseInt(authorityCode);
140 121

  
141
    		setName(fullCode);
142
    		//setAbrev(crsWkt.getName());
143
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
122
        datum = new CRSDatum(spatialReference.GetSemiMajor(), spatialReference.GetInvFlattening());
123
        proj4String = spatialReference.ExportToProj4();
124
//            crsWkt = new CrsWkt(authorityName+":"+authorityCode);
125
        crsWkt = new CrsWkt(spatialReference);
126
        setWKT(spatialReference.ExportToWkt());
127
    }
144 128

  
145
    	}
146
		//	Asignar el datum y el crs base (en el caso de ser projectado):
147
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
148
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
149
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
150
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
129
    public Crs(int epsgCode, int aut) throws CrsException {
130
        String strEpsgCode = "";
131
        if (aut == 1) {
132
            strEpsgCode = "EPSG:" + epsgCode;
133
        } else if (aut == 2) {
134
            strEpsgCode = "ESRI:" + epsgCode;
135
        } else if (aut == 3) {
136
            strEpsgCode = "IAU2000:" + epsgCode;
137
        } else if (aut == 4) {
138
            strEpsgCode = "USR:" + epsgCode;
139
        } else
140
            System.out.println("Error, autorithy err?neo");
141
        crsWkt = new CrsWkt(strEpsgCode);
142
        setWKT(crsWkt.getWkt());
143
    }
151 144

  
152
			//crs base (en el caso de ser projectado):
153
			/*if(this.isProjected()){
154
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
155
				crsBase = new CrsProj(proj4Base);
156
			}*/
157
		}
158
	}
145
    /**
146
     * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
147
     *
148
     * @param code
149
     * @throws CrsException
150
     */
151
    public Crs(String code) throws CrsException {
152
        String fullCode;
153
        setWKT(code);
154
        if (code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
155
            fullCode = code;
156
        else
157
            fullCode = "EPSG:" + code;
158
        String cod = "";
159
        if (code.length() < 15) {
160
            code = code.substring(code.indexOf(":") + 1);
161
            try {
162
                // Creamos el objeto que tendra los diferentes parametros de la
163
                // cadena Wkt
164
                crsWkt = new CrsWkt(fullCode);
165
                setName(fullCode);
166
                setAbrev(fullCode);
159 167

  
160
	/**
161
	 *Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
162
	 *
163
	 * @param epsg_cod
164
	 * @param code
165
	 * @throws CrsException
166
	 */
167
	public Crs(int epsg_cod, String code) throws CrsException {
168
		String fullCode;
169
		setWKT(code);
170
		setCode(epsg_cod);
171
		if(code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
172
			fullCode = code;
173
		else fullCode = "EPSG:"+code;
174
		String cod = "";
175
		if(code.length() < 15 ) {
176
			code = code.substring(code.indexOf(":")+1);
177
			try {
178
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
179
				crsWkt = new CrsWkt(fullCode);
180
				setName(fullCode);
181
				setAbrev(fullCode);
168
            } catch (NumberFormatException e) {
169
                logger.error("Can't Wkt.", e);
170
            }
171
        } else {
172
            String aux;
173
            String code2 = "";
174
            for (int i = 0; i < code.length(); i++) {
175
                aux = "" + code.charAt(i);
176
                if (!aux.equals(" ")) {
177
                    code2 += aux;
178
                } else {
179
                    code2 += "";
180
                }
181
            }
182
            crsWkt = new CrsWkt(code2);
182 183

  
183
			} catch (NumberFormatException e) {
184
				logger.error("Can't get Wkt.",e);
185
			}
186
		}else {
187
			String aux;
188
			String code2 = "";
189
			for(int i = 0; i < code.length(); i++) {
190
				aux = ""+code.charAt(i);
191
				if(!aux.equals(" ")) {
192
					code2+=aux;
193
				}else {
194
					code2 += "";
195
				}
196
			}
197
			crsWkt = new CrsWkt(code2);
198
			/*
199
			 * Arreglo temporal para ver si funcionan de la iau2000 las proyecciones
200
			 * cilindrica equidistante y oblicua cilindrica equidistante
201
			 * que no estan en gdal, por lo que asignaremos directamente su cadena
202
			 * en proj4 para trabajar con ellas
203
			 */
204
			if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
205
	    		setName(fullCode);
206
	    		//setAbrev(crsWkt.getName());
207
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
208
			}
209
			else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){
210
				String spheroid1 = crsWkt.getSpheroid()[1];
211
				String spheroid2 = crsWkt.getSpheroid()[2];
212
				String centralMeridian = "";
213
				String falseNorthing = "";
214
				String falseEasting = "";
215
				String standardParallel1 = "0.0";
216
				for (int i=0; i<crsWkt.getParam_name().length;i++){
217
					if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
218
						centralMeridian = crsWkt.getParam_value()[i];
219
					if (crsWkt.getParam_name()[i].equals("False_Easting"))
220
						falseEasting = crsWkt.getParam_value()[i];
221
					if(crsWkt.getParam_name()[i].equals("False_Northing"))
222
						falseNorthing = crsWkt.getParam_value()[i];
223
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
224
						standardParallel1 = crsWkt.getParam_value()[i];
225
				}
226
				if (spheroid2.equals("0.0")){
227
					proj4String = "+proj=eqc +a=" + spheroid1 +
228
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
229
					" +lat_ts="+standardParallel1;
230
				} else {
231
					proj4String = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 +
232
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
233
					" +lat_ts="+standardParallel1;
234
				}
235
				setName(fullCode);
236
	    		//setAbrev(crsWkt.getName());
237
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
184
            setName(fullCode);
185
            // setAbrev(crsWkt.getName());
186
            setAbrev(crsWkt.getAuthority()[0] + ":" + crsWkt.getAuthority()[1]);
238 187

  
239
			}
240
			else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
241
				String spheroid1 = crsWkt.getSpheroid()[1];
242
				String spheroid2 = crsWkt.getSpheroid()[2];
243
				String centralMeridian = "";
244
				String falseNorthing = "";
245
				String falseEasting = "";
246
				String standardParallel1 = "";
247
				String standardParallel2 = "0.0";
248
				for (int i=0; i<crsWkt.getParam_name().length;i++){
249
					if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
250
						centralMeridian = crsWkt.getParam_value()[i];
251
					if (crsWkt.getParam_name()[i].equals("False_Easting"))
252
						falseEasting = crsWkt.getParam_value()[i];
253
					if(crsWkt.getParam_name()[i].equals("False_Northing"))
254
						falseNorthing = crsWkt.getParam_value()[i];
255
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
256
						standardParallel1 = crsWkt.getParam_value()[i];
257
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2"))
258
						standardParallel2 = crsWkt.getParam_value()[i];
259
				}
260
				if (spheroid2.equals("0.0")){
261
					proj4String = "+proj=ocea +a="+ spheroid1  +
262
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
263
					" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
264
					" +lon_2=long_2 +no_defs";
265
				} else {
266
					proj4String = "+proj=ocea +a="+ spheroid1 + " +rf=" + spheroid2 +
267
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
268
					" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
269
					" +lon_2=long_2 +no_defs";
270
				}
271
				setName(fullCode);
272
	    		//setAbrev(crsWkt.getName());
273
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
274
			}
275
		}
276
		//	Asignar el datum:
277
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
278
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
279
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
280
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
188
        }
189
        // Asignar el datum y el crs base (en el caso de ser projectado):
190
        if (!(crsWkt.getSpheroid()[1].equals("") || crsWkt.getSpheroid()[2].equals(""))) {
191
            double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
192
            double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
193
            datum = new CRSDatum(eSemiMajorAxis, eIFlattening);
281 194

  
282
			// Crs base (en el caso de ser projectado):
283
			/*if(this.isProjected()){
284
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
285
				crsBase = new CrsProj(proj4Base);
286
			}*/
287
		}
288
	}
195
            // crs base (en el caso de ser projectado):
196
            /*
197
             * if(this.isProjected()){
198
             * String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1]
199
             * + " +rf=" + crsWkt.getSpheroid()[2] ;
200
             * crsBase = new CrsProj(proj4Base);
201
             * }
202
             */
203
        }
204
    }
289 205

  
290
	/**
291
	 * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
292
	 * En el caso de WKT le a?ade a la cadena proj4 el string params.
293
	 *
294
	 * @param epsg_cod
295
	 * @param code
296
	 * @param params
297
	 * @throws CrsException
298
	 */
299
	public Crs(int epsg_cod, String code,String params) throws CrsException {
300
		String fullCode;
301
		setCode(epsg_cod);
302
		setWKT(code);
303
		if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
304
			fullCode = code;
305
		else fullCode = "EPSG:"+code;
306
		String cod = "";
307
		if(code.length() < 15 ) {
308
			code = code.substring(code.indexOf(":")+1);
309
			try {
310
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
311
				crsWkt = new CrsWkt(fullCode);
206
    /**
207
     * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
208
     *
209
     * @param epsg_cod
210
     * @param code
211
     * @throws CrsException
212
     */
213
    public Crs(int epsg_cod, String code) throws CrsException {
214
        String fullCode;
215
        setWKT(code);
216
        setCode(epsg_cod);
217
        if (code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P')
218
            fullCode = code;
219
        else
220
            fullCode = "EPSG:" + code;
312 221

  
313
				setName(fullCode);
314
				setAbrev(fullCode);
222
        SpatialReference sr = new SpatialReference();
223
//        Vector<String> vector = new Vector<String>();
224
//        vector.add(code);
225
//        sr.ImportFromWkt(vector);
226
        sr.ImportFromWkt(code);
227
        initFromSpatialReference(sr);
315 228

  
316
			} catch (NumberFormatException e) {
317
				logger.error("Can't get Wkt.",e);
318
			}
319
		}else {
320
			String aux;
321
			String code2 = "";
322
			for(int i = 0; i < code.length(); i++) {
323
				aux = ""+code.charAt(i);
324
				if(!aux.equals(" ")) {
325
					code2+=aux;
326
				}else {
327
					code2 += "";
328
				}
329
			}
330
			crsWkt = new CrsWkt(code2);
229
//        String cod = "";
230
//        if (code.length() < 15) {
231
//            code = code.substring(code.indexOf(":") + 1);
232
//            try {
233
//                // Creamos el objeto que tendra los diferentes parametros de la
234
//                // cadena Wkt
235
//                crsWkt = new CrsWkt(fullCode);
236
//                setName(fullCode);
237
//                setAbrev(fullCode);
238
//
239
//            } catch (NumberFormatException e) {
240
//                logger.error("Can't get Wkt.", e);
241
//            }
242
//        } else {
243
//            String aux;
244
//            String code2 = "";
245
//            for (int i = 0; i < code.length(); i++) {
246
//                aux = "" + code.charAt(i);
247
//                if (!aux.equals(" ")) {
248
//                    code2 += aux;
249
//                } else {
250
//                    code2 += "";
251
//                }
252
//            }
253
//            crsWkt = new CrsWkt(code2);
254
//            /*
255
//             * Arreglo temporal para ver si funcionan de la iau2000 las
256
//             * proyecciones
257
//             * cilindrica equidistante y oblicua cilindrica equidistante
258
//             * que no estan en gdal, por lo que asignaremos directamente su
259
//             * cadena
260
//             * en proj4 para trabajar con ellas
261
//             */
262
//            if (!crsWkt.getProjection().equals("Equidistant_Cylindrical")
263
//                && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")) {
264
//                setName(fullCode);
265
//                // setAbrev(crsWkt.getName());
266
//                setAbrev(crsWkt.getAuthority()[0] + ":" + crsWkt.getAuthority()[1]);
267
//            } else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")) {
268
//                String spheroid1 = crsWkt.getSpheroid()[1];
269
//                String spheroid2 = crsWkt.getSpheroid()[2];
270
//                String centralMeridian = "";
271
//                String falseNorthing = "";
272
//                String falseEasting = "";
273
//                String standardParallel1 = "0.0";
274
//                for (int i = 0; i < crsWkt.getParam_name().length; i++) {
275
//                    if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
276
//                        centralMeridian = crsWkt.getParam_value()[i];
277
//                    if (crsWkt.getParam_name()[i].equals("False_Easting"))
278
//                        falseEasting = crsWkt.getParam_value()[i];
279
//                    if (crsWkt.getParam_name()[i].equals("False_Northing"))
280
//                        falseNorthing = crsWkt.getParam_value()[i];
281
//                    if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
282
//                        standardParallel1 = crsWkt.getParam_value()[i];
283
//                }
284
//                if (spheroid2.equals("0.0")) {
285
//                    proj4String =
286
//                        "+proj=eqc +a=" + spheroid1 + " +lon_0=" + centralMeridian + " +x_0=" + falseEasting + " +y_0="
287
//                            + falseNorthing + " +lat_ts=" + standardParallel1;
288
//                } else {
289
//                    proj4String =
290
//                        "+proj=eqc +a=" + spheroid1 + " +rf=" + spheroid2 + " +lon_0=" + centralMeridian + " +x_0="
291
//                            + falseEasting + " +y_0=" + falseNorthing + " +lat_ts=" + standardParallel1;
292
//                }
293
//                setName(fullCode);
294
//                // setAbrev(crsWkt.getName());
295
//                setAbrev(crsWkt.getAuthority()[0] + ":" + crsWkt.getAuthority()[1]);
296
//
297
//            } else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")) {
298
//                String spheroid1 = crsWkt.getSpheroid()[1];
299
//                String spheroid2 = crsWkt.getSpheroid()[2];
300
//                String centralMeridian = "";
301
//                String falseNorthing = "";
302
//                String falseEasting = "";
303
//                String standardParallel1 = "";
304
//                String standardParallel2 = "0.0";
305
//                for (int i = 0; i < crsWkt.getParam_name().length; i++) {
306
//                    if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
307
//                        centralMeridian = crsWkt.getParam_value()[i];
308
//                    if (crsWkt.getParam_name()[i].equals("False_Easting"))
309
//                        falseEasting = crsWkt.getParam_value()[i];
310
//                    if (crsWkt.getParam_name()[i].equals("False_Northing"))
311
//                        falseNorthing = crsWkt.getParam_value()[i];
312
//                    if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
313
//                        standardParallel1 = crsWkt.getParam_value()[i];
314
//                    if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2"))
315
//                        standardParallel2 = crsWkt.getParam_value()[i];
316
//                }
317
//                if (spheroid2.equals("0.0")) {
318
//                    proj4String =
319
//                        "+proj=ocea +a=" + spheroid1 + " +lon_0=" + centralMeridian + " +x_0=" + falseEasting
320
//                            + " +y_0=" + falseNorthing + " +lat_1=" + standardParallel1 + " +lat_2="
321
//                            + standardParallel2 + " +lon_1=long_1" + " +lon_2=long_2 +no_defs";
322
//                } else {
323
//                    proj4String =
324
//                        "+proj=ocea +a=" + spheroid1 + " +rf=" + spheroid2 + " +lon_0=" + centralMeridian + " +x_0="
325
//                            + falseEasting + " +y_0=" + falseNorthing + " +lat_1=" + standardParallel1 + " +lat_2="
326
//                            + standardParallel2 + " +lon_1=long_1" + " +lon_2=long_2 +no_defs";
327
//                }
328
//                setName(fullCode);
329
//                // setAbrev(crsWkt.getName());
330
//                setAbrev(crsWkt.getAuthority()[0] + ":" + crsWkt.getAuthority()[1]);
331
//            }
332
//        }
333
//        // Asignar el datum:
334
//        if (!(crsWkt.getSpheroid()[1].equals("") || crsWkt.getSpheroid()[2].equals(""))) {
335
//            double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
336
//            double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
337
//            datum = new CRSDatum(eSemiMajorAxis, eIFlattening);
338
//
339
//            // Crs base (en el caso de ser projectado):
340
//            /*
341
//             * if(this.isProjected()){
342
//             * String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1]
343
//             * + " +rf=" + crsWkt.getSpheroid()[2] ;
344
//             * crsBase = new CrsProj(proj4Base);
345
//             * }
346
//             */
347
//        }
348
    }
331 349

  
332
    		setName(fullCode);
333
    		//setAbrev(crsWkt.getName());
334
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
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
366
            fullCode = "EPSG:" + code;
367
        String cod = "";
368
        if (code.length() < 15) {
369
            code = code.substring(code.indexOf(":") + 1);
370
            try {
371
                // Creamos el objeto que tendra los diferentes parametros de la
372
                // cadena Wkt
373
                crsWkt = new CrsWkt(fullCode);
335 374

  
336
		}
337
		//	Asignar el datum:
338
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
339
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
340
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
341
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
375
                setName(fullCode);
376
                setAbrev(fullCode);
342 377

  
343
			// Crs base (en el caso de ser projectado):
344
			/*if(this.isProjected()){
345
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
346
				crsBase = new CrsProj(proj4Base);
347
			}*/
348
		}
349
	}
378
            } catch (NumberFormatException e) {
379
                logger.error("Can't get Wkt.", e);
380
            }
381
        } else {
382
            String aux;
383
            String code2 = "";
384
            for (int i = 0; i < code.length(); i++) {
385
                aux = "" + code.charAt(i);
386
                if (!aux.equals(" ")) {
387
                    code2 += aux;
388
                } else {
389
                    code2 += "";
390
                }
391
            }
392
            crsWkt = new CrsWkt(code2);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff