Revision 11279

View differences:

branches/F2/libraries/libJCRS/src-test/es/idr/test/ValidateEsriCRSs.java
51 51
			
52 52
	        ArrayList res = new ArrayList();
53 53
	        ArrayList units = new ArrayList();
54
	        ArrayList validos = new ArrayList();
54 55
	        while (result.next()) {
55 56
	        	int cod = result.getInt("esri_code");
56 57
	        	String wkt = result.getString("esri_wkt");
......
59 60
        		
60 61
        			try {
61 62
						source = CRS.parseWKT(wkt);
63
						validos.add(String.valueOf(cod));
62 64
						if (source instanceof DefaultProjectedCRS) {
63 65
							String str;
64 66
							boolean esta = false;
......
107 109
	        for (int i = 0; i< units.size(); i++) {
108 110
	        	System.out.println(units.get(i));
109 111
	        }
112
	        System.out.println("Numero CRSs validos: " + validos.size());
110 113
	        System.out.println("Numero medidas: " + units.size());
111 114
	        System.out.println("Numero CRSs fallidos: " + res.size());
112 115
		} catch (SQLException e1) {
branches/F2/libraries/libJCRS/src-test/es/idr/test/connection/UsrConnection.java
1
package es.idr.test.connection;
2

  
3
import java.sql.Connection;
4
import java.sql.DriverManager;
5
import java.sql.SQLException;
6
import java.sql.Statement;
7

  
8
public class UsrConnection {
9

  
10
	Connection connect;
11
	
12
	public UsrConnection() {
13
		try {
14
			Class.forName("org.hsqldb.jdbcDriver");
15
		} catch (ClassNotFoundException e) {
16
			e.printStackTrace();
17
		}
18
		
19
		try {			
20
			connect =  DriverManager.getConnection("jdbc:hsqldb:file:/home/jlgomez/gvSIGF2/crsTest/usr", "sa", "");			
21
		} catch (SQLException e1) {
22
			e1.printStackTrace();
23
		}
24
	}
25
	
26
	public Connection getConnection(){
27
		return connect;
28
	}
29
	
30
	public void shutdown() throws SQLException {
31

  
32
        Statement st = connect.createStatement();
33

  
34
        // db writes out to files and performs clean shuts down
35
        // otherwise there will be an unclean shutdown
36
        // when program ends
37
        st.execute("SHUTDOWN");
38
        connect.close();    // if there are no other open connection
39
    }
40
	
41
	public synchronized void update(String expression) throws SQLException {
42

  
43
        Statement st = null;
44

  
45
        st = connect.createStatement();    // statements
46

  
47
        int i = st.executeUpdate(expression);    // run the query
48

  
49
        if (i == -1) {
50
            System.out.println("db error : " + expression);
51
        }
52

  
53
        st.close();
54
    }    
55
}
0 56

  
branches/F2/libraries/libJCRS/src-test/es/idr/test/ValidateEpsgCRSs.java
46 46
			
47 47
	        ArrayList res = new ArrayList();
48 48
	        ArrayList units = new ArrayList();
49
	        ArrayList validos = new ArrayList();
49 50
	        while (result.next()) {
50 51
	        	int cod = result.getInt("COORD_REF_SYS_CODE");
51 52
	        	
......
54 55
        		
55 56
        			try {
56 57
						source = CRS.decode(strEpsgCode);
58
						validos.add(String.valueOf(cod));
57 59
						if (source instanceof DefaultProjectedCRS) {
58 60
							String str;
59 61
							boolean esta = false;
......
102 104
	        for (int i = 0; i< units.size(); i++) {
103 105
	        	System.out.println(units.get(i));
104 106
	        }
107
	        System.out.println("Numero CRSs validos: " + validos.size());
105 108
	        System.out.println("Numero CRSs fallidos: " + res.size());
106 109
	        System.out.println("Numero medidas: " + units.size());
107 110
		} catch (SQLException e1) {
branches/F2/libraries/libJCRS/src-test/es/idr/test/InsertUserDataCrs.java
1
package es.idr.test;
2

  
3
import java.sql.ResultSet;
4
import java.sql.SQLException;
5

  
6
import org.gvsig.crs.Query;
7

  
8
import es.idr.test.connection.UsrConnection;
9

  
10
public class InsertUserDataCrs {
11

  
12
	/**
13
	 * @param args
14
	 */
15
	public static void main(String[] args) {
16
		// TODO Auto-generated method stub
17
		UsrConnection conn = new UsrConnection();
18
		
19
		String sentence = "INSERT INTO USR VALUES(2000,'PROJCS[\"Anguilla_1957_British_West_Indies_Grid\",GEOGCS[\"GCS_Anguilla_1957\",DATUM[\"D_Anguilla_1957\",SPHEROID[\"Clarke_1880_RGS\",6378249.145,293.465]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",400000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-62.0],PARAMETER[\"Scale_Factor\",0.9995],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]','Anguilla_1957_British_West_Indies_Grid','GCS_Anguilla_1957','D_Anguilla_1957')";
20
		
21
		try {
22
			conn.update(sentence);			
23
			conn.shutdown();
24
		} catch (SQLException e) {
25
			// TODO Auto-generated catch block
26
			e.printStackTrace();
27
		}
28
	}
29

  
30
}
0 31

  
branches/F2/libraries/libJCRS/src-test/es/idr/test/TestWKTandProj4Epsg.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.ConversionException;
10
import javax.units.Unit;
11

  
12
import org.geotools.referencing.CRS;
13
import org.geotools.referencing.crs.DefaultGeographicCRS;
14
import org.geotools.referencing.crs.DefaultProjectedCRS;
15
import org.geotools.referencing.datum.DefaultGeodeticDatum;
16
import org.geotools.referencing.factory.epsg.HSQLDataSource;
17
import org.geotools.referencing.wkt.UnformattableObjectException;
18
import org.gvsig.crs.Crs;
19
import org.gvsig.crs.CrsException;
20
import org.gvsig.crs.Proj4;
21
import org.opengis.referencing.FactoryException;
22
import org.opengis.referencing.NoSuchAuthorityCodeException;
23
import org.opengis.referencing.crs.CoordinateReferenceSystem;
24

  
25
public class TestWKTandProj4Epsg {
26

  
27
	public static void main(String[] args) {
28
		HSQLDataSource ds = new HSQLDataSource();
29
		Connection conn;
30
		try {
31
			conn = ds.getConnection();
32
		
33
			final PreparedStatement stmt;
34
	        stmt = conn.prepareStatement("SELECT COORD_REF_SYS_CODE, COORD_REF_SYS_NAME"
35
	                                      + " FROM epsg_coordinatereferencesystem");
36
	        ResultSet result;
37
			
38
			result = stmt.executeQuery();
39
			
40
	        ArrayList wkt = new ArrayList();
41
	        ArrayList proj4 = new ArrayList();
42
	        ArrayList name = new ArrayList();
43
	        ArrayList codigo = new ArrayList();
44
	        ArrayList fallos = new ArrayList();
45
	        while (result.next()) {
46
	        	int cod = result.getInt("COORD_REF_SYS_CODE");
47
	        	codigo.add(String.valueOf(cod));
48
	        	name.add(result.getString("COORD_REF_SYS_NAME"));
49
        		
50
    			try {
51
					Crs crs = new Crs(cod,1);
52
					wkt.add(crs.getWKT());
53
					Proj4 proj= new Proj4();
54
					proj4.add(proj.exportToProj4(crs));
55
					
56
				} catch (CrsException e) {
57
					// TODO Auto-generated catch block
58
					e.printStackTrace();
59
				} catch (NumberFormatException e) {
60
					// TODO Auto-generated catch block
61
					//e.printStackTrace();
62
					fallos.add(""+cod+": "+e);
63
				} catch (ConversionException e) {
64
					// TODO Auto-generated catch block
65
					//e.printStackTrace();
66
					fallos.add(""+cod+": "+e);
67
				}catch (UnformattableObjectException e) {
68
					// TODO Auto-generated catch block
69
					//e.printStackTrace();
70
					fallos.add(""+cod+": "+e);
71
				}			
72
	        }
73
	        for (int i = 0; i< codigo.size(); i++) {
74
	        	System.out.println("C?digo: "+codigo.get(i)+"\tNombre: "+name.get(i));
75
	        	System.out.println("Cadena WKT: "+wkt.get(i));
76
	        	System.out.println("Cadena Proj4: "+name.get(i));
77
	        }	
78
	        for (int i = 0; i< fallos.size(); i++) {
79
	        	System.out.println(fallos.get(i));
80
	        	
81
	        }	
82
	       
83
	        System.out.println("Numero CRSs: " + codigo.size());	
84
	        System.out.println("Numero fallos: " + fallos.size());
85
		} catch (SQLException e1) {
86
			// TODO Auto-generated catch block
87
			e1.printStackTrace();
88
		}	
89
	}
90
}
0 91

  

Also available in: Unified diff