Revision 1998
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/projection/test/TestGeotools21.java | ||
---|---|---|
1 |
package es.idr.projection.test; |
|
2 |
|
|
3 |
import org.gvsig.crs.CrsException; |
|
4 |
import org.gvsig.crs.CrsFactory; |
|
5 |
import org.gvsig.crs.ICrs; |
|
6 |
import org.gvsig.crs.Proj4; |
|
7 |
import org.opengis.referencing.FactoryException; |
|
8 |
import org.opengis.referencing.NoSuchAuthorityCodeException; |
|
9 |
|
|
10 |
public class TestGeotools21 { |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* @param args |
|
15 |
*/ |
|
16 |
public static void main(String[] args) { |
|
17 |
try { |
|
18 |
String strEpsgCode; |
|
19 |
// Notas: |
|
20 |
// - transverse mercator south orientated no esta soportada por Proj4 |
|
21 |
// - Buscar ejemplo de la CylindricalEqualArea |
|
22 |
// - Buscar ejemplo de la AzimuthalEquidistant |
|
23 |
// - Buscar ejemplo de la Gnomonic |
|
24 |
// - Buscar ejemplo de la Bonne |
|
25 |
// - Buscar ejemplo de la Equirectangular |
|
26 |
// - Buscar ejemplo de la EquidistantConic |
|
27 |
// - Buscar ejemplo de la MillerCylindrical |
|
28 |
// - Buscar ejemplo de la Mollweide |
|
29 |
// - Buscar ejemplo de la EckertIV |
|
30 |
// - Buscar ejemplo de la EckertVI |
|
31 |
// - Buscar ejemplo de la Robinson |
|
32 |
// - Buscar ejemplo de la VanDerGrinten |
|
33 |
// - Buscar ejemplo de la Sinusoidal |
|
34 |
// - Buscar ejemplo de la GallStereographic |
|
35 |
// - Buscar ejemplo de la Goode |
|
36 |
|
|
37 |
//strEpsgCode="EPSG:2065"; // Krovak |
|
38 |
//strEpsgCode="EPSG:2052"; // tm south orientated No en mi Proj4 |
|
39 |
//strEpsgCode="EPSG:2084"; // tm south orientated |
|
40 |
//strEpsgCode="EPSG:32662"; // Plate Carree -> Funciona, problema elipsoide |
|
41 |
// Tomara como radio el semieje mayor del elipsoide |
|
42 |
//strEpsgCode="EPSG:27200"; // NewZealandMapGrid -> Mirar lo de +datum |
|
43 |
// He tenido que incluir un mecanismo para valores concretos de parametros |
|
44 |
strEpsgCode="EPSG:32761"; // CassiniSoldner -> Falla +to_meter=.. |
|
45 |
//strEpsgCode="EPSG:2099"; |
|
46 |
//strEpsgCode="EPSG:2200"; // en lugar de stere pone sterea,igual 2171 |
|
47 |
// 2036 - falla, 32661 |
|
48 |
//strEpsgCode="EPSG:2163"; // Laea esferica, funciona |
|
49 |
//strEpsgCode="EPSG:3035"; // ETRS-LAEA, funciona |
|
50 |
//strEpsgCode="EPSG:29100"; // Polyconic, falla en geotools |
|
51 |
//strEpsgCode="EPSG:2964"; // Albers-conic-equal-area |
|
52 |
// debería fallar por cambio de unidad |
|
53 |
//strEpsgCode="EPSG:24571"; // Oblicua de mercator, rf mas decimales |
|
54 |
// quitar segundo alpha |
|
55 |
//strEpsgCode="EPSG:29700"; // Oblicua de mercator, rf mas decimales |
|
56 |
//strEpsgCode="EPSG:21780"; //somer, sin alpha |
|
57 |
ICrs crs=null; |
|
58 |
//CoordinateReferenceSystem source; |
|
59 |
//source = CRS.decode(strEpsgCode); |
|
60 |
crs = new CrsFactory().getCRS(strEpsgCode); |
|
61 |
|
|
62 |
System.out.println(crs.getWKT()); |
|
63 |
System.out.println(crs.getProj4String()); //proj4.exportToProj4(crs)); |
|
64 |
|
|
65 |
|
|
66 |
} catch (CrsException e) { |
|
67 |
// TODO Auto-generated catch block |
|
68 |
e.printStackTrace(); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
} |
|
0 | 73 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/test/TestGeotools21.java | ||
---|---|---|
1 |
package es.idr.test; |
|
2 |
|
|
3 |
import org.geotools.referencing.CRS; |
|
4 |
import org.opengis.referencing.FactoryException; |
|
5 |
import org.opengis.referencing.NoSuchAuthorityCodeException; |
|
6 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
7 |
|
|
8 |
public class TestGeotools21 { |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* @param args |
|
13 |
*/ |
|
14 |
public static void main(String[] args) { |
|
15 |
try { |
|
16 |
String strEpsgCode="EPSG:27572"; |
|
17 |
CoordinateReferenceSystem source; |
|
18 |
source = CRS.decode(strEpsgCode); |
|
19 |
System.out.println(source.toWKT()); |
|
20 |
|
|
21 |
} catch (NoSuchAuthorityCodeException e) { |
|
22 |
// TODO Auto-generated catch block |
|
23 |
e.printStackTrace(); |
|
24 |
} catch (FactoryException e) { |
|
25 |
// TODO Auto-generated catch block |
|
26 |
e.printStackTrace(); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
} |
|
0 | 31 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/test/connection/TestConnection.java | ||
---|---|---|
1 |
package es.idr.test.connection; |
|
2 |
|
|
3 |
|
|
4 |
import java.sql.ResultSet; |
|
5 |
import java.sql.SQLException; |
|
6 |
|
|
7 |
import es.idr.teledeteccion.connection.EpsgConnection; |
|
8 |
import es.idr.teledeteccion.connection.Query; |
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
public class TestConnection { |
|
13 |
|
|
14 |
public TestConnection () { |
|
15 |
testEpsgDataBase(); |
|
16 |
testEsriDataBase(); |
|
17 |
testIau2000DataBase(); |
|
18 |
} |
|
19 |
/** |
|
20 |
* @param args |
|
21 |
*/ |
|
22 |
public static void main(String[] args) { |
|
23 |
// TODO Auto-generated method stub |
|
24 |
TestConnection tc = new TestConnection(); |
|
25 |
|
|
26 |
|
|
27 |
} |
|
28 |
|
|
29 |
private void testEpsgDataBase() { |
|
30 |
EpsgConnection connect = new EpsgConnection(); |
|
31 |
connect.setConnectionEPSG(); |
|
32 |
String sentence = "SELECT coord_ref_sys_name " + |
|
33 |
"FROM epsg_coordinatereferencesystem " + |
|
34 |
"WHERE coord_ref_sys_code = 23030"; |
|
35 |
|
|
36 |
ResultSet result; |
|
37 |
try { |
|
38 |
result = Query.select(sentence,connect.getConnection()); |
|
39 |
result.next(); |
|
40 |
System.out.println(result.getString("coord_ref_sys_name")); |
|
41 |
} catch (SQLException e) { |
|
42 |
// TODO Auto-generated catch block |
|
43 |
e.printStackTrace(); |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
private void testEsriDataBase (){ |
|
48 |
EpsgConnection connect = new EpsgConnection(); |
|
49 |
connect.setConnectionEsri(); |
|
50 |
String sentence = "SELECT esri_proj " + |
|
51 |
"FROM ESRI " + |
|
52 |
"WHERE esri_code = 23030"; |
|
53 |
|
|
54 |
ResultSet result = null; |
|
55 |
try { |
|
56 |
result = Query.select(sentence,connect.getConnection()); |
|
57 |
result.next(); |
|
58 |
System.out.println(result.getString("esri_proj")); |
|
59 |
} catch (SQLException e) { |
|
60 |
// TODO Auto-generated catch block |
|
61 |
e.printStackTrace(); |
|
62 |
} |
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
private void testIau2000DataBase() { |
|
67 |
EpsgConnection connect = new EpsgConnection(); |
|
68 |
connect.setConnectionIAU2000(); |
|
69 |
String sentence = "SELECT iau_geog " + |
|
70 |
"FROM IAU2000 " + |
|
71 |
"WHERE iau_code = 19900"; |
|
72 |
|
|
73 |
ResultSet result = null; |
|
74 |
try { |
|
75 |
result = Query.select(sentence,connect.getConnection()); |
|
76 |
result.next(); |
|
77 |
System.out.println(result.getString("iau_geog")); |
|
78 |
} catch (SQLException e) { |
|
79 |
// TODO Auto-generated catch block |
|
80 |
e.printStackTrace(); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
0 | 85 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/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/gt2-usr-hsql/src/org/geotools/referencing/factory/usr/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 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/test/ValidateEpsgCRSs.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.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 |
|
|
0 | 156 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/test/InsertUserDataCrs.java | ||
---|---|---|
1 |
package es.idr.test; |
|
2 |
|
|
3 |
import java.sql.SQLException; |
|
4 |
|
|
5 |
import es.idr.teledeteccion.connection.EpsgConnection; |
|
6 |
|
|
7 |
|
|
8 |
public class InsertUserDataCrs { |
|
9 |
|
|
10 |
/** |
|
11 |
* @param args |
|
12 |
*/ |
|
13 |
public static void main(String[] args) { |
|
14 |
// TODO Auto-generated method stub |
|
15 |
EpsgConnection conn = new EpsgConnection(); |
|
16 |
conn.setConnectionUsr(); |
|
17 |
|
|
18 |
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')"; |
|
19 |
|
|
20 |
try { |
|
21 |
conn.update(sentence); |
|
22 |
conn.shutdown(); |
|
23 |
} catch (SQLException e) { |
|
24 |
// TODO Auto-generated catch block |
|
25 |
e.printStackTrace(); |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
} |
|
0 | 30 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/test/TestWKTandProj4Epsg.java | ||
---|---|---|
1 |
package es.idr.test; |
|
2 |
|
|
3 |
import java.io.BufferedWriter; |
|
4 |
import java.io.FileWriter; |
|
5 |
import java.io.IOException; |
|
6 |
import java.sql.Connection; |
|
7 |
import java.sql.PreparedStatement; |
|
8 |
import java.sql.ResultSet; |
|
9 |
import java.sql.SQLException; |
|
10 |
import java.util.ArrayList; |
|
11 |
|
|
12 |
import javax.units.ConversionException; |
|
13 |
|
|
14 |
import org.geotools.referencing.factory.epsg.HSQLDataSource; |
|
15 |
import org.geotools.referencing.wkt.UnformattableObjectException; |
|
16 |
import org.gvsig.crs.Crs; |
|
17 |
import org.gvsig.crs.CrsException; |
|
18 |
import org.gvsig.crs.CrsFactory; |
|
19 |
import org.gvsig.crs.CrsGT; |
|
20 |
import org.gvsig.crs.ICrs; |
|
21 |
import org.gvsig.crs.Proj4; |
|
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 |
int indice = 0; |
|
33 |
int fallo = 0; |
|
34 |
final PreparedStatement stmt; |
|
35 |
stmt = conn.prepareStatement("SELECT COORD_REF_SYS_CODE, COORD_REF_SYS_NAME" |
|
36 |
+" FROM epsg_coordinatereferencesystem "); |
|
37 |
//+" WHERE COORD_REF_SYS_CODE>29372"); |
|
38 |
ResultSet result; |
|
39 |
|
|
40 |
result = stmt.executeQuery(); |
|
41 |
|
|
42 |
String filename = "salida.txt"; |
|
43 |
|
|
44 |
BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); |
|
45 |
|
|
46 |
while (result.next()) { |
|
47 |
ICrs crs = null; |
|
48 |
int cod = result.getInt("COORD_REF_SYS_CODE"); |
|
49 |
try { |
|
50 |
|
|
51 |
crs = new CrsFactory().getCRS("EPSG:"+cod); |
|
52 |
if (crs instanceof CrsGT) { |
|
53 |
// //continue; |
|
54 |
if (crs.getProj4String() == null){ |
|
55 |
bw.write("C?digo: "+cod+"\tNombre: "+result.getString("COORD_REF_SYS_NAME")+"\n"); |
|
56 |
bw.write("Cadena WKT: "+crs.getWKT()+"\n"); |
|
57 |
bw.write("Cadena Proj4: No cadena proj4 \n"); |
|
58 |
bw.write("Fallo: Fallo generando en cadena proj4 \n"); |
|
59 |
bw.write("\n\n"); |
|
60 |
} |
|
61 |
} |
|
62 |
else { |
|
63 |
if (crs != null) { |
|
64 |
bw.write("C?digo: "+cod+"\tNombre: "+result.getString("COORD_REF_SYS_NAME")+"\n"); |
|
65 |
bw.write("Cadena WKT: "+crs.getWKT()+"\n"); |
|
66 |
bw.write("Cadena Proj4: "+crs.getProj4String()+"\n"); |
|
67 |
bw.write("Fallo: Creado con crs antiguo \n"); |
|
68 |
bw.write("\n\n"); |
|
69 |
} |
|
70 |
else { |
|
71 |
bw.write("C?digo: "+cod+"\tNombre: "+result.getString("COORD_REF_SYS_NAME")+"\n"); |
|
72 |
bw.write("Fallo: Falla tanto geotools como crs antiguo \n"); |
|
73 |
bw.write("\n\n"); |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
} catch (CrsException e) { |
|
80 |
bw.write("C?digo: "+cod+"\tNombre: "+result.getString("COORD_REF_SYS_NAME")+"\n"); |
|
81 |
bw.write("Cadena WKT: No cadena wkt \n"); |
|
82 |
bw.write("Cadena Proj4: No cadena proj4\n"); |
|
83 |
bw.write("Fallo: "+e+" \n"); |
|
84 |
bw.write("\n\n"); |
|
85 |
} catch (NumberFormatException e) { |
|
86 |
bw.write("C?digo: "+cod+"\tNombre: "+result.getString("COORD_REF_SYS_NAME")+"\n"); |
|
87 |
bw.write("Cadena WKT: No cadena wkt \n"); |
|
88 |
bw.write("Cadena Proj4: No cadena proj4\n"); |
|
89 |
bw.write("Fallo: "+e+" \n"); |
|
90 |
bw.write("\n\n"); |
|
91 |
} catch (ConversionException e) { |
|
92 |
bw.write("C?digo: "+cod+"\tNombre: "+result.getString("COORD_REF_SYS_NAME")+"\n"); |
|
93 |
bw.write("Cadena WKT: No cadena wkt \n"); |
|
94 |
bw.write("Cadena Proj4: No cadena proj4\n"); |
|
95 |
bw.write("Fallo: "+e+" \n"); |
|
96 |
bw.write("\n\n"); |
|
97 |
}catch (UnformattableObjectException e) { |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
bw.flush(); |
|
102 |
bw.close(); |
|
103 |
|
|
104 |
} catch (SQLException e1) { |
|
105 |
// TODO Auto-generated catch block |
|
106 |
e1.printStackTrace(); |
|
107 |
} catch (IOException e) { |
|
108 |
// TODO Auto-generated catch block |
|
109 |
e.printStackTrace(); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
0 | 113 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/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.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 |
} |
|
0 | 122 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/crs/crsGT/ProvidersTest.java | ||
---|---|---|
1 |
package es.idr.crs.crsGT; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.Iterator; |
|
5 |
|
|
6 |
import org.geotools.factory.FactoryRegistry; |
|
7 |
import org.geotools.referencing.operation.MathTransformProvider; |
|
8 |
|
|
9 |
public class ProvidersTest { |
|
10 |
|
|
11 |
|
|
12 |
public static void main(String[] args) { |
|
13 |
final Class[] categories = {org.geotools.referencing.operation.MathTransformProvider.class}; |
|
14 |
FactoryRegistry registry = new FactoryRegistry(Arrays.asList(categories)); |
|
15 |
Iterator providers = registry.getServiceProviders(MathTransformProvider.class); |
|
16 |
Iterator providers2 = null; |
|
17 |
MathTransformProvider provider = null; |
|
18 |
MathTransformProvider provider2 = null; |
|
19 |
while (providers.hasNext()){ |
|
20 |
provider = (MathTransformProvider) providers.next(); |
|
21 |
if(provider.nameMatches("IDR")){ |
|
22 |
providers2 = registry.getServiceProviders(MathTransformProvider.class); |
|
23 |
while (providers2.hasNext()){ |
|
24 |
provider2 = (MathTransformProvider) providers2.next(); |
|
25 |
if(provider2.nameMatches(provider.getName().toString()) && !provider2.nameMatches("IDR")) |
|
26 |
registry.deregisterServiceProvider(provider2, categories[0]); |
|
27 |
} |
|
28 |
} |
|
29 |
} |
|
30 |
providers = registry.getServiceProviders(MathTransformProvider.class); |
|
31 |
while (providers.hasNext()) { |
|
32 |
provider = (MathTransformProvider) providers.next(); |
|
33 |
if (provider.nameMatches("IDR")) |
|
34 |
System.out.println("-IDR-"+provider.toString()); |
|
35 |
else |
|
36 |
System.out.println(provider.toString()); |
|
37 |
} |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
0 | 41 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/es/idr/crs/crsGT/CrsGTTest.java | ||
---|---|---|
1 |
package es.idr.crs.crsGT; |
|
2 |
|
|
3 |
import org.cresques.cts.IProjection; |
|
4 |
import org.gvsig.crs.CrsException; |
|
5 |
import org.gvsig.crs.CrsGT; |
|
6 |
import org.gvsig.crs.ICrs; |
|
7 |
import org.gvsig.crs.Proj4; |
|
8 |
import org.gvsig.crs.repository.EpsgRepositoryGT; |
|
9 |
import org.gvsig.crs.repository.EsriRepositoryGT; |
|
10 |
import org.gvsig.crs.repository.Iau2000RepositoryGT; |
|
11 |
import org.gvsig.crs.repository.UsrRepositoryGT; |
|
12 |
|
|
13 |
public class CrsGTTest { |
|
14 |
|
|
15 |
public CrsGTTest() { |
|
16 |
epsgTest(); |
|
17 |
esriTest(); |
|
18 |
iau2000Test(); |
|
19 |
usrTest(); |
|
20 |
} |
|
21 |
/** |
|
22 |
* @param args |
|
23 |
*/ |
|
24 |
public static void main(String[] args) { |
|
25 |
CrsGTTest g = new CrsGTTest(); |
|
26 |
} |
|
27 |
|
|
28 |
public void epsgTest() { |
|
29 |
EpsgRepositoryGT repo = new EpsgRepositoryGT(); |
|
30 |
IProjection crs=null; |
|
31 |
crs = repo.getCrs("23030"); |
|
32 |
if (crs!=null){ |
|
33 |
System.out.println(crs.getAbrev()); |
|
34 |
System.out.println(((ICrs)crs).getCode()); |
|
35 |
System.out.println(((ICrs)crs).getWKT()); |
|
36 |
System.out.println(((ICrs)crs).getDatum().getEIFlattening()); |
|
37 |
System.out.println(((ICrs)crs).getDatum().getESemiMajorAxis()); |
|
38 |
System.out.println(((ICrs)crs).isProjected()+"\n\n"); |
|
39 |
|
|
40 |
System.out.println("----------- CrsWkt:--------------"); |
|
41 |
System.out.println(((ICrs)crs).getCrsWkt().getAuthority()[0]+":"+((ICrs)crs).getCrsWkt().getAuthority()[1]); |
|
42 |
System.out.println(((ICrs)crs).getCrsWkt().getName()); |
|
43 |
System.out.println(((ICrs)crs).getCrsWkt().getDatumName()); |
|
44 |
System.out.println(((ICrs)crs).getCrsWkt().getGeogcs()); |
|
45 |
System.out.println(((ICrs)crs).getCrsWkt().getProjcs()); |
|
46 |
System.out.println(((ICrs)crs).getCrsWkt().getProjection()); |
|
47 |
System.out.println(((ICrs)crs).getCrsWkt().getPrimen()[0]+" -- "+ ((ICrs)crs).getCrsWkt().getPrimen()[1]+"\n\n"); |
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
try { |
|
52 |
Proj4 proj4 = new Proj4(); |
|
53 |
System.out.println(proj4.exportToProj4(((CrsGT)crs).getCrsGT())); |
|
54 |
} catch (CrsException e) { |
|
55 |
// TODO Auto-generated catch block |
|
56 |
e.printStackTrace(); |
|
57 |
} |
|
58 |
|
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
public void esriTest() { |
|
63 |
EsriRepositoryGT repo = new EsriRepositoryGT(); |
|
64 |
IProjection crs=null; |
|
65 |
crs = repo.getCrs("23030"); |
|
66 |
if (crs!=null){ |
|
67 |
System.out.println(crs.getAbrev()); |
|
68 |
System.out.println(((ICrs)crs).getCode()); |
|
69 |
System.out.println(((ICrs)crs).getWKT()); |
|
70 |
System.out.println(((ICrs)crs).getDatum().getEIFlattening()); |
|
71 |
System.out.println(((ICrs)crs).getDatum().getESemiMajorAxis()); |
|
72 |
System.out.println(((ICrs)crs).isProjected()+"\n\n"); |
|
73 |
|
|
74 |
System.out.println("----------- CrsWkt:--------------"); |
|
75 |
System.out.println(((ICrs)crs).getCrsWkt().getAuthority()[0]+":"+((ICrs)crs).getCrsWkt().getAuthority()[1]); |
|
76 |
System.out.println(((ICrs)crs).getCrsWkt().getName()); |
|
77 |
System.out.println(((ICrs)crs).getCrsWkt().getDatumName()); |
|
78 |
System.out.println(((ICrs)crs).getCrsWkt().getGeogcs()); |
|
79 |
System.out.println(((ICrs)crs).getCrsWkt().getProjcs()); |
|
80 |
System.out.println(((ICrs)crs).getCrsWkt().getProjection()); |
|
81 |
System.out.println(((ICrs)crs).getCrsWkt().getPrimen()[0]+" -- "+ ((ICrs)crs).getCrsWkt().getPrimen()[1]+"\n\n"); |
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
try { |
|
86 |
Proj4 proj4 = new Proj4(); |
|
87 |
System.out.println(proj4.exportToProj4(((CrsGT)crs).getCrsGT())); |
|
88 |
} catch (CrsException e) { |
|
89 |
// TODO Auto-generated catch block |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
|
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public void iau2000Test() { |
|
97 |
Iau2000RepositoryGT repo = new Iau2000RepositoryGT(); |
|
98 |
IProjection crs=null; |
|
99 |
crs = repo.getCrs("19900"); |
|
100 |
if (crs!=null){ |
|
101 |
System.out.println(crs.getAbrev()); |
|
102 |
System.out.println(((ICrs)crs).getCode()); |
|
103 |
System.out.println(((ICrs)crs).getWKT()); |
|
104 |
System.out.println(((ICrs)crs).getDatum().getEIFlattening()); |
|
105 |
System.out.println(((ICrs)crs).getDatum().getESemiMajorAxis()); |
|
106 |
System.out.println(((ICrs)crs).isProjected()+"\n\n"); |
|
107 |
|
|
108 |
System.out.println("----------- CrsWkt:--------------"); |
|
109 |
System.out.println(((ICrs)crs).getCrsWkt().getAuthority()[0]+":"+((ICrs)crs).getCrsWkt().getAuthority()[1]); |
|
110 |
System.out.println(((ICrs)crs).getCrsWkt().getName()); |
|
111 |
System.out.println(((ICrs)crs).getCrsWkt().getDatumName()); |
|
112 |
System.out.println(((ICrs)crs).getCrsWkt().getGeogcs()); |
|
113 |
System.out.println(((ICrs)crs).getCrsWkt().getProjcs()); |
|
114 |
System.out.println(((ICrs)crs).getCrsWkt().getProjection()); |
|
115 |
System.out.println(((ICrs)crs).getCrsWkt().getPrimen()[0]+" -- "+ ((ICrs)crs).getCrsWkt().getPrimen()[1]+"\n\n"); |
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
try { |
|
120 |
Proj4 proj4 = new Proj4(); |
|
121 |
System.out.println(proj4.exportToProj4(((CrsGT)crs).getCrsGT())); |
|
122 |
} catch (CrsException e) { |
|
123 |
// TODO Auto-generated catch block |
|
124 |
e.printStackTrace(); |
|
125 |
} |
|
126 |
|
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
public void usrTest() { |
|
131 |
UsrRepositoryGT repo = new UsrRepositoryGT(); |
|
132 |
IProjection crs=null; |
|
133 |
crs = repo.getCrs("2000"); |
|
134 |
if (crs!=null){ |
|
135 |
System.out.println(crs.getAbrev()); |
|
136 |
System.out.println(((ICrs)crs).getCode()); |
|
137 |
System.out.println(((ICrs)crs).getWKT()); |
|
138 |
System.out.println(((ICrs)crs).getDatum().getEIFlattening()); |
|
139 |
System.out.println(((ICrs)crs).getDatum().getESemiMajorAxis()); |
|
140 |
System.out.println(((ICrs)crs).isProjected()+"\n\n"); |
|
141 |
|
|
142 |
System.out.println("----------- CrsWkt:--------------"); |
|
143 |
System.out.println(((ICrs)crs).getCrsWkt().getAuthority()[0]+":"+((ICrs)crs).getCrsWkt().getAuthority()[1]); |
|
144 |
System.out.println(((ICrs)crs).getCrsWkt().getName()); |
|
145 |
System.out.println(((ICrs)crs).getCrsWkt().getDatumName()); |
|
146 |
System.out.println(((ICrs)crs).getCrsWkt().getGeogcs()); |
|
147 |
System.out.println(((ICrs)crs).getCrsWkt().getProjcs()); |
|
148 |
System.out.println(((ICrs)crs).getCrsWkt().getProjection()); |
|
149 |
System.out.println(((ICrs)crs).getCrsWkt().getPrimen()[0]+" -- "+ ((ICrs)crs).getCrsWkt().getPrimen()[1]+"\n\n"); |
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
try { |
|
154 |
Proj4 proj4 = new Proj4(); |
|
155 |
System.out.println(proj4.exportToProj4(((CrsGT)crs).getCrsGT())); |
|
156 |
} catch (CrsException e) { |
|
157 |
// TODO Auto-generated catch block |
|
158 |
e.printStackTrace(); |
|
159 |
} |
|
160 |
|
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
} |
|
0 | 165 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/org/gvsig/crs/repository/RepositoryTest.java | ||
---|---|---|
1 |
package org.gvsig.crs.repository; |
|
2 |
|
|
3 |
import org.gvsig.crs.Crs; |
|
4 |
|
|
5 |
|
|
6 |
public class RepositoryTest { |
|
7 |
public static void main(String[] args){ |
|
8 |
EpsgRepository epsgRep= new EpsgRepository(); |
|
9 |
Crs crs = (Crs)epsgRep.getCrs("23030"); |
|
10 |
if (crs != null){ |
|
11 |
String abrev = crs.getAbrev(); |
|
12 |
System.out.println(abrev); |
|
13 |
} |
|
14 |
else |
|
15 |
System.out.println("el c?digo no existe en el repositorio."); |
|
16 |
} |
|
17 |
} |
|
0 | 18 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/test/org/gvsig/crs/jscrollpanel/ScrollPanelTest.java | ||
---|---|---|
1 |
package org.gvsig.crs.jscrollpanel; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
|
|
5 |
import javax.swing.BorderFactory; |
|
6 |
import javax.swing.JFrame; |
|
7 |
import javax.swing.JScrollPane; |
|
8 |
import javax.swing.JTable; |
|
9 |
import javax.swing.table.DefaultTableModel; |
|
10 |
import javax.swing.table.TableColumn; |
|
11 |
|
|
12 |
public class ScrollPanelTest { |
|
13 |
|
|
14 |
JTable jTable = null; |
|
15 |
JScrollPane jScrollPane = null; |
|
16 |
|
|
17 |
public ScrollPanelTest() { |
|
18 |
super(); |
|
19 |
JFrame jFrame = new JFrame(); |
|
20 |
jFrame.getContentPane().add(getJScrollPane()); |
|
21 |
jFrame.setSize(500, 150); |
|
22 |
jFrame.setVisible(true); |
|
23 |
// TODO Auto-generated constructor stub |
|
24 |
} |
|
25 |
|
|
26 |
public JTable getJTable() { |
|
27 |
if (jTable == null) { |
|
28 |
String[] columnNames= {"UNA COLUMNA", "DOS COLUMNAS"}; |
|
29 |
Object[][]data = {}; |
|
30 |
DefaultTableModel dtm = new DefaultTableModel(data, columnNames); |
|
31 |
jTable = new JTable(dtm); |
|
32 |
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
33 |
TableColumn column = null; |
|
34 |
for (int i = 0; i < 2; i++) { |
|
35 |
column = jTable.getColumnModel().getColumn(i); |
|
36 |
if (i == 0) { |
|
37 |
column.setPreferredWidth(600); |
|
38 |
} |
|
39 |
} |
|
40 |
//jTable.setPreferredSize(new Dimension(800, 100)); |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
return jTable; |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
private JScrollPane getJScrollPane() { |
|
50 |
if (jScrollPane == null) { |
|
51 |
jScrollPane = new JScrollPane(getJTable(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
|
52 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
|
53 |
jScrollPane.setBorder( |
|
54 |
BorderFactory.createCompoundBorder( |
|
55 |
BorderFactory.createCompoundBorder( |
|
56 |
BorderFactory.createTitledBorder("TABLA GEN?RICA DE 2 CAMPOS"), |
|
57 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
|
58 |
jScrollPane.getBorder())); |
|
59 |
jScrollPane.setViewportView(getJTable()); |
|
60 |
} |
|
61 |
return jScrollPane; |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
public static void main(String[] args){ |
|
66 |
ScrollPanelTest al = new ScrollPanelTest(); |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
} |
|
0 | 72 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/main/java/es/idr/teledeteccion/connection/usr/FactoryUsingHSQL.java | ||
---|---|---|
1 |
/* |
|
2 |
* GeoTools - OpenSource mapping toolkit |
|
3 |
* http://geotools.org |
|
4 |
* (C) 2005-2006, GeoTools Project Managment Committee (PMC) |
|
5 |
* |
|
6 |
* This library is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU Lesser General Public |
|
8 |
* License as published by the Free Software Foundation; |
|
9 |
* version 2.1 of the License. |
|
10 |
* |
|
11 |
* This library is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
* Lesser General Public License for more details. |
|
15 |
*/ |
|
16 |
package es.idr.teledeteccion.connection.usr; |
|
17 |
|
|
18 |
// J2SE dependencies |
|
19 |
|
|
20 |
import java.io.IOException; |
|
21 |
import java.sql.Connection; |
|
22 |
import java.sql.PreparedStatement; |
|
23 |
import java.sql.ResultSet; |
|
24 |
import java.sql.SQLException; |
|
25 |
import java.sql.Statement; |
|
26 |
import java.text.ParseException; |
|
27 |
import java.util.Hashtable; |
|
28 |
import java.util.Set; |
|
29 |
|
|
30 |
import org.geotools.metadata.iso.citation.CitationImpl; |
|
31 |
import org.geotools.referencing.wkt.Parser; |
|
32 |
import org.gvsig.crs.CrsFactory; |
|
33 |
import org.hsqldb.jdbc.jdbcDataSource; |
|
34 |
import org.opengis.metadata.citation.Citation; |
|
35 |
import org.opengis.referencing.FactoryException; |
|
36 |
import org.opengis.referencing.IdentifiedObject; |
|
37 |
import org.opengis.referencing.crs.CRSAuthorityFactory; |
|
38 |
import org.opengis.referencing.crs.CRSFactory; |
|
39 |
import org.opengis.referencing.crs.CompoundCRS; |
|
40 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
41 |
import org.opengis.referencing.crs.DerivedCRS; |
|
42 |
import org.opengis.referencing.crs.EngineeringCRS; |
|
43 |
import org.opengis.referencing.crs.GeocentricCRS; |
|
44 |
import org.opengis.referencing.crs.GeographicCRS; |
|
45 |
import org.opengis.referencing.crs.ImageCRS; |
|
46 |
import org.opengis.referencing.crs.ProjectedCRS; |
|
47 |
import org.opengis.referencing.crs.TemporalCRS; |
|
48 |
import org.opengis.referencing.crs.VerticalCRS; |
|
49 |
import org.opengis.util.InternationalString; |
|
50 |
|
|
51 |
|
|
52 |
public class FactoryUsingHSQL extends jdbcDataSource implements CRSAuthorityFactory { |
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* The connection to the EPSG database. |
|
58 |
*/ |
|
59 |
protected Connection connection; |
|
60 |
|
|
61 |
// object factory |
|
62 |
protected CRSFactory crsFactory; |
|
63 |
|
|
64 |
/** Cache of parsed CoordinateReferenceSystem WKT by ESRI_NUMBER */ |
|
65 |
private Hashtable cache = new Hashtable(); |
|
66 |
|
|
67 |
/** |
|
68 |
* The database name. |
|
69 |
* |
|
70 |
* @since 2.3 |
|
71 |
*/ |
|
72 |
public static final String DATABASE_NAME = "USR"; |
|
73 |
|
|
74 |
public FactoryUsingHSQL() { |
|
75 |
try { |
|
76 |
loadDefault(); |
|
77 |
} |
|
78 |
catch( IOException oops ){ |
|
79 |
System.err.println("Could not load "+ oops ); |
|
80 |
} |
|
81 |
//this(FactoryFinder.getCRSFactory(null)); |
|
82 |
} |
|
83 |
|
|
84 |
protected FactoryUsingHSQL(CRSFactory factory) { |
|
85 |
this.crsFactory = factory; |
|
86 |
try { |
|
87 |
loadDefault(); |
|
88 |
} |
|
89 |
catch( IOException oops ){ |
|
90 |
System.err.println("Could not load "+ oops ); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
protected void loadDefault() throws IOException { |
|
95 |
String db = "jdbc:hsqldb:file:" + CrsFactory.getDataBaseFolder().getAbsolutePath() + "/usr"; |
|
96 |
setDatabase(db); |
|
97 |
setUser("sa"); |
|
98 |
try { |
|
99 |
connection = super.getConnection(); |
|
100 |
} catch (SQLException e) { |
|
101 |
// TODO Auto-generated catch block |
|
102 |
e.printStackTrace(); |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws FactoryException { |
|
108 |
// TODO Auto-generated method stub |
|
109 |
CoordinateReferenceSystem returnValue = null; |
|
110 |
String wkt = null; |
|
111 |
String USR_NUMBER = code.substring(code.indexOf(":")+1, code.length()); |
|
112 |
int cod = Integer.parseInt(USR_NUMBER); |
|
113 |
|
|
114 |
if( cache.contains( USR_NUMBER ) ){ |
|
115 |
Object value = cache.get( USR_NUMBER ); |
|
116 |
if( value instanceof Throwable ){ |
|
117 |
throw new FactoryException( "WKT for "+code+" could not be parsed", (Throwable) value ); |
|
118 |
} |
|
119 |
if( value instanceof CoordinateReferenceSystem){ |
|
120 |
return (CoordinateReferenceSystem) value; |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
try { |
|
125 |
final PreparedStatement stmt; |
|
126 |
|
|
127 |
String sentence = "SELECT USR_WKT" |
|
128 |
+ " FROM USR" |
|
129 |
+ " WHERE USR_CODE = " + code.substring(code.indexOf(":")+1, code.length()); |
|
130 |
|
|
131 |
Statement st = null; |
|
132 |
ResultSet result = null; |
|
133 |
loadDefault(); |
|
134 |
st = connection.createStatement(); |
|
135 |
result = st.executeQuery(sentence); |
|
136 |
st.close(); |
|
137 |
connection.close(); |
|
138 |
while (result.next()) { |
|
139 |
wkt = result.getString("usr_wkt"); |
|
140 |
} |
|
141 |
result.close(); |
|
142 |
if( wkt.indexOf( cod ) == -1){ |
|
143 |
wkt = wkt.trim(); |
|
144 |
wkt = wkt.substring(0, wkt.length()-1 ); |
|
145 |
wkt += ",AUTHORITY[\"USR\",\""+cod+"\"]]"; |
|
146 |
} |
|
147 |
} catch (SQLException exception) { |
|
148 |
System.out.println(exception); |
|
149 |
} catch (IOException e) { |
|
150 |
// TODO Auto-generated catch block |
|
151 |
e.printStackTrace(); |
|
152 |
} |
|
153 |
Parser parser = new Parser(); |
|
154 |
|
|
155 |
try { |
|
156 |
returnValue = parser.parseCoordinateReferenceSystem(wkt); |
|
157 |
} catch (ParseException e) { |
|
158 |
// TODO Auto-generated catch block |
|
159 |
System.out.println("Cadena WKT no ha podido ser parseada"); |
|
160 |
e.printStackTrace(); |
|
161 |
} |
|
162 |
|
|
163 |
return returnValue; |
|
164 |
} |
|
165 |
|
|
166 |
public CompoundCRS createCompoundCRS(String arg0) throws FactoryException { |
|
167 |
// TODO Auto-generated method stub |
|
168 |
return null; |
|
169 |
} |
|
170 |
|
|
171 |
public DerivedCRS createDerivedCRS(String arg0) throws FactoryException { |
|
172 |
// TODO Auto-generated method stub |
|
173 |
return null; |
|
174 |
} |
|
175 |
|
|
176 |
public EngineeringCRS createEngineeringCRS(String arg0) throws FactoryException { |
|
177 |
// TODO Auto-generated method stub |
|
178 |
return null; |
|
179 |
} |
|
180 |
|
|
181 |
public GeographicCRS createGeographicCRS(String arg0) throws FactoryException { |
|
182 |
// TODO Auto-generated method stub |
|
183 |
return null; |
|
184 |
} |
|
185 |
|
|
186 |
public GeocentricCRS createGeocentricCRS(String arg0) throws FactoryException { |
|
187 |
// TODO Auto-generated method stub |
|
188 |
return null; |
|
189 |
} |
|
190 |
|
|
191 |
public ImageCRS createImageCRS(String arg0) throws FactoryException { |
|
192 |
// TODO Auto-generated method stub |
|
193 |
return null; |
|
194 |
} |
|
195 |
|
|
196 |
public ProjectedCRS createProjectedCRS(String arg0) throws FactoryException { |
|
197 |
// TODO Auto-generated method stub |
|
198 |
return null; |
|
199 |
} |
|
200 |
|
|
201 |
public TemporalCRS createTemporalCRS(String arg0) throws FactoryException { |
|
202 |
// TODO Auto-generated method stub |
|
203 |
return null; |
|
204 |
} |
|
205 |
|
|
206 |
public VerticalCRS createVerticalCRS(String arg0) throws FactoryException { |
|
207 |
// TODO Auto-generated method stub |
|
208 |
return null; |
|
209 |
} |
|
210 |
|
|
211 |
public Citation getAuthority() { |
|
212 |
Citation citation = CitationImpl.createCitation("USR"); |
|
213 |
citation.getIdentifiers().add("USR"); |
|
214 |
return citation; |
|
215 |
} |
|
216 |
|
|
217 |
public Set getAuthorityCodes(Class arg0) throws FactoryException { |
|
218 |
// TODO Auto-generated method stub |
|
219 |
return null; |
|
220 |
} |
|
221 |
|
|
222 |
public InternationalString getDescriptionText(String arg0) throws FactoryException { |
|
223 |
// TODO Auto-generated method stub |
|
224 |
return null; |
|
225 |
} |
|
226 |
|
|
227 |
public IdentifiedObject createObject(String code) throws FactoryException { |
|
228 |
// TODO Auto-generated method stub |
|
229 |
return createCoordinateReferenceSystem(code); |
|
230 |
} |
|
231 |
|
|
232 |
public Citation getVendor() { |
|
233 |
// TODO Auto-generated method stub |
|
234 |
return null; |
|
235 |
} |
|
236 |
} |
|
0 | 237 |
org.gvsig.projection.jcrs/tags/org.gvsig.projection.jcrs-2.1.266/org.gvsig.projection.jcrs.lib/src/main/java/es/idr/teledeteccion/connection/EpsgConnection.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
*/ |
|
20 |
package es.idr.teledeteccion.connection; |
|
21 |
|
|
22 |
import java.sql.Connection; |
|
23 |
import java.sql.SQLException; |
|
24 |
import java.sql.Statement; |
|
25 |
|
|
26 |
import org.gvsig.crs.CrsFactory; |
|
27 |
import org.hsqldb.jdbc.jdbcDataSource; |
|
28 |
import org.slf4j.Logger; |
|
29 |
import org.slf4j.LoggerFactory; |
|
30 |
|
|
31 |
import es.idr.teledeteccion.connection.epsg.HSQLDataSource; |
|
32 |
|
|
33 |
/** |
|
34 |
* Clase para la conexi?n con la base de datos de hsqldb. |
|
35 |
* Establece el driver necesario, as? como la cadena de |
|
36 |
* conexi?n a la base de datos de la EPSG y la IAU2000 |
|
37 |
* |
|
38 |
* @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com) |
|
39 |
* |
|
40 |
*/ |
|
41 |
public class EpsgConnection extends jdbcDataSource { |
|
42 |
|
|
43 |
private static final Logger logger = LoggerFactory.getLogger(EpsgConnection.class); |
|
44 |
|
|
45 |
Connection connect = null; |
|
46 |
String connectionType = null; |
|
47 |
|
|
48 |
public EpsgConnection() { |
|
49 |
/* try { |
|
50 |
Class.forName("org.hsqldb.jdbcDriver"); |
|
51 |
} catch (ClassNotFoundException e) { |
|
52 |
logger.error("Can't create EpsgConnection",e); |
|
53 |
}*/ |
|
54 |
} |
|
55 |
|
|
56 |
private void setConnection(Connection connection, String type) { |
|
57 |
this.connect = connection; |
|
58 |
this.connectionType = type; |
|
59 |
logger.debug("Created connection to '"+connectionType+"'."); |
|
60 |
} |
|
61 |
|
|
62 |
public void setConnectionEPSG() { |
|
63 |
HSQLDataSource ds = new HSQLDataSource(); |
|
64 |
|
|
65 |
try { |
|
66 |
setConnection(ds.getConnection(), "EPSG"); |
|
67 |
} catch (SQLException e) { |
|
68 |
logger.warn("Cant get conection from HSQLDataSource.", e); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Establece la conexi?n con la base de datos de la IAU2000 |
|
74 |
* |
|
75 |
*/ |
|
76 |
public void setConnectionIAU2000() { |
|
77 |
String db = "jdbc:hsqldb:file:" + CrsFactory.getDataBaseFolder().getAbsolutePath() + "/iau2000"; |
|
78 |
setDatabase(db); |
|
79 |
setUser("sa"); |
|
80 |
try { |
|
81 |
setConnection(super.getConnection(),"IAU2000"); |
|
82 |
} catch (SQLException e) { |
|
83 |
logger.warn("Can't get conection from database '" + db + "'.", e); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Establece la conexi?n con la base de datos de ESRI |
|
89 |
* |
|
90 |
*/ |
|
91 |
public void setConnectionEsri() { |
|
92 |
String db = "jdbc:hsqldb:file:" + CrsFactory.getDataBaseFolder().getAbsolutePath() + "/esri"; |
|
93 |
setDatabase(db); |
|
94 |
setUser("sa"); |
|
95 |
try { |
|
96 |
setConnection(super.getConnection(),"Esri"); |
|
97 |
} catch (SQLException e) { |
|
98 |
logger.warn("Can't get conection from database '" + db + "'.", e); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Sets connection for CRS:* coordinate reference systems |
|
104 |
* such as CRS:84 |
|
105 |
* |
|
106 |
*/ |
|
107 |
public void setConnectionNoAuth() { |
|
108 |
String db = "jdbc:hsqldb:file:" + CrsFactory.getDataBaseFolder().getAbsolutePath() + "/noauth"; |
|
109 |
setDatabase(db); |
|
110 |
setUser("sa"); |
|
111 |
try { |
|
112 |
setConnection(super.getConnection(),"NoAuth"); |
|
113 |
} catch (SQLException e) { |
|
114 |
logger.warn("Can't get conection from database '" + db + "'.", e); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Establece la conexi?n con la base de datos de USR |
|
120 |
* |
|
121 |
*/ |
|
122 |
public void setConnectionUsr() { |
|
123 |
String db = "jdbc:hsqldb:file:" + CrsFactory.getDataBaseFolder().getAbsolutePath() + "/usr"; |
|
124 |
setDatabase(db); |
|
125 |
setUser("sa"); |
|
126 |
try { |
|
127 |
setConnection(super.getConnection(),"Usr"); |
|
128 |
} catch (SQLException e) { |
|
129 |
logger.warn("Can't get conection from database '" + db + "'.", e); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
public Connection getConnection() { |
|
134 |
return connect; |
|
135 |
} |
|
136 |
|
|
137 |
public void close() throws SQLException { |
|
138 |
|
|
139 |
try { |
|
140 |
connect.close(); // if there are no other open connection |
|
141 |
logger.debug("Shutdown connection to '" + connectionType + "' database."); |
|
142 |
} catch (Exception ex) { |
|
143 |
logger.warn("Can't shutdown the conexion.",ex); |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
public void shutdown() throws SQLException { |
|
148 |
|
|
149 |
// db writes out to files and performs clean shuts down |
|
150 |
// otherwise there will be an unclean shutdown |
|
151 |
// when program ends |
|
152 |
try { |
|
153 |
Statement st = connect.createStatement(); |
|
154 |
st.execute("SHUTDOWN"); |
|
155 |
connect.close(); // if there are no other open connection |
|
156 |
logger.debug("Shutdown connection to '" + connectionType + "' database."); |
|
157 |
} catch (Exception ex) { |
|
158 |
logger.warn("Can't shutdown the conexion.",ex); |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
public synchronized void update(String expression) throws SQLException { |
|
163 |
|
|
164 |
Statement st = null; |
|
165 |
st = connect.createStatement(); |
|
166 |
int i = st.executeUpdate(expression); |
|
167 |
if ( i == -1 ) { |
Also available in: Unified diff