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