root / branches / libProjection_v2_0_prep / libraries / libJCRS / src / org / gvsig / crs / ogr / Epsg2wkt.java @ 27137
History | View | Annotate | Download (6.96 KB)
1 | 27137 | cmartinez | /* 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"};
|
||
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 | |||
83 | |||
84 | /**
|
||
85 | * Constructor para un CRS horizontal y proyectado
|
||
86 | */
|
||
87 | public Epsg2wkt(CrsEPSG epsg, String kind) { |
||
88 | |||
89 | if (kind.equals("proj")){ |
||
90 | String[] spheroid = epsg.getSPHEROID(); |
||
91 | String[] primem = epsg.getPRIMEM(); |
||
92 | String[] param_name = epsg.getParam_name(); |
||
93 | String[] param_value = epsg.getParam_value(); |
||
94 | String[] authority = epsg.getAUTHORITY(); |
||
95 | |||
96 | cadWKT = "PROJCS[\""+ epsg.getPROJCS()+"\", GEOGCS[\"" + epsg.getGEOGCS() + "\", DATUM[\""+ epsg.getDATUM() + |
||
97 | "\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
||
98 | "PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\""+ epsg.getUNIT_A() + "\", " + (Math.PI/180) + |
||
99 | "]], PROJECTION[\""+ getNameProjectionWkt(epsg.getPROJECTION()) + "\"], "; |
||
100 | |||
101 | /*
|
||
102 | * falta la parte de los par?metros... metodo para nombres...
|
||
103 | */
|
||
104 | for (int i= 0; i< param_name.length;i++){ |
||
105 | param_name[i] = getParametersWkt(param_name[i]); |
||
106 | cadWKT += "PARAMETER[\""+param_name[i]+"\", " + param_value[i]+ "], "; |
||
107 | } |
||
108 | |||
109 | cadWKT += "UNIT[\""+ epsg.getUNIT_B() + "\", "+epsg.getUnit_BValue()+"], "; |
||
110 | cadWKT += "AUTHORITY[\""+ authority[0] + "\", " + authority[1] + "]]"; |
||
111 | } |
||
112 | else if (kind.equals("geog")) { |
||
113 | String[] spheroid = epsg.getSPHEROID(); |
||
114 | String[] primem = epsg.getPRIMEM(); |
||
115 | String[] authority = epsg.getAUTHORITY(); |
||
116 | cadWKT = "GEOGCS[\"" + epsg.getGEOGCS() + "\", DATUM[\""+ epsg.getDATUM() + |
||
117 | "\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
||
118 | "PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\""+ epsg.getUNIT_A() + "\", " + (Math.PI/180) + |
||
119 | "], ";
|
||
120 | cadWKT += "AUTHORITY[\""+ authority[0] + "\", " + authority[1] + "]]"; |
||
121 | } |
||
122 | |||
123 | else if (kind.equals("geoc")){ |
||
124 | String[] spheroid = epsg.getSPHEROID(); |
||
125 | String[] primem = epsg.getPRIMEM(); |
||
126 | cadWKT = "GEOCCS[\"" + epsg.getGEOGCS() + "\", DATUM[\""+ epsg.getDATUM() + |
||
127 | "\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
||
128 | "PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\""+ epsg.getUNIT_A() + "\", " + (Math.PI/180) + |
||
129 | "]]";
|
||
130 | /*
|
||
131 | * parte necesaria cuando tratemos CRS geocentricos
|
||
132 | */
|
||
133 | } |
||
134 | |||
135 | else if (kind.equals("comp")){ |
||
136 | /*
|
||
137 | * parte necesaria cuando tratemos CRS compuestos (Hablar con David)
|
||
138 | */
|
||
139 | } |
||
140 | } |
||
141 | |||
142 | /*
|
||
143 | * Contructor para un CRS local (por ahora no se contempla)
|
||
144 | */
|
||
145 | public Epsg2wkt(String localcs, String local_datum, String unit, ArrayList axis) { |
||
146 | cadWKT = "LOCAL_CS[" + localcs + ", LOCAL_DATUM["+ local_datum + |
||
147 | "], UNIT["+ unit +"]"; |
||
148 | |||
149 | for (int i =0; i< axis.size(); i++){ |
||
150 | cadWKT += ", AXIS[" + axis.get(i) + "]"; |
||
151 | } |
||
152 | |||
153 | cadWKT += "]";
|
||
154 | } |
||
155 | |||
156 | public String getWKT(){ |
||
157 | return cadWKT;
|
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * Consigue la proyecci?n en el formato correcto para que sea legible
|
||
162 | * por la librer?a proj4. Acepta la proyecci?n del CRS seleccionado y
|
||
163 | * devuelve la misma proyecci?n escrita de manera correcta.
|
||
164 | * @param projection
|
||
165 | * @return
|
||
166 | */
|
||
167 | private String getNameProjectionWkt(String projection) { |
||
168 | String proj = null; |
||
169 | /*
|
||
170 | * hacer el cambio de nombre de proyeccion correcta
|
||
171 | */
|
||
172 | for (int i = 0; i< projectionsEPSG.length; i++){ |
||
173 | if (projectionsEPSG[i].equals(projection)){
|
||
174 | projection = projectionsWkt[i]; |
||
175 | } |
||
176 | } |
||
177 | proj = projection.replaceAll(" ", "_"); |
||
178 | return proj;
|
||
179 | } |
||
180 | |||
181 | /**
|
||
182 | * Acepta el par?metro actual, realiza el cambio necesario para que
|
||
183 | * sea legible por la proj4, y lo devuelve para insertarlo en la
|
||
184 | * cadena wkt
|
||
185 | *
|
||
186 | * @param param
|
||
187 | * @return
|
||
188 | */
|
||
189 | private String getParametersWkt(String param){ |
||
190 | for (int j=0; j< paramsEPSG.length; j++){ |
||
191 | if (param.equals(paramsEPSG[j])){
|
||
192 | param = paramsWkt[j]; |
||
193 | } |
||
194 | } |
||
195 | return param.replaceAll(" ", "_"); |
||
196 | } |
||
197 | } |