root / org.gvsig.jcrs / libJCRS / src-test / es / idr / test / ValidateEsriCRSs.java @ 38
History | View | Annotate | Download (4.07 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.opengis.referencing.FactoryException; |
17 |
import org.opengis.referencing.NoSuchAuthorityCodeException; |
18 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
19 |
|
20 |
import es.idr.teledeteccion.connection.EpsgConnection; |
21 |
import es.idr.teledeteccion.connection.Query; |
22 |
|
23 |
public class ValidateEsriCRSs { |
24 |
|
25 |
public ValidateEsriCRSs() {
|
26 |
|
27 |
} |
28 |
|
29 |
/**
|
30 |
* @param args
|
31 |
*/
|
32 |
public static void main(String[] args) { |
33 |
//HSQLDataSource ds = new HSQLDataSource();
|
34 |
EpsgConnection conn = new EpsgConnection();
|
35 |
//Connection conn;
|
36 |
conn.setConnectionEsri(); |
37 |
try {
|
38 |
//conn = ds.getConnection();
|
39 |
|
40 |
//final PreparedStatement stmt;
|
41 |
/*stmt = conn.prepareStatement("SELECT esri_code"
|
42 |
+ " FROM esri");
|
43 |
*/
|
44 |
String sentence = "SELECT esri_code,esri_wkt " + |
45 |
"FROM ESRI";
|
46 |
ResultSet result;
|
47 |
result = Query.select(sentence,conn.getConnection());
|
48 |
|
49 |
|
50 |
|
51 |
//result = stmt.executeQuery();
|
52 |
|
53 |
ArrayList res = new ArrayList(); |
54 |
ArrayList units = new ArrayList(); |
55 |
ArrayList validos = new ArrayList(); |
56 |
while (result.next()) {
|
57 |
int cod = result.getInt("esri_code"); |
58 |
String wkt = result.getString("esri_wkt"); |
59 |
//String strEpsgCode="ESRI:"+cod;
|
60 |
CoordinateReferenceSystem source; |
61 |
|
62 |
/*try {
|
63 |
source = CRS.parseWKT(wkt);
|
64 |
validos.add(String.valueOf(cod));
|
65 |
if (source instanceof DefaultProjectedCRS) {
|
66 |
String str;
|
67 |
boolean esta = false;
|
68 |
DefaultProjectedCRS sour = (DefaultProjectedCRS) source;
|
69 |
|
70 |
Unit u = ((DefaultGeodeticDatum) sour.getDatum()).getPrimeMeridian().getAngularUnit();
|
71 |
units.add(u.toString());
|
72 |
|
73 |
for (int j = 0; j< units.size(); j++) {
|
74 |
if (units.get(j).equals(u.toString())){
|
75 |
esta = true;
|
76 |
break;
|
77 |
}
|
78 |
}
|
79 |
if (!esta){
|
80 |
units.add(u.toString());
|
81 |
esta = false;
|
82 |
}
|
83 |
for (int i=0; i< sour.getConversionFromBase().getParameterValues().values().size();i++) {
|
84 |
str = sour.getConversionFromBase().getParameterValues().values().get(i).toString();
|
85 |
u = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).getUnit();
|
86 |
units.add(u.toString());
|
87 |
|
88 |
}
|
89 |
}
|
90 |
if (source instanceof DefaultGeographicCRS) {
|
91 |
DefaultGeographicCRS sour = (DefaultGeographicCRS) source;
|
92 |
boolean esta = false;
|
93 |
Unit u = ((DefaultGeodeticDatum) sour.getDatum()).getPrimeMeridian().getAngularUnit();
|
94 |
units.add(u.toString());
|
95 |
|
96 |
}
|
97 |
} catch (NoSuchAuthorityCodeException e) {
|
98 |
res.add(String.valueOf(cod)+" --> "+e);
|
99 |
// TODO Auto-generated catch block
|
100 |
//e.printStackTrace();
|
101 |
} catch (FactoryException e) {
|
102 |
res.add(String.valueOf(cod)+" --> "+e);
|
103 |
// TODO Auto-generated catch block
|
104 |
//e.printStackTrace();
|
105 |
}*/
|
106 |
} |
107 |
/*for (int i = 0; i< res.size(); i++) {
|
108 |
System.out.println(res.get(i));
|
109 |
}*/
|
110 |
for (int i = 0; i< units.size(); i++) { |
111 |
System.out.println(units.get(i));
|
112 |
} |
113 |
System.out.println("Numero CRSs validos: " + validos.size()); |
114 |
System.out.println("Numero medidas: " + units.size()); |
115 |
System.out.println("Numero CRSs fallidos: " + res.size()); |
116 |
} catch (SQLException e1) { |
117 |
// TODO Auto-generated catch block
|
118 |
e1.printStackTrace(); |
119 |
} |
120 |
} |
121 |
} |