root / trunk / libraries / libCq CMS for java.old / src / org / cresques / geo / cover / Coverage.java @ 199
History | View | Annotate | Download (8.4 KB)
1 |
/*
|
---|---|
2 |
* Created on 25-abr-2004
|
3 |
*
|
4 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
5 |
*/
|
6 |
package org.cresques.geo.cover; |
7 |
|
8 |
import java.util.Hashtable; |
9 |
import java.util.Enumeration; |
10 |
|
11 |
import java.io.File; |
12 |
import java.io.FilenameFilter; |
13 |
|
14 |
import java.awt.Color; |
15 |
|
16 |
import org.cresques.px.*; |
17 |
import org.cresques.ui.CQApp; |
18 |
import org.cresques.cts.ICoordTrans; |
19 |
import org.cresques.cts.IProjection; |
20 |
import org.cresques.geo.Projected; |
21 |
import org.cresques.geo.Projection; |
22 |
import org.cresques.geo.ReProjection; |
23 |
import org.cresques.io.GeoRasterFile; |
24 |
//import org.cresques.io.*;
|
25 |
|
26 |
|
27 |
class FileSupport { |
28 |
String extension;
|
29 |
Class supportClass;
|
30 |
public FileSupport(String e, Class c) { |
31 |
extension = e; |
32 |
supportClass = c; |
33 |
} |
34 |
}; |
35 |
|
36 |
/**
|
37 |
* Cobertura espacial
|
38 |
*
|
39 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
40 |
*/
|
41 |
|
42 |
public class Coverage implements Projected { |
43 |
/* protected FileSupport [] fSupport = {
|
44 |
new FileSupport("ecw", EcwFile.class)
|
45 |
};*/
|
46 |
// Nombre de la cobertura
|
47 |
protected String name = "Orto ICV 1:5.000"; |
48 |
// Direcci?n raiz de los datos
|
49 |
protected String dName = null; //"//sercart/cartografia/ortofotos/Orto_ICV/00009"; |
50 |
protected int nLevels = 1; |
51 |
protected String hojaPrefix = ""; |
52 |
protected Hashtable hojas = null; |
53 |
; |
54 |
protected PxObjList marcos;
|
55 |
|
56 |
protected Color color = null; |
57 |
protected Color fillColor = null; |
58 |
protected boolean loadable = true; |
59 |
|
60 |
protected IProjection proj = null; |
61 |
|
62 |
public Coverage() {
|
63 |
hojas = new Hashtable(); |
64 |
} |
65 |
|
66 |
public String getName() { return name; } |
67 |
public Hashtable getHojas() { return hojas; } |
68 |
|
69 |
public IProjection getProjection() { return proj; } |
70 |
public void setProjection(IProjection p) { proj = p; } |
71 |
public void reProject(ICoordTrans rp) { |
72 |
// TODO metodo reProject pendiente de implementar
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* Verifica si la extensi?n del fichero esta en la lista de ficheros soportados.
|
77 |
* @param fName
|
78 |
* @return
|
79 |
* /
|
80 |
private boolean isSupportedFile(String fName) {
|
81 |
String fn = fName.toLowerCase();
|
82 |
for (int i=0; i< fSupport.length; i++)
|
83 |
if (fn.endsWith(fSupport[i].extension))
|
84 |
return true;
|
85 |
return false;
|
86 |
}*/
|
87 |
|
88 |
public void catalogue(String [] files) { |
89 |
for (int i=0; i<files.length; i++) { |
90 |
hojas.put(hojaPrefix+files[i],files[i]); |
91 |
} |
92 |
} |
93 |
|
94 |
public void catalogue() { |
95 |
catalogue(dName); |
96 |
} |
97 |
|
98 |
public void catalogueList(String [][] files) { |
99 |
Projection prj; |
100 |
for (int i=0; i<files.length; i++) { |
101 |
if (files[i][2] != null) |
102 |
prj = (Projection) Projection.getProjectionByName(proj.getDatum(), files[i][2]);
|
103 |
else
|
104 |
prj = ((Projection) proj); |
105 |
hojas.put(files[i][0],new Hoja(prj, files[i][1], files[i][0])); |
106 |
} |
107 |
} |
108 |
|
109 |
public void catalogue(String dName) { |
110 |
System.out.println("Catalogando '"+dName+"' ..."); |
111 |
File dir = new File(dName); |
112 |
if (!dir.exists()) {
|
113 |
System.err.println("Que dice que '"+dName+"'no existe"); |
114 |
return;
|
115 |
} |
116 |
String[] files = dir.list(); |
117 |
if (files != null) { |
118 |
catalogue(files); |
119 |
} |
120 |
} |
121 |
|
122 |
public void generateMinuteo(CQApp app, String lName, String lName1) { |
123 |
PxLayer layer1 = null;
|
124 |
if (color == null) color = new Color(64,220,64,255); |
125 |
if (fillColor == null) fillColor = new Color(128,220,128,32); |
126 |
if (hojas.size()== 0) |
127 |
catalogue(this.dName);
|
128 |
marcos = new PxObjList();
|
129 |
if (nLevels>0) { |
130 |
layer1 = app.createLayer(name+lName1, proj); |
131 |
layer1.setColor(color); |
132 |
layer1.setFillColor(fillColor); |
133 |
} |
134 |
PxLayer layer = app.createLayer(name+lName, proj); |
135 |
layer.setColor(color); |
136 |
layer.setFillColor(fillColor); |
137 |
Enumeration enum = hojas.keys(); |
138 |
String hName, hCode;
|
139 |
Hoja h; |
140 |
Object obj = null; |
141 |
while (enum.hasMoreElements()) { |
142 |
hName = (String) enum.nextElement(); |
143 |
obj = hojas.get(hName); |
144 |
if (obj.getClass() == String.class) { |
145 |
hCode = (String) obj;
|
146 |
generateMinuteoHoja(dName+"/"+hCode, hName, layer, layer1);
|
147 |
} else if (obj.getClass() == Hoja.class) { |
148 |
h = (Hoja) obj; |
149 |
generateMinuteoHoja(dName+"/"+h.getCode(), h, layer, layer1);
|
150 |
} |
151 |
} |
152 |
app.setCurrentMinuteo(layer); |
153 |
if (proj != app.getCurrentProjection()) {
|
154 |
ICoordTrans rp = null;
|
155 |
if (proj instanceof Projection) |
156 |
rp = new ReProjection(((Projection) proj), ((Projection)app.getCurrentProjection()));
|
157 |
layer.reProject(rp); |
158 |
if (layer1 != null) layer1.reProject(rp); |
159 |
} |
160 |
} |
161 |
|
162 |
public void generateMinuteoHoja(String hFName, Hoja h, PxLayer layer, PxLayer layer1) { |
163 |
GeoRasterFile eFile = null;
|
164 |
PxContour contour = null;
|
165 |
String fName = null; |
166 |
File dir = new File(hFName); |
167 |
if (!hFName.startsWith("ecwp:") && !dir.exists()) { |
168 |
System.err.println("Hoja '"+hFName+"' Inexistente"); |
169 |
return;
|
170 |
} |
171 |
if (dir.isDirectory()) {
|
172 |
} else {
|
173 |
if (!GeoRasterFile.fileIsSupported(hFName) ) return; |
174 |
fName = hFName; |
175 |
System.out.println("Analizo '"+h.getName()+"' ..."); |
176 |
eFile = GeoRasterFile.openFile(null, fName);
|
177 |
contour = new PxContour(eFile.getExtent(), fName, h.getName(), h.getProjection());
|
178 |
eFile.close(); |
179 |
contour.c(color); |
180 |
contour.fillColor(fillColor); |
181 |
layer.add(contour); |
182 |
} |
183 |
} |
184 |
|
185 |
public void generateMinuteoHoja(String hName, String name, PxLayer layer, PxLayer layer1) { |
186 |
GeoRasterFile eFile = null;
|
187 |
PxContour contour = null;
|
188 |
String fName = null; |
189 |
File dir = new File(hName); |
190 |
if (!hName.startsWith("ecwp:") && !dir.exists()) { |
191 |
System.err.println("Hoja '"+hName+"' Inexistente"); |
192 |
return;
|
193 |
} |
194 |
if (dir.isDirectory()) {
|
195 |
FilenameFilter filter = new FilenameFilter() { |
196 |
public boolean accept(File dir, String fName) { |
197 |
return GeoRasterFile.fileIsSupported(fName);
|
198 |
} |
199 |
}; |
200 |
String [] files = dir.list(filter); |
201 |
System.out.print(files.length+" ficheros."); |
202 |
|
203 |
if (files.length > 0) { |
204 |
Extent extent = new Extent();
|
205 |
for (int i=0; i<files.length; i++) { |
206 |
fName = hName+"/"+files[i];
|
207 |
System.out.println("Analizo '"+fName+"' ..."); |
208 |
eFile = GeoRasterFile.openFile(null, fName);
|
209 |
contour = new PxContour(eFile.getExtent(), fName, files[i], proj);
|
210 |
eFile.close(); |
211 |
|
212 |
//contour = EcwFile.getContour(fName, files[i], proj);
|
213 |
layer1.add(contour); |
214 |
// mapview.loadECW(hName+"/"+fName);
|
215 |
extent.add(contour.getExtent()); |
216 |
} |
217 |
if (contour != null) { |
218 |
contour = new PxContour(extent, hName, name, proj);
|
219 |
contour.c(color); |
220 |
contour.fillColor(fillColor); |
221 |
layer.add(contour); |
222 |
} |
223 |
} |
224 |
} else {
|
225 |
if (!GeoRasterFile.fileIsSupported(hName) ) return; |
226 |
fName = hName; |
227 |
System.out.println("Analizo '"+name+"' ..."); |
228 |
//contour = EcwFile.getContour(fName, name, proj);
|
229 |
eFile = GeoRasterFile.openFile(null, fName);
|
230 |
contour = new PxContour(eFile.getExtent(), fName, name, proj);
|
231 |
eFile.close(); |
232 |
contour.c(color); |
233 |
contour.fillColor(fillColor); |
234 |
layer.add(contour); |
235 |
// mapview.loadECW(hName+"/"+fName);
|
236 |
} |
237 |
} |
238 |
|
239 |
public void loadHoja(CQApp app, String hoja) { |
240 |
if (!loadable) return; |
241 |
String fName = null; |
242 |
Object obj = hojas.get(hoja);
|
243 |
String hCode=null; |
244 |
if (obj.getClass() == String.class) { |
245 |
hCode = (String) obj;
|
246 |
} else if (obj.getClass() == Hoja.class) { |
247 |
hCode = ((Hoja) obj).getCode(); |
248 |
} |
249 |
String hDName = dName+"/"+hCode; |
250 |
System.out.print("Explorando '"+hDName+"' ("+hoja+") ... " ); |
251 |
File dir = new File(hDName); |
252 |
if ((!hDName.startsWith("ecwp:") && !dir.exists()) || |
253 |
hojas.get(hoja) == null) {
|
254 |
System.err.println("Que dice que no existe"); |
255 |
return;
|
256 |
} |
257 |
|
258 |
String[] files;/* = dir.list(); |
259 |
/* if (children == null) {
|
260 |
// Either dir does not exist or is not a directory
|
261 |
} else {
|
262 |
for (int i=0; i<children.length; i++) {
|
263 |
// Get filename of file or directory
|
264 |
String filename = children[i];
|
265 |
}
|
266 |
} */
|
267 |
|
268 |
// It is also possible to filter the list of returned files.
|
269 |
// This example does not return any files that start with `.'.
|
270 |
if (dir.isDirectory()) {
|
271 |
FilenameFilter filter = new FilenameFilter() { |
272 |
public boolean accept(File dir, String fName) { |
273 |
return GeoRasterFile.fileIsSupported(fName);
|
274 |
} |
275 |
}; |
276 |
files = dir.list(filter); |
277 |
System.out.print(files.length+" ficheros."); |
278 |
|
279 |
if (files.length > 0) { |
280 |
PxLayer layer = app.createLayer(name+hoja, proj); |
281 |
for (int i=0; i<files.length; i++) { |
282 |
fName = files[i]; |
283 |
System.out.println("Cargo ...'"+fName+"'"); |
284 |
app.loadFile(hDName+"/"+fName, proj);
|
285 |
//mapview.canvas.zoomExtents();
|
286 |
app.getCanvas().repaint(); |
287 |
} |
288 |
} |
289 |
} else {
|
290 |
PxLayer layer = app.getLayerByName(name); |
291 |
if (layer == null) { |
292 |
layer = app.createLayer(name, proj); |
293 |
} |
294 |
app.setCurrentLayer(layer); |
295 |
fName = hDName; |
296 |
if (!GeoRasterFile.fileIsSupported(fName)) return; |
297 |
System.out.println("Cargo ...'"+fName+"'"); |
298 |
app.loadFile(fName, proj); |
299 |
//mapview.canvas.zoomExtents();
|
300 |
app.getCanvas().repaint(); |
301 |
} |
302 |
} |
303 |
} |