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