root / branches / F2 / libraries / libJCRS / src-test / es / idr / test / ValidateEpsgCRSs.java @ 11106
History | View | Annotate | Download (4.95 KB)
1 |
package es.idr.test; |
---|---|
2 |
|
3 |
import java.sql.Connection; |
4 |
import java.sql.PreparedStatement; |
5 |
import java.sql.ResultSet; |
6 |
import java.sql.SQLException; |
7 |
import java.util.ArrayList; |
8 |
|
9 |
import javax.units.Unit; |
10 |
|
11 |
import org.geotools.referencing.CRS; |
12 |
import org.geotools.referencing.crs.DefaultGeographicCRS; |
13 |
import org.geotools.referencing.crs.DefaultProjectedCRS; |
14 |
import org.geotools.referencing.datum.DefaultGeodeticDatum; |
15 |
import org.geotools.referencing.factory.epsg.HSQLDataSource; |
16 |
import org.gvsig.crs.Crs; |
17 |
import org.gvsig.crs.CrsException; |
18 |
import org.opengis.referencing.FactoryException; |
19 |
import org.opengis.referencing.NoSuchAuthorityCodeException; |
20 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
21 |
import org.opengis.referencing.crs.GeographicCRS; |
22 |
|
23 |
|
24 |
|
25 |
public class ValidateEpsgCRSs { |
26 |
|
27 |
public ValidateEpsgCRSs() {
|
28 |
|
29 |
} |
30 |
|
31 |
/**
|
32 |
* @param args
|
33 |
*/
|
34 |
public static void main(String[] args) { |
35 |
HSQLDataSource ds = new HSQLDataSource();
|
36 |
Connection conn;
|
37 |
try {
|
38 |
conn = ds.getConnection(); |
39 |
|
40 |
final PreparedStatement stmt; |
41 |
stmt = conn.prepareStatement("SELECT COORD_REF_SYS_CODE"
|
42 |
+ " FROM epsg_coordinatereferencesystem");
|
43 |
ResultSet result;
|
44 |
|
45 |
result = stmt.executeQuery(); |
46 |
|
47 |
ArrayList res = new ArrayList(); |
48 |
ArrayList units = new ArrayList(); |
49 |
while (result.next()) {
|
50 |
int cod = result.getInt("COORD_REF_SYS_CODE"); |
51 |
|
52 |
String strEpsgCode="EPSG:"+cod; |
53 |
CoordinateReferenceSystem source; |
54 |
|
55 |
try {
|
56 |
source = CRS.decode(strEpsgCode); |
57 |
if (source instanceof DefaultProjectedCRS) { |
58 |
String str;
|
59 |
boolean esta = false; |
60 |
DefaultProjectedCRS sour = (DefaultProjectedCRS) source; |
61 |
|
62 |
Unit u = ((DefaultGeodeticDatum) sour.getDatum()).getPrimeMeridian().getAngularUnit(); |
63 |
units.add(u.toString()); |
64 |
|
65 |
/*for (int j = 0; j< units.size(); j++) {
|
66 |
if (units.get(j).equals(u.toString())){
|
67 |
esta = true;
|
68 |
break;
|
69 |
}
|
70 |
}
|
71 |
if (!esta){
|
72 |
units.add(u.toString());
|
73 |
esta = false;
|
74 |
}*/
|
75 |
for (int i=0; i< sour.getConversionFromBase().getParameterValues().values().size();i++) { |
76 |
str = sour.getConversionFromBase().getParameterValues().values().get(i).toString(); |
77 |
u = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).getUnit(); |
78 |
units.add(u.toString()); |
79 |
|
80 |
} |
81 |
} |
82 |
if (source instanceof DefaultGeographicCRS) { |
83 |
DefaultGeographicCRS sour = (DefaultGeographicCRS) source; |
84 |
boolean esta = false; |
85 |
Unit u = ((DefaultGeodeticDatum) sour.getDatum()).getPrimeMeridian().getAngularUnit(); |
86 |
units.add(u.toString()); |
87 |
|
88 |
} |
89 |
} catch (NoSuchAuthorityCodeException e) {
|
90 |
res.add(String.valueOf(cod)+" --> "+e); |
91 |
// TODO Auto-generated catch block
|
92 |
//e.printStackTrace();
|
93 |
} catch (FactoryException e) {
|
94 |
res.add(String.valueOf(cod)+" --> "+e); |
95 |
// TODO Auto-generated catch block
|
96 |
//e.printStackTrace();
|
97 |
} |
98 |
} |
99 |
for (int i = 0; i< res.size(); i++) { |
100 |
System.out.println(res.get(i));
|
101 |
} |
102 |
for (int i = 0; i< units.size(); i++) { |
103 |
System.out.println(units.get(i));
|
104 |
} |
105 |
System.out.println("Numero CRSs fallidos: " + res.size()); |
106 |
System.out.println("Numero medidas: " + units.size()); |
107 |
} catch (SQLException e1) { |
108 |
// TODO Auto-generated catch block
|
109 |
e1.printStackTrace(); |
110 |
} |
111 |
} |
112 |
|
113 |
} |
114 |
|
115 |
|
116 |
/*CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
|
117 |
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:23032");
|
118 |
|
119 |
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
|
120 |
System.out.println("Dimensiones: "+transform.getSourceDimensions());
|
121 |
double points[] = {2.5,3.0};
|
122 |
System.out.println("Puntos fuente: "+ points[0]+" "+points[1]);
|
123 |
transform.transform(points, 0, points, 0, 1);
|
124 |
System.out.println("Puntos destino: "+ points[0]+" "+points[1]);
|
125 |
|
126 |
int epsgCount = 0;
|
127 |
System.out.println("CRSs Disponibles en EPSG: \n");
|
128 |
Set codes = CRS.getSupportedCodes("EPSG");
|
129 |
for (Iterator iter = codes.iterator(); iter.hasNext();) {
|
130 |
String code = (String) iter.next();
|
131 |
System.out.println("EPSG:"+code);
|
132 |
epsgCount++;
|
133 |
}
|
134 |
System.out.println("N�mero de CRSs en EPSG: "+epsgCount);
|
135 |
try {
|
136 |
System.out.println("Descripci�n de EPSG:23030: \n"+CRS.getAuthorityFactory(false).getDescriptionText("EPSG:23030"));
|
137 |
} catch (FactoryRegistryException e) {
|
138 |
// TODO Auto-generated catch block
|
139 |
e.printStackTrace();
|
140 |
} catch (FactoryException e) {
|
141 |
// TODO Auto-generated catch block
|
142 |
e.printStackTrace();
|
143 |
}
|
144 |
|
145 |
} catch (NoSuchAuthorityCodeException e) {
|
146 |
// TODO Auto-generated catch block
|
147 |
e.printStackTrace();
|
148 |
} catch (FactoryException e) {
|
149 |
// TODO Auto-generated catch block
|
150 |
e.printStackTrace();
|
151 |
}*/
|
152 |
|