Statistics
| Revision:

root / branches / F2 / libraries / libJCRS / src-test / es / idr / test / ValidateEsriCRSs.java @ 11106

History | View | Annotate | Download (3.76 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.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
}