root / org.gvsig.jcrs / libJCRS / src-test / es / idr / test / ValidateEpsgCRSs.java @ 38
History | View | Annotate | Download (5.25 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.gvsig.crs.Crs; |
16 |
import org.gvsig.crs.CrsException; |
17 |
import org.geotools.referencing.factory.epsg.HSQLDataSource; |
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 |
ArrayList validos = new ArrayList(); |
50 |
while (result.next()) {
|
51 |
int cod = result.getInt("COORD_REF_SYS_CODE"); |
52 |
|
53 |
String strEpsgCode="EPSG:"+cod; |
54 |
CoordinateReferenceSystem source; |
55 |
|
56 |
try {
|
57 |
source = CRS.decode(strEpsgCode); |
58 |
validos.add(String.valueOf(cod));
|
59 |
if (source instanceof DefaultProjectedCRS) { |
60 |
String str;
|
61 |
boolean esta = false; |
62 |
DefaultProjectedCRS sour = (DefaultProjectedCRS) source; |
63 |
|
64 |
Unit u = ((DefaultGeodeticDatum) sour.getDatum()).getPrimeMeridian().getAngularUnit(); |
65 |
units.add(u.toString()); |
66 |
|
67 |
/*for (int j = 0; j< units.size(); j++) {
|
68 |
if (units.get(j).equals(u.toString())){
|
69 |
esta = true;
|
70 |
break;
|
71 |
}
|
72 |
}
|
73 |
if (!esta){
|
74 |
units.add(u.toString());
|
75 |
esta = false;
|
76 |
}*/
|
77 |
for (int i=0; i< sour.getConversionFromBase().getParameterValues().values().size();i++) { |
78 |
str = sour.getConversionFromBase().getParameterValues().values().get(i).toString(); |
79 |
u = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).getUnit(); |
80 |
units.add(u.toString()); |
81 |
|
82 |
} |
83 |
} |
84 |
if (source instanceof DefaultGeographicCRS) { |
85 |
DefaultGeographicCRS sour = (DefaultGeographicCRS) source; |
86 |
boolean esta = false; |
87 |
Unit u = ((DefaultGeodeticDatum) sour.getDatum()).getPrimeMeridian().getAngularUnit(); |
88 |
units.add(u.toString()); |
89 |
|
90 |
} |
91 |
} catch (NoSuchAuthorityCodeException e) {
|
92 |
res.add(String.valueOf(cod)+" --> "+e); |
93 |
// TODO Auto-generated catch block
|
94 |
//e.printStackTrace();
|
95 |
} catch (FactoryException e) {
|
96 |
res.add(String.valueOf(cod)+" --> "+e); |
97 |
// TODO Auto-generated catch block
|
98 |
//e.printStackTrace();
|
99 |
} |
100 |
} |
101 |
for (int i = 0; i< res.size(); i++) { |
102 |
System.out.println(res.get(i));
|
103 |
} |
104 |
for (int i = 0; i< units.size(); i++) { |
105 |
System.out.println(units.get(i));
|
106 |
} |
107 |
System.out.println("Numero CRSs validos: " + validos.size()); |
108 |
System.out.println("Numero CRSs fallidos: " + res.size()); |
109 |
System.out.println("Numero medidas: " + units.size()); |
110 |
} catch (SQLException e1) { |
111 |
// TODO Auto-generated catch block
|
112 |
e1.printStackTrace(); |
113 |
} |
114 |
} |
115 |
|
116 |
} |
117 |
|
118 |
|
119 |
/*CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
|
120 |
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:23032");
|
121 |
|
122 |
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
|
123 |
System.out.println("Dimensiones: "+transform.getSourceDimensions());
|
124 |
double points[] = {2.5,3.0};
|
125 |
System.out.println("Puntos fuente: "+ points[0]+" "+points[1]);
|
126 |
transform.transform(points, 0, points, 0, 1);
|
127 |
System.out.println("Puntos destino: "+ points[0]+" "+points[1]);
|
128 |
|
129 |
int epsgCount = 0;
|
130 |
System.out.println("CRSs Disponibles en EPSG: \n");
|
131 |
Set codes = CRS.getSupportedCodes("EPSG");
|
132 |
for (Iterator iter = codes.iterator(); iter.hasNext();) {
|
133 |
String code = (String) iter.next();
|
134 |
System.out.println("EPSG:"+code);
|
135 |
epsgCount++;
|
136 |
}
|
137 |
System.out.println("N�mero de CRSs en EPSG: "+epsgCount);
|
138 |
try {
|
139 |
System.out.println("Descripci�n de EPSG:23030: \n"+CRS.getAuthorityFactory(false).getDescriptionText("EPSG:23030"));
|
140 |
} catch (FactoryRegistryException e) {
|
141 |
// TODO Auto-generated catch block
|
142 |
e.printStackTrace();
|
143 |
} catch (FactoryException e) {
|
144 |
// TODO Auto-generated catch block
|
145 |
e.printStackTrace();
|
146 |
}
|
147 |
|
148 |
} catch (NoSuchAuthorityCodeException e) {
|
149 |
// TODO Auto-generated catch block
|
150 |
e.printStackTrace();
|
151 |
} catch (FactoryException e) {
|
152 |
// TODO Auto-generated catch block
|
153 |
e.printStackTrace();
|
154 |
}*/
|
155 |
|