svn-gvsig-desktop / tags / v1_1_Build_1013 / libraries / libJCRS / src / org / gvsig / crs / ogr / Epsg2wkt.java @ 13521
History | View | Annotate | Download (7.91 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.ogr; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
|
45 |
/**
|
46 |
* Clase que genera de un CRS escogido del repositorio de EPSG su cadena
|
47 |
* en wkt correctamente para la creaci?n del CRS conforme a los par?metros
|
48 |
* aceptados en la librer?a proj4 (en cuanto a formato)
|
49 |
*
|
50 |
* @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
|
51 |
*/
|
52 |
public class Epsg2wkt { |
53 |
|
54 |
String cadWKT= ""; |
55 |
|
56 |
/*
|
57 |
* definimos 2 arrays para el cambio de proyecciones y de parametros de la epsg a
|
58 |
* proyecciones y par?metros entendibles por gdal, de manera que el elemento i
|
59 |
* de cada uno de ellos coincide con el cambio correcto de epsg a gdal.
|
60 |
*/
|
61 |
String[] paramsEPSG = {"Angle from Rectified to Skew Grid", "Azimuth of initial line", |
62 |
"Easting at false origin", "Easting at projection centre", "False easting", |
63 |
"False northing", "Latitude of false origin", "Latitude of 1st standard parallel", |
64 |
"Latitude of natural origin", "Latitude of origin", "Latitude of projection centre", |
65 |
"Latitude of 2nd standard parallel", "Longitude of false origin", |
66 |
"Longitude of natural origin", "Longitude of origin", "Longitude of projection centre", |
67 |
"Northing at false origin", "Northing at projection centre", |
68 |
"Scale factor at natural origin", "Scale factor on initial line",}; |
69 |
|
70 |
String[] paramsWkt = {"rectified_grid_angle", "azimuth", "false_easting", "false_easting", |
71 |
"false_easting", "false_northing", "latitude_of_origin", "standard_parallel_1", |
72 |
"latitude_of_origin", "latitude_of_origin", "latitude_of_center", "standard_parallel_2", |
73 |
"central_meridian", "central_meridian", "central_meridian", "longitude_of_center", |
74 |
"false_northing", "false_northing", "scale_factor", "scale_factor",}; |
75 |
|
76 |
String[] projectionsEPSG = {"Lambert Conic Conformal (1SP)","Lambert Conic Conformal (2SP)", |
77 |
"Lambert Conic Conformal (2SP) Belgium", "American Polyconic", "Krovak Oblique Conic Conformal", |
78 |
"Albers Equal Area", "Mercator (1SP)", "Mercator (2SP)", "Polar Stereographic (variant A)", "Polar Stereographic (variant B)", "Polar Stereographic (variant C)"}; |
79 |
|
80 |
String[] projectionsWkt = {"Lambert Conformal Conic 1SP","Lambert Conformal Conic 2SP", |
81 |
"Lambert Conformal Conic 2SP Belgium", "Polyconic", "Krovak", "Albers Conic Equal Area", |
82 |
"Mercator 1SP", "Mercator 2SP", "Polar Stereographic", "Polar Stereographic", "Polar Stereographic"}; |
83 |
|
84 |
String[] authority ; |
85 |
|
86 |
/**
|
87 |
* Constructor para un CRS horizontal y proyectado
|
88 |
*/
|
89 |
public Epsg2wkt(GetCRSepsg epsg, String kind) { |
90 |
|
91 |
if (kind.equals("proj")){ |
92 |
String[] spheroid = epsg.getSPHEROID(); |
93 |
String[] primem = epsg.getPRIMEM(); |
94 |
String[] param_name = epsg.getParam_name(); |
95 |
String[] param_value = epsg.getParam_value(); |
96 |
authority = epsg.getAUTHORITY(); |
97 |
|
98 |
cadWKT = "PROJCS[\""+ epsg.getPROJCS()+"\", GEOGCS[\"" + epsg.getGEOGCS() + "\", DATUM[\""+ epsg.getDATUM() + |
99 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
100 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\""+ epsg.getUNIT_A() + "\", " + (Math.PI/180) + |
101 |
"]], PROJECTION[\""+ getNameProjectionWkt(epsg.getPROJECTION()) + "\"], "; |
102 |
|
103 |
/*
|
104 |
* falta la parte de los par?metros... metodo para nombres...
|
105 |
*/
|
106 |
for (int i= 0; i< param_name.length;i++){ |
107 |
param_name[i] = getParametersWkt(param_name[i]); |
108 |
cadWKT += "PARAMETER[\""+param_name[i]+"\", " + param_value[i]+ "], "; |
109 |
} |
110 |
|
111 |
cadWKT += "UNIT[\""+ epsg.getUNIT_B() + "\", "+epsg.getUnit_BValue()+"], "; |
112 |
cadWKT += "AUTHORITY[\""+ authority[0] + "\", " + authority[1] + "]]"; |
113 |
} |
114 |
else if (kind.equals("geog")) { |
115 |
String[] spheroid = epsg.getSPHEROID(); |
116 |
String[] primem = epsg.getPRIMEM(); |
117 |
String[] authority = epsg.getAUTHORITY(); |
118 |
cadWKT = "GEOGCS[\"" + epsg.getGEOGCS() + "\", DATUM[\""+ epsg.getDATUM() + |
119 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
120 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\""+ epsg.getUNIT_A() + "\", " + (Math.PI/180) + |
121 |
"], ";
|
122 |
cadWKT += "AUTHORITY[\""+ authority[0] + "\", " + authority[1] + "]]"; |
123 |
} |
124 |
|
125 |
else if (kind.equals("geoc")){ |
126 |
String[] spheroid = epsg.getSPHEROID(); |
127 |
String[] primem = epsg.getPRIMEM(); |
128 |
cadWKT = "GEOCCS[\"" + epsg.getGEOGCS() + "\", DATUM[\""+ epsg.getDATUM() + |
129 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
130 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\""+ epsg.getUNIT_A() + "\", " + (Math.PI/180) + |
131 |
"]]";
|
132 |
/*
|
133 |
* parte necesaria cuando tratemos CRS geocentricos
|
134 |
*/
|
135 |
} |
136 |
|
137 |
else if (kind.equals("comp")){ |
138 |
/*
|
139 |
* parte necesaria cuando tratemos CRS compuestos (Hablar con David)
|
140 |
*/
|
141 |
} |
142 |
} |
143 |
|
144 |
/*
|
145 |
* Contructor para un CRS local (por ahora no se contempla)
|
146 |
*/
|
147 |
public Epsg2wkt(String localcs, String local_datum, String unit, ArrayList axis) { |
148 |
cadWKT = "LOCAL_CS[" + localcs + ", LOCAL_DATUM["+ local_datum + |
149 |
"], UNIT["+ unit +"]"; |
150 |
|
151 |
for (int i =0; i< axis.size(); i++){ |
152 |
cadWKT += ", AXIS[" + axis.get(i) + "]"; |
153 |
} |
154 |
|
155 |
cadWKT += "]";
|
156 |
} |
157 |
|
158 |
public String getWKT(){ |
159 |
return cadWKT;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* Consigue la proyecci?n en el formato correcto para que sea legible
|
164 |
* por la librer?a proj4. Acepta la proyecci?n del CRS seleccionado y
|
165 |
* devuelve la misma proyecci?n escrita de manera correcta.
|
166 |
* @param projection
|
167 |
* @return
|
168 |
*/
|
169 |
private String getNameProjectionWkt(String projection) { |
170 |
String proj = null; |
171 |
|
172 |
/**
|
173 |
* El motivo de este cambio es que si le pedimos la proyecci?n a estos dos
|
174 |
* crs proyectados dentro de la epsg, el valor devuelto es la proyecci?n
|
175 |
* "oblique mercator", mientras que tras consultarlo en distintas fuentes
|
176 |
* todas coinciden en que la proyecci?n para estos dos c?digos de la epsg es la
|
177 |
* "Hotine Oblique Mercator". Si se deja con la proyecci?n que viene de la epsg,
|
178 |
* al pasar por gdal para formar la cadena proj4 falla, mientras que al cambiar
|
179 |
* el nombre de dicha proyecci?n, la cadena proj4 resultante es correcta.
|
180 |
*/
|
181 |
// TODO controlar estos casos excepcionales
|
182 |
if (authority[1].equals("2056") || authority[1].equals("21781")) |
183 |
return "Hotine_Oblique_Mercator"; |
184 |
/*
|
185 |
* hacer el cambio de nombre de proyeccion correcta
|
186 |
*/
|
187 |
for (int i = 0; i< projectionsEPSG.length; i++){ |
188 |
if (projectionsEPSG[i].equals(projection)){
|
189 |
projection = projectionsWkt[i]; |
190 |
} |
191 |
} |
192 |
proj = projection.replaceAll(" ", "_"); |
193 |
return proj;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Acepta el par?metro actual, realiza el cambio necesario para que
|
198 |
* sea legible por la proj4, y lo devuelve para insertarlo en la
|
199 |
* cadena wkt
|
200 |
*
|
201 |
* @param param
|
202 |
* @return
|
203 |
*/
|
204 |
private String getParametersWkt(String param){ |
205 |
for (int j=0; j< paramsEPSG.length; j++){ |
206 |
if (param.equals(paramsEPSG[j])){
|
207 |
param = paramsWkt[j]; |
208 |
} |
209 |
} |
210 |
return param.replaceAll(" ", "_"); |
211 |
} |
212 |
} |