svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / geo / cover / Mtn.java @ 2312
History | View | Annotate | Download (7.11 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 java.io.BufferedReader; |
27 |
import java.io.FileNotFoundException; |
28 |
import java.io.FileReader; |
29 |
import java.io.IOException; |
30 |
import java.lang.Character; |
31 |
import java.util.TreeMap; |
32 |
import java.util.Iterator; |
33 |
import java.util.Vector; |
34 |
|
35 |
import org.cresques.geo.Ellipsoid; |
36 |
import org.cresques.geo.UtmZone; |
37 |
import org.cresques.px.Extent; |
38 |
import org.cresques.px.IObjList; |
39 |
import org.cresques.px.Minuteo; |
40 |
import org.cresques.px.PxContour; |
41 |
import org.cresques.px.PxObj; |
42 |
import org.cresques.px.PxObjList; |
43 |
import org.cresques.px.dxf.DxfSolid; |
44 |
import org.cresques.px.dxf.DxfText; |
45 |
|
46 |
/**
|
47 |
* Calculos de hojas del Instituto Geogr?fico Nacional de Espa?a.
|
48 |
*
|
49 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
50 |
*/
|
51 |
|
52 |
class Ign { |
53 |
/* MTN50: En coordenadas geogr?ficas: ancho =
|
54 |
*
|
55 |
*/
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
60 |
*/
|
61 |
public class Mtn { |
62 |
public static Mtn25 mtn25 = new Mtn25(); |
63 |
static Mtn50 mtn50 = Mtn.mtn25.getMtn50();
|
64 |
public static TreeMap hoja25 = Mtn.mtn25.hoja; |
65 |
public static TreeMap hoja50 = Mtn.mtn50.hoja; |
66 |
|
67 |
UtmZone zone = null;
|
68 |
String name = null; |
69 |
TreeMap hoja = null; |
70 |
private Minuteo min = null; |
71 |
|
72 |
public Minuteo getMinuteo() { return min; } |
73 |
|
74 |
protected void calcMinuteo() { |
75 |
System.out.println(name+": genero Minuteo"); |
76 |
min = new Minuteo(zone);
|
77 |
String hName;
|
78 |
PxContour contour; |
79 |
Iterator keys;
|
80 |
Hoja h = null;
|
81 |
|
82 |
keys = hoja.keySet().iterator(); |
83 |
while (keys.hasNext()) {
|
84 |
hName = (String) keys.next();
|
85 |
h = (Hoja) hoja.get(hName); |
86 |
contour = new PxContour(h.getVertex(), hName);
|
87 |
contour.setColor(null);
|
88 |
min.add(contour); |
89 |
} |
90 |
} |
91 |
|
92 |
public static void parseLayer(PxObjList layer) { |
93 |
Mtn25.mtn25.parseLyr(layer); |
94 |
} |
95 |
public static Minuteo getMinuteo25() { return mtn25.getMinuteo(); } |
96 |
public static Minuteo getMinuteo50() { return mtn50.getMinuteo(); } |
97 |
} |
98 |
|
99 |
class Mtn50 extends Mtn { |
100 |
public Mtn50() {
|
101 |
name = "MTN50";
|
102 |
zone = UtmZone.getProjection(Ellipsoid.hayford, 30, UtmZone.NORTH);
|
103 |
hoja = new TreeMap(); |
104 |
} |
105 |
} |
106 |
|
107 |
class Mtn25 extends Mtn { |
108 |
String buf;
|
109 |
//private TreeMap hojas25 = new TreeMap();
|
110 |
|
111 |
BufferedReader fi;
|
112 |
long l = 0; |
113 |
|
114 |
public Mtn25() {
|
115 |
name = "MTN25";
|
116 |
zone = UtmZone.getProjection(Ellipsoid.hayford, 30, UtmZone.NORTH);
|
117 |
hoja = new TreeMap(); |
118 |
/*String fname = "data/mtn25.txt";
|
119 |
load(fname);
|
120 |
calcMinuteo();*/
|
121 |
} |
122 |
|
123 |
public Mtn50 getMtn50() {
|
124 |
Mtn50 mtn50 = new Mtn50();
|
125 |
|
126 |
Iterator keys = hoja.keySet().iterator();
|
127 |
Hoja h = null, h50 = null; |
128 |
String code50;
|
129 |
while (keys.hasNext()) {
|
130 |
h = (Hoja) hoja.get(keys.next()); |
131 |
//System.err.println("Hoja 25"+h.code);
|
132 |
code50 = h.code.split("-")[0]; |
133 |
if (mtn50.hoja.containsKey(code50)) {
|
134 |
h50 = (Hoja) mtn50.hoja.get(code50); |
135 |
switch (Integer.parseInt(h.code.split("-")[1])) { |
136 |
case 1: h50.setTL(h.tl); break; |
137 |
case 2: h50.setTR(h.tr); break; |
138 |
case 3: h50.setBL(h.bl); break; |
139 |
case 4: h50.setBR(h.br); break; |
140 |
} |
141 |
} else
|
142 |
h50 = new Hoja(code50, h, null); |
143 |
mtn50.hoja.put(code50, h50); |
144 |
} |
145 |
mtn50.calcMinuteo(); |
146 |
return mtn50;
|
147 |
} |
148 |
|
149 |
public void load(String name) { |
150 |
try {
|
151 |
System.out.println("Cargando '"+name+"' ..."); |
152 |
fi = new BufferedReader(new FileReader(name)); |
153 |
while ((buf = fi.readLine()) != null) { |
154 |
//System.out.println(buf);
|
155 |
l++; |
156 |
parseLine(buf); |
157 |
} |
158 |
fi.close(); |
159 |
System.out.println("'"+name+"' cargado. ("+l+" l?neas)."); |
160 |
} catch (FileNotFoundException e) { |
161 |
e.printStackTrace(); |
162 |
} catch (IOException ie) { |
163 |
System.err.println("ERROR."+l+"lineas leidas"); |
164 |
ie.printStackTrace(); |
165 |
} |
166 |
} |
167 |
|
168 |
void parseLine(String l) { |
169 |
//756-1,[(311114.0, 4337768.0), (325515.0, 4337434.0), (325309.0, 4328185.0), (310891.0, 4328519.0)]
|
170 |
String [] field = l.split(","); |
171 |
field[1] = field[1].substring(1); |
172 |
field[8] = field[8].substring(0,field[8].length()-1); |
173 |
String name = field[0]; |
174 |
String aux;
|
175 |
double x,y;
|
176 |
Vector pt = new Vector(); |
177 |
for (int i=1; i<8; i+=2) { |
178 |
x = Double.parseDouble(field[i].trim().substring(1)); |
179 |
aux = field[i+1].trim();
|
180 |
y = Double.parseDouble(aux.substring(0, aux.length()-1)); |
181 |
pt.add(zone.createPoint(x, y)); |
182 |
} |
183 |
hoja.put(name, new Hoja(name, pt, "")); |
184 |
System.out.println(name);
|
185 |
} |
186 |
|
187 |
/*
|
188 |
* Genera las hojas del MTN25 a partir de una capa dxf.
|
189 |
* Llena un TreeMap con las hojas, de manera que se pueden
|
190 |
* obtener por su c?digo.
|
191 |
*/
|
192 |
private void fillSolids(IObjList marcos, IObjList oList) { |
193 |
Iterator iter = oList.iterator();;
|
194 |
while (iter.hasNext()) {
|
195 |
Object o = iter.next();
|
196 |
if (o instanceof IObjList) fillSolids(marcos, (IObjList) o); |
197 |
else if (o instanceof DxfSolid) marcos.add((PxObj) o); |
198 |
} |
199 |
} |
200 |
|
201 |
private void fillTexts(IObjList textos, IObjList oList) { |
202 |
Iterator iter = oList.iterator();;
|
203 |
while (iter.hasNext()) {
|
204 |
Object o = iter.next();
|
205 |
if (o instanceof IObjList) fillTexts(textos, (IObjList) o); |
206 |
else if (o instanceof DxfText) |
207 |
//if (Character.isDigit(((DxfText) o).getText().charAt(1)))
|
208 |
textos.add((Extent.Has) o); |
209 |
} |
210 |
} |
211 |
|
212 |
public void parseLyr(IObjList layer) { |
213 |
hoja = new TreeMap(); |
214 |
PxObjList marcos = new PxObjList();
|
215 |
PxObjList textos = new PxObjList();
|
216 |
Iterator iter = null; |
217 |
// Lleno una lista con solids, otra con texts.
|
218 |
System.out.println("layer: "+layer.size()+" objetos ("+layer.iterator().next()+")"); |
219 |
fillSolids(marcos, layer); |
220 |
System.out.println("fillSolids: "+marcos.size()+" marcos"); |
221 |
fillTexts(textos, layer); |
222 |
System.out.println("fillTexts: "+textos.size()+" textos"); |
223 |
// Para cada text busco un solid. Si lo encuentro creo
|
224 |
// una hoja con el solid y el text como name, la mento en
|
225 |
// el TreeMap y saco el solid de marcos
|
226 |
Hoja h = null;
|
227 |
DxfText text = null;
|
228 |
DxfSolid marco = null;
|
229 |
IObjList select = null;
|
230 |
iter = textos.iterator(); |
231 |
while (iter.hasNext()) {
|
232 |
text = (DxfText) iter.next(); |
233 |
if (hoja.containsKey(text.getText())) continue; |
234 |
if (!Character.isDigit(text.getText().split("-")[1].charAt(0))) continue; |
235 |
select = marcos.getAt(text.getPt1()); |
236 |
if (select.size() >= 1) { |
237 |
marco = (DxfSolid) select.iterator().next(); |
238 |
h = new Hoja(text.getText(), marco.getPts(), null); |
239 |
h.setProjection(layer.getProjection()); |
240 |
hoja.put(text.getText(), h); |
241 |
marcos.remove(marco); |
242 |
} else {
|
243 |
// ERROR. No puede haber m?s de un marco por texto
|
244 |
} |
245 |
} |
246 |
|
247 |
calcMinuteo(); |
248 |
Mtn.mtn50 = Mtn.mtn25.getMtn50(); |
249 |
Mtn.hoja25 = Mtn.mtn25.hoja; |
250 |
Mtn.hoja50 = Mtn.mtn50.hoja; |
251 |
} |
252 |
} |
253 |
|