root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.jcrs.lib / src / main / java / org / gvsig / crs / repository / Iau2000Repository.java @ 229
History | View | Annotate | Download (3.62 KB)
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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.crs.repository; |
42 |
|
43 |
import java.sql.ResultSet; |
44 |
import java.sql.SQLException; |
45 |
|
46 |
import es.idr.teledeteccion.connection.EpsgConnection; |
47 |
import es.idr.teledeteccion.connection.Query; |
48 |
|
49 |
import org.slf4j.Logger; |
50 |
import org.slf4j.LoggerFactory; |
51 |
|
52 |
import org.gvsig.crs.Crs; |
53 |
import org.gvsig.crs.CrsException; |
54 |
import org.gvsig.crs.ICrs; |
55 |
import org.gvsig.crs.ogr.Iau2wkt; |
56 |
import org.gvsig.tools.dispose.Disposable; |
57 |
|
58 |
/**
|
59 |
* Repositorio de CRSs de IAU2000
|
60 |
*
|
61 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
62 |
*
|
63 |
*/
|
64 |
public class Iau2000Repository implements ICrsRepository, Disposable { |
65 |
private static final Logger LOG = |
66 |
LoggerFactory.getLogger(Iau2000Repository.class); |
67 |
|
68 |
EpsgConnection connection = null;
|
69 |
|
70 |
public Iau2000Repository() {
|
71 |
connection = new EpsgConnection();
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Obtiene un CRS a partir de su c?digo IAU2000.
|
76 |
*
|
77 |
* @param code Codigo IAU2000 del CRS.
|
78 |
* @return ICrs
|
79 |
*/
|
80 |
public ICrs getCrs(String code) { |
81 |
String cadWKT = ""; |
82 |
Crs crs = null;
|
83 |
|
84 |
String sentence = "SELECT iau_code, iau_wkt, iau_proj, iau_geog, iau_datum " + |
85 |
"FROM IAU2000 " +
|
86 |
"WHERE iau_code = " + code;
|
87 |
|
88 |
connection.setConnectionIAU2000(); |
89 |
ResultSet result = Query.select(sentence,connection.getConnection()); |
90 |
try {
|
91 |
connection.shutdown(); |
92 |
} catch (SQLException e) { |
93 |
LOG.info("Error while shutting down the connection", e);
|
94 |
} |
95 |
try {
|
96 |
if (!result.next())
|
97 |
return null; |
98 |
cadWKT = result.getString("iau_wkt");
|
99 |
} catch (SQLException e1) { |
100 |
LOG.info("Error executing the SQL", e1);
|
101 |
return null; |
102 |
} |
103 |
cadWKT = cadWKT.substring(0, cadWKT.length()-1) + ", AUTHORITY[\"IAU2000\","+ Integer.parseInt(code)+"]]"; |
104 |
if (cadWKT.charAt(0) == 'P'){ |
105 |
Iau2wkt wk = new Iau2wkt(cadWKT);
|
106 |
cadWKT = wk.getWkt(); |
107 |
} |
108 |
|
109 |
try {
|
110 |
crs = new Crs(Integer.parseInt(code),cadWKT); |
111 |
} catch (CrsException e) {
|
112 |
LOG.info("Impossible to parse the CRS", e);
|
113 |
} |
114 |
|
115 |
return crs;
|
116 |
} |
117 |
|
118 |
public void dispose() { |
119 |
try {
|
120 |
this.connection.shutdown();
|
121 |
this.connection = null; |
122 |
} catch (SQLException ex) { |
123 |
LOG.warn("Con't shutdown the connection.",ex);
|
124 |
} |
125 |
} |
126 |
} |