root / trunk / libraries / libCq_CMS_praster / src / org / cresques / geo / cover / Mtn.java @ 8026
History | View | Annotate | Download (8.7 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.geo.cover; |
25 |
|
26 |
import org.cresques.geo.Ellipsoid; |
27 |
import org.cresques.geo.UtmZone; |
28 |
|
29 |
import org.cresques.px.Extent; |
30 |
import org.cresques.px.IObjList; |
31 |
import org.cresques.px.Minuteo; |
32 |
import org.cresques.px.PxContour; |
33 |
import org.cresques.px.PxObj; |
34 |
import org.cresques.px.PxObjList; |
35 |
import org.cresques.px.dxf.DxfSolid; |
36 |
import org.cresques.px.dxf.DxfText; |
37 |
|
38 |
import java.io.BufferedReader; |
39 |
import java.io.FileNotFoundException; |
40 |
import java.io.FileReader; |
41 |
import java.io.IOException; |
42 |
|
43 |
import java.lang.Character; |
44 |
|
45 |
import java.util.Iterator; |
46 |
import java.util.TreeMap; |
47 |
import java.util.Vector; |
48 |
|
49 |
|
50 |
/**
|
51 |
* Calculos de hojas del Instituto Geogr?fico Nacional de Espa?a.
|
52 |
*
|
53 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
54 |
*/
|
55 |
class Ign { |
56 |
/* MTN50: En coordenadas geogr?ficas: ancho =
|
57 |
*
|
58 |
*/
|
59 |
} |
60 |
|
61 |
|
62 |
/**
|
63 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
64 |
*/
|
65 |
public class Mtn { |
66 |
public static Mtn25 mtn25 = new Mtn25(); |
67 |
static Mtn50 mtn50 = Mtn.mtn25.getMtn50();
|
68 |
public static TreeMap hoja25 = Mtn.mtn25.hoja; |
69 |
public static TreeMap hoja50 = Mtn.mtn50.hoja; |
70 |
UtmZone zone = null;
|
71 |
String name = null; |
72 |
TreeMap hoja = null; |
73 |
private Minuteo min = null; |
74 |
|
75 |
public Minuteo getMinuteo() {
|
76 |
return min;
|
77 |
} |
78 |
|
79 |
protected void calcMinuteo() { |
80 |
System.out.println(name + ": genero Minuteo"); |
81 |
min = new Minuteo(zone);
|
82 |
|
83 |
String hName;
|
84 |
PxContour contour; |
85 |
Iterator keys;
|
86 |
Hoja h = null;
|
87 |
|
88 |
keys = hoja.keySet().iterator(); |
89 |
|
90 |
while (keys.hasNext()) {
|
91 |
hName = (String) keys.next();
|
92 |
h = (Hoja) hoja.get(hName); |
93 |
contour = new PxContour(h.getVertex(), hName);
|
94 |
contour.setColor(null);
|
95 |
min.add(contour); |
96 |
} |
97 |
} |
98 |
|
99 |
public static void parseLayer(PxObjList layer) { |
100 |
Mtn25.mtn25.parseLyr(layer); |
101 |
} |
102 |
|
103 |
public static Minuteo getMinuteo25() { |
104 |
return mtn25.getMinuteo();
|
105 |
} |
106 |
|
107 |
public static Minuteo getMinuteo50() { |
108 |
return mtn50.getMinuteo();
|
109 |
} |
110 |
} |
111 |
|
112 |
|
113 |
class Mtn50 extends Mtn { |
114 |
public Mtn50() {
|
115 |
name = "MTN50";
|
116 |
zone = UtmZone.getProjection(Ellipsoid.hayford, 30, UtmZone.NORTH);
|
117 |
hoja = new TreeMap(); |
118 |
} |
119 |
} |
120 |
|
121 |
|
122 |
class Mtn25 extends Mtn { |
123 |
String buf;
|
124 |
|
125 |
//private TreeMap hojas25 = new TreeMap();
|
126 |
BufferedReader fi;
|
127 |
long l = 0; |
128 |
|
129 |
public Mtn25() {
|
130 |
name = "MTN25";
|
131 |
zone = UtmZone.getProjection(Ellipsoid.hayford, 30, UtmZone.NORTH);
|
132 |
hoja = new TreeMap(); |
133 |
|
134 |
/*String fname = "data/mtn25.txt";
|
135 |
load(fname);
|
136 |
calcMinuteo();*/
|
137 |
} |
138 |
|
139 |
public Mtn50 getMtn50() {
|
140 |
Mtn50 mtn50 = new Mtn50();
|
141 |
|
142 |
Iterator keys = hoja.keySet().iterator();
|
143 |
Hoja h = null;
|
144 |
Hoja h50 = null;
|
145 |
String code50;
|
146 |
|
147 |
while (keys.hasNext()) {
|
148 |
h = (Hoja) hoja.get(keys.next()); |
149 |
|
150 |
//System.err.println("Hoja 25"+h.code);
|
151 |
code50 = h.code.split("-")[0]; |
152 |
|
153 |
if (mtn50.hoja.containsKey(code50)) {
|
154 |
h50 = (Hoja) mtn50.hoja.get(code50); |
155 |
|
156 |
switch (Integer.parseInt(h.code.split("-")[1])) { |
157 |
case 1: |
158 |
h50.setTL(h.tl); |
159 |
|
160 |
break;
|
161 |
|
162 |
case 2: |
163 |
h50.setTR(h.tr); |
164 |
|
165 |
break;
|
166 |
|
167 |
case 3: |
168 |
h50.setBL(h.bl); |
169 |
|
170 |
break;
|
171 |
|
172 |
case 4: |
173 |
h50.setBR(h.br); |
174 |
|
175 |
break;
|
176 |
} |
177 |
} else {
|
178 |
h50 = new Hoja(code50, h, null); |
179 |
} |
180 |
|
181 |
mtn50.hoja.put(code50, h50); |
182 |
} |
183 |
|
184 |
mtn50.calcMinuteo(); |
185 |
|
186 |
return mtn50;
|
187 |
} |
188 |
|
189 |
public void load(String name) { |
190 |
try {
|
191 |
System.out.println("Cargando '" + name + "' ..."); |
192 |
fi = new BufferedReader(new FileReader(name)); |
193 |
|
194 |
while ((buf = fi.readLine()) != null) { |
195 |
//System.out.println(buf);
|
196 |
l++; |
197 |
parseLine(buf); |
198 |
} |
199 |
|
200 |
fi.close(); |
201 |
System.out.println("'" + name + "' cargado. (" + l + " l?neas)."); |
202 |
} catch (FileNotFoundException e) { |
203 |
e.printStackTrace(); |
204 |
} catch (IOException ie) { |
205 |
System.err.println("ERROR." + l + "lineas leidas"); |
206 |
ie.printStackTrace(); |
207 |
} |
208 |
} |
209 |
|
210 |
void parseLine(String l) { |
211 |
//756-1,[(311114.0, 4337768.0), (325515.0, 4337434.0), (325309.0, 4328185.0), (310891.0, 4328519.0)]
|
212 |
String[] field = l.split(","); |
213 |
field[1] = field[1].substring(1); |
214 |
field[8] = field[8].substring(0, field[8].length() - 1); |
215 |
|
216 |
String name = field[0]; |
217 |
String aux;
|
218 |
double x;
|
219 |
double y;
|
220 |
Vector pt = new Vector(); |
221 |
|
222 |
for (int i = 1; i < 8; i += 2) { |
223 |
x = Double.parseDouble(field[i].trim().substring(1)); |
224 |
aux = field[i + 1].trim();
|
225 |
y = Double.parseDouble(aux.substring(0, aux.length() - 1)); |
226 |
pt.add(zone.createPoint(x, y)); |
227 |
} |
228 |
|
229 |
hoja.put(name, new Hoja(name, pt, "")); |
230 |
System.out.println(name);
|
231 |
} |
232 |
|
233 |
/*
|
234 |
* Genera las hojas del MTN25 a partir de una capa dxf.
|
235 |
* Llena un TreeMap con las hojas, de manera que se pueden
|
236 |
* obtener por su c?digo.
|
237 |
*/
|
238 |
private void fillSolids(IObjList marcos, IObjList oList) { |
239 |
Iterator iter = oList.iterator();
|
240 |
; |
241 |
|
242 |
while (iter.hasNext()) {
|
243 |
Object o = iter.next();
|
244 |
|
245 |
if (o instanceof IObjList) { |
246 |
fillSolids(marcos, (IObjList) o); |
247 |
} else if (o instanceof DxfSolid) { |
248 |
marcos.add((PxObj) o); |
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
private void fillTexts(IObjList textos, IObjList oList) { |
254 |
Iterator iter = oList.iterator();
|
255 |
; |
256 |
|
257 |
while (iter.hasNext()) {
|
258 |
Object o = iter.next();
|
259 |
|
260 |
if (o instanceof IObjList) { |
261 |
fillTexts(textos, (IObjList) o); |
262 |
} else if (o instanceof DxfText) { |
263 |
//if (Character.isDigit(((DxfText) o).getText().charAt(1)))
|
264 |
textos.add((Extent.Has) o); |
265 |
} |
266 |
} |
267 |
} |
268 |
|
269 |
public void parseLyr(IObjList layer) { |
270 |
hoja = new TreeMap(); |
271 |
|
272 |
PxObjList marcos = new PxObjList();
|
273 |
PxObjList textos = new PxObjList();
|
274 |
Iterator iter = null; |
275 |
|
276 |
// Lleno una lista con solids, otra con texts.
|
277 |
System.out.println("layer: " + layer.size() + " objetos (" + |
278 |
layer.iterator().next() + ")");
|
279 |
fillSolids(marcos, layer); |
280 |
System.out.println("fillSolids: " + marcos.size() + " marcos"); |
281 |
fillTexts(textos, layer); |
282 |
System.out.println("fillTexts: " + textos.size() + " textos"); |
283 |
|
284 |
// Para cada text busco un solid. Si lo encuentro creo
|
285 |
// una hoja con el solid y el text como name, la mento en
|
286 |
// el TreeMap y saco el solid de marcos
|
287 |
Hoja h = null;
|
288 |
DxfText text = null;
|
289 |
DxfSolid marco = null;
|
290 |
IObjList select = null;
|
291 |
iter = textos.iterator(); |
292 |
|
293 |
while (iter.hasNext()) {
|
294 |
text = (DxfText) iter.next(); |
295 |
|
296 |
if (hoja.containsKey(text.getText())) {
|
297 |
continue;
|
298 |
} |
299 |
|
300 |
if (!Character.isDigit(text.getText().split("-")[1].charAt(0))) { |
301 |
continue;
|
302 |
} |
303 |
|
304 |
select = marcos.getAt(text.getPt1()); |
305 |
|
306 |
if (select.size() >= 1) { |
307 |
marco = (DxfSolid) select.iterator().next(); |
308 |
h = new Hoja(text.getText(), marco.getPts(), null); |
309 |
h.setProjection(layer.getProjection()); |
310 |
hoja.put(text.getText(), h); |
311 |
marcos.remove(marco); |
312 |
} else {
|
313 |
// ERROR. No puede haber m?s de un marco por texto
|
314 |
} |
315 |
} |
316 |
|
317 |
calcMinuteo(); |
318 |
Mtn.mtn50 = Mtn.mtn25.getMtn50(); |
319 |
Mtn.hoja25 = Mtn.mtn25.hoja; |
320 |
Mtn.hoja50 = Mtn.mtn50.hoja; |
321 |
} |
322 |
} |