root / org.gvsig.jcrs / trunk / libJCRS / src / org / gvsig / crs / repository / EpsgRepository.java @ 76
History | View | Annotate | Download (4.12 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.CrsEPSG; |
56 |
import org.gvsig.crs.ogr.Epsg2wkt; |
57 |
/**
|
58 |
* Repositorio de CRSs de EPSG
|
59 |
*
|
60 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
61 |
*
|
62 |
*/
|
63 |
public class EpsgRepository implements ICrsRepository { |
64 |
private static final Logger LOG = |
65 |
LoggerFactory.getLogger(EpsgRepository.class); |
66 |
|
67 |
public EpsgConnection connection = null; |
68 |
|
69 |
public EpsgRepository() {
|
70 |
connection = new EpsgConnection();
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Obtiene un CRS a partir de su c?digo EPSG.
|
75 |
*
|
76 |
* @param code Codigo EPSG del CRS.
|
77 |
* @return ICrs
|
78 |
*/
|
79 |
public ICrs getCrs(String code) { |
80 |
int epsg_code = Integer.parseInt(code); |
81 |
boolean source_yn = false; |
82 |
int source_cod = 0; |
83 |
int datum_code = 0; |
84 |
int projection_conv_code = 0; |
85 |
String crs_kind = null; |
86 |
|
87 |
Epsg2wkt wkt = null;
|
88 |
|
89 |
Crs crs = null;
|
90 |
|
91 |
ResultSet result = null; |
92 |
String sentence = "SELECT source_geogcrs_code, projection_conv_code, " |
93 |
+ "coord_ref_sys_kind, datum_code "
|
94 |
+ "FROM epsg_coordinatereferencesystem "
|
95 |
+ "WHERE coord_ref_sys_code = " + code;
|
96 |
|
97 |
connection.setConnectionEPSG(); |
98 |
result = Query.select(sentence,connection.getConnection());
|
99 |
|
100 |
/*try {
|
101 |
connection.shutdown();
|
102 |
} catch (SQLException e) {
|
103 |
// TODO Auto-generated catch block
|
104 |
e.printStackTrace();
|
105 |
}*/
|
106 |
|
107 |
try {
|
108 |
if (!result.next())
|
109 |
return null; |
110 |
source_cod = result.getInt("source_geogcrs_code");
|
111 |
projection_conv_code = result.getInt("projection_conv_code");
|
112 |
crs_kind = result.getString("coord_ref_sys_kind");
|
113 |
datum_code = result.getInt("datum_code");
|
114 |
} catch (SQLException e1) { |
115 |
LOG.info("Error executing the SQL", e1);
|
116 |
return null; |
117 |
} |
118 |
|
119 |
if (datum_code != 0){ |
120 |
source_yn = true;
|
121 |
} |
122 |
else if (source_cod != 0){ |
123 |
source_yn = false;
|
124 |
} |
125 |
else source_yn = true; |
126 |
|
127 |
CrsEPSG ep = new CrsEPSG(epsg_code, source_yn, source_cod, projection_conv_code, connection);
|
128 |
|
129 |
if (crs_kind.equals("geographic 2D") || crs_kind.equals("geographic 3D")){ |
130 |
wkt = new Epsg2wkt(ep , "geog"); |
131 |
} |
132 |
else if (crs_kind.equals("projected")){ |
133 |
wkt = new Epsg2wkt(ep, "proj"); |
134 |
} |
135 |
else if (crs_kind.equals("compound")){ |
136 |
wkt = new Epsg2wkt(ep,"comp"); |
137 |
} |
138 |
else if (crs_kind.equals("geocentric")){ |
139 |
wkt = new Epsg2wkt(ep,"geoc"); |
140 |
} |
141 |
|
142 |
try {
|
143 |
crs = new Crs(Integer.parseInt(code),wkt.getWKT()); |
144 |
} catch (CrsException e) {
|
145 |
LOG.info("Impossible to parse the CRS", e);
|
146 |
return null; |
147 |
} |
148 |
return crs;
|
149 |
} |
150 |
} |