Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/geo/cover/Coverage.java

View differences:

Coverage.java
1 1
/*
2 2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5 3
 *
4
 * Copyright (C) 2004-5.
5
 *
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
8 8
 * as published by the Free Software Foundation; either version 2
......
18 18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19 19
 *
20 20
 * For more information, contact:
21
 * 
21
 *
22 22
 * cresques@gmail.com
23 23
 */
24 24
package org.cresques.geo.cover;
25 25

  
26
import java.util.ArrayList;
27
import java.util.Hashtable;
28
import java.util.Enumeration;
29

  
30
import java.io.File;
31
import java.io.FilenameFilter;
32

  
33
import java.awt.Color;
34

  
35
import org.cresques.px.*;
36
import org.cresques.ui.CQApp;
37 26
import org.cresques.cts.ICoordTrans;
38 27
import org.cresques.cts.IProjection;
39 28
import org.cresques.cts.ProjectionPool;
40 29
import org.cresques.cts.gt2.CoordSys;
41 30
import org.cresques.cts.gt2.CoordTrans;
31

  
42 32
import org.cresques.geo.Projected;
43 33
import org.cresques.geo.Projection;
44 34
import org.cresques.geo.ReProjection;
35

  
45 36
import org.cresques.io.GeoRasterFile;
46 37

  
38
import org.cresques.px.*;
39

  
40
import org.cresques.ui.CQApp;
41

  
42
import java.awt.Color;
43

  
44
import java.io.File;
45
import java.io.FilenameFilter;
46

  
47
import java.util.ArrayList;
48
import java.util.Enumeration;
49
import java.util.Hashtable;
50

  
51

  
47 52
/**
48 53
 * Cobertura espacial
49
 * 
54
 *
50 55
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
51 56
 */
52

  
53 57
public class Coverage implements Projected {
54
	boolean debug = true;
55
/*	protected FileSupport [] fSupport = {
56
		new FileSupport("ecw", EcwFile.class)
57
	};*/
58
	// Nombre de la cobertura
59
	protected String name = "Orto ICV 1:5.000";
60
	protected String fName = "cover";
61
	// Direcci?n raiz de los datos
62
	protected String dName = null; //"//sercart/cartografia/ortofotos/Orto_ICV/00009";
63
	protected int	nLevels = 1;
64
	protected String hojaPrefix = "";
65
	protected Hashtable hojas = null;
66
	private Hashtable files = null;
58
    boolean debug = true;
67 59

  
68
	protected PxObjList marcos;
69
	
70
	public Color color = null;
71
	public Color fillColor = null;
72
	protected boolean loadable = true;
73
	
74
	private String fType = "";
75
	
76
	protected IProjection proj = null;
77
	
78
	private boolean available = true;
79
	
80
	public Coverage() {
81
		hojas = new Hashtable();
82
		files = new Hashtable();
83
	}
84
	
85
	public String getName() { return name; }
86
	public Hashtable getHojas() { return hojas; }
87
	
88
	public IProjection getProjection() { return proj; }
89
	public void setProjection(IProjection p) { proj = p; }
90
	public void reProject(ICoordTrans rp) {
91
		// TODO metodo reProject pendiente de implementar
92
	}
93
	
94
	/**
95
	 * Asigna el estado de disponibilidad.
96
	 * Cuando una cobertura no esta disponible (la unidad est?
97
	 * inactiva, no tiene ficheros, etc...) deber? ponerse a false.
98
	 * Es true por defecto
99
	 * @param av Disponibilidad.
100
	 */
101
	public void setAvailable(boolean av) { available = av; }
102
	/**
103
	 * Devuelve el estado de disponibilidad. 
104
	 * @return Disponibilidad.
105
	 */
106
	public boolean getAvailable() { return available; }
107
	
108
	/**
109
	 * Especifica el tipo de los ficheros que forman la cobertura.
110
	 * Es un string que ser? procesado por la aplicaci?n. La clase
111
	 * Coverage no hace ning?n tratamiento de este valor.
112
	 * @param fType Tipo de ficheros.
113
	 */
114
	public void setFileType(String fType) { this.fType = fType; }
115
	
116
	/**
117
	 * Devuelve el tipo de fichero.
118
	 * @return Tipo de fichero.
119
	 */
120
	public String getFileType() { return fType; }
121
	
122
	public void catalogue(String [] files) {
123
		String hName = null;
124
		for (int i=0; i<files.length; i++) {
125
			hName = hojaPrefix+files[i];
126
			hojas.put(hName, files[i]);
127
			if (debug) System.out.println("Coverage: hojas.put('"+hName+"'");
128
		}
129
	}
60
    /*        protected FileSupport [] fSupport = {
61
                    new FileSupport("ecw", EcwFile.class)
62
            };*/
130 63

  
131
	public void catalogue() {
132
		catalogue(dName);
133
	}
134
	/**
135
	 * Hace el cat?logo a partir de la lista de ficheros.
136
	 * @param files
137
	 */
138
	public void catalogueList(String [][] files) {
139
		IProjection prj = proj;
140
		String hName = null;
141
		for (int i=0; i<files.length; i++) {
142
			if (files[i][2] != null)
143
				if (proj instanceof Projection)
144
					prj = (Projection) Projection.getProjectionByName(proj.getDatum(), files[i][2]);
145
    			else if (proj instanceof CoordSys)
146
    				prj = ProjectionPool.get(files[i][2]);
147
    		hName = files[i][0];
148
			hojas.put(hName, new Hoja(prj, files[i][1], files[i][0]));
149
			if (debug) System.out.println("Coverage: hojas.put('"+hName+"'");
150
		}
151
	}
152
	
153
	/**
154
	 * Hace el cat?logo recorriendo un directorio.
155
	 * @param dName
156
	 */
157
	public void catalogue(String dName) {
158
		System.out.println("Catalogando '"+dName+"' ...");
159
		File dir = new File(dName);
160
		if (!dir.exists()) {
161
			System.err.println("Que dice que '"+dName+"'no existe");
162
			return;
163
		}
164
		String[] files = dir.list();
165
		if (files != null) {
166
			catalogue(files);
167
		} 
168
	}
169
	
170
	public IObjList [] loadMinuteo() {
171
		IObjList [] minuteo = null;
172
		return minuteo;
173
	}
174
	
175
	public void saveMinuteo(IObjList [] minuteo) {
176
		for (int i=0; i<minuteo.length; i++) {
177
			
178
		}
179
	}
180
	/**
181
	 * Genera el minuteo, reproyectado.
182
	 * @param targetProj proyeccion de destino
183
	 * @return array de minuteos
184
	 */
185
	
186
	public IObjList[] generateMinuteo(IProjection targetProj) {
187
		IObjList [] minuteo = loadMinuteo();
188
		if (minuteo != null) return minuteo;
189
		minuteo = new IObjList[nLevels];
190
		for (int i=0; i<minuteo.length; i++)
191
			minuteo[i] = new PxObjList();
192
		if (hojas.size()== 0)
193
			catalogue(this.dName);
194
		marcos = new PxObjList();
195
		IObjList layer = minuteo[0], layer1 = null;
196
		if (nLevels > 1) layer1 = minuteo[1];
197
		
198
		Enumeration enum = hojas.keys();
199
		String hName, hCode;
200
		Hoja h;
201
		Object obj = null; 
202
		while (enum.hasMoreElements()) {
203
			hName = (String) enum.nextElement();
204
			try {
205
				obj = hojas.get(hName);
206
				if (obj instanceof String) {
207
					hCode = (String) obj;
208
					generateMinuteoHoja(dName+"/"+hCode, hName, layer, layer1);
209
				} else if (obj instanceof Hoja) {
210
					h = (Hoja) obj;
211
					generateMinuteoHoja(dName+"/"+h.getCode(), h, layer, layer1);
212
				}
213
			} catch (Exception e) {
214
				// TODO Tengo que tratar los errores de una forma mejor.
215
				System.err.println("Error al cargar la hoja "+hName);
216
				e.printStackTrace();
217
			}
218
		}
219
		saveMinuteo(minuteo);
220
		//app.setCurrentMinuteo(layer);
221
		if (proj != targetProj) {
222
			ICoordTrans rp = null;
223
			if (proj instanceof Projection)
224
				rp = new ReProjection(((Projection) proj), ((Projection) targetProj));
225
			else if (proj instanceof CoordSys)
226
				rp = new CoordTrans((CoordSys) proj, (CoordSys) targetProj);
227
			layer.reProject(rp);
228
			if (layer1 != null) layer1.reProject(rp);
229
		}
230
		return minuteo;
231
	}
232
	
233
	public void generateMinuteo(CQApp app, String lName, String lName1) {
234
		PxLayer layer1 = null;
235
		if (color == null) color = new Color(64,220,64,255);
236
		if (fillColor == null) fillColor = new Color(128,220,128,32);
237
		if (hojas.size()== 0)
238
			catalogue(this.dName);
239
		marcos = new PxObjList();
240
		if (nLevels>0) {
241
			layer1 = app.createLayer(name+lName1, proj);
242
			layer1.setColor(color);
243
			layer1.setFillColor(fillColor);
244
		}
245
		PxLayer layer = app.createLayer(name+lName, proj);
246
		layer.setColor(color);
247
		layer.setFillColor(fillColor);
248
		Enumeration enum = hojas.keys();
249
		String hName, hCode;
250
		Hoja h;
251
		Object obj = null; 
252
		while (enum.hasMoreElements()) {
253
			hName = (String) enum.nextElement();
254
			obj = hojas.get(hName);
255
			if (obj.getClass() == String.class) {
256
				hCode = (String) obj;
257
				generateMinuteoHoja(dName+"/"+hCode, hName, layer, layer1);
258
			} else if (obj.getClass() == Hoja.class) {
259
				h = (Hoja) obj;
260
				generateMinuteoHoja(dName+"/"+h.getCode(), h, layer, layer1);
261
			}
262
		}
263
		app.setCurrentMinuteo(layer);
264
		if (proj != app.getCurrentProjection()) {
265
			ICoordTrans rp = null;
266
			if (proj instanceof Projection)
267
				rp = new ReProjection(((Projection) proj), ((Projection)app.getCurrentProjection()));
268
			layer.reProject(rp);
269
			if (layer1 != null) layer1.reProject(rp);
270
		}
271
	}
272
	
273
	public void generateMinuteoHoja(String hFName, Hoja h, IObjList layer, IObjList layer1) {
274
		GeoRasterFile eFile = null;
275
		PxContour contour = null;
276
		String fName = null;
277
		File dir = new File(hFName);
278
		if (!hFName.startsWith("ecwp:") && !dir.exists()) {
279
			System.err.println("Hoja '"+hFName+"' Inexistente");
280
			return;
281
		}
282
		if (dir.isDirectory()) {
283
		} else {
284
			if (!GeoRasterFile.fileIsSupported(hFName) ) return;
285
			fName = hFName;
286
			System.out.println("Analizo '"+h.getName()+"' ...");
287
			eFile = GeoRasterFile.openFile(null, fName);
288
			contour = new PxContour(eFile.getExtent(), fName, h.getName(), h.getProjection());
289
    		if (proj != h.getProjection()) {
290
    			ICoordTrans rp = null;
291
    			if (proj instanceof Projection)
292
    				rp = new ReProjection(((Projection) h.getProjection()), ((Projection) proj));
293
    			else if (proj instanceof CoordSys)
294
    				rp = new CoordTrans((CoordSys) h.getProjection(), (CoordSys) proj);
295
    			contour.reProject(rp);
296
    		}
297
			eFile.close();
298
			contour.c(color);
299
			contour.fillColor(fillColor);
300
			layer.add(contour);
301
		}		
302
	}
303
	
304
	public void generateMinuteoHoja(String hName, String name, IObjList layer, IObjList layer1) {
305
		GeoRasterFile eFile = null;
306
		PxContour contour = null;
307
		String fName = null;
308
		File dir = new File(hName);
309
		if (!hName.startsWith("ecwp:") && !dir.exists()) {
310
			System.err.println("Hoja '"+hName+"' Inexistente");
311
			return;
312
		}
313
		if (dir.isDirectory()) {
314
			FilenameFilter filter = new FilenameFilter() {
315
				public boolean accept(File dir, String fName) {
316
					return GeoRasterFile.fileIsSupported(fName);
317
				}
318
			};
319
			String [] files = dir.list(filter);
320
			System.out.print(files.length+" ficheros.");
64
    // Nombre de la cobertura
65
    protected String name = "Orto ICV 1:5.000";
66
    protected String fName = "cover";
321 67

  
322
			if (files.length > 0) {
323
				Extent extent = new Extent();
324
				for (int i=0; i<files.length; i++) {
325
					fName = hName+"/"+files[i];
326
					System.out.println("Analizo '"+fName+"' ...");
327
					eFile = GeoRasterFile.openFile(null, fName);
328
					contour = new PxContour(eFile.getExtent(), fName, files[i], proj);
329
					eFile.close();
68
    // Direcci?n raiz de los datos
69
    protected String dName = null; //"//sercart/cartografia/ortofotos/Orto_ICV/00009";
70
    protected int nLevels = 1;
71
    protected String hojaPrefix = "";
72
    protected Hashtable hojas = null;
73
    private Hashtable files = null;
74
    protected PxObjList marcos;
75
    public Color color = null;
76
    public Color fillColor = null;
77
    protected boolean loadable = true;
78
    private String fType = "";
79
    protected IProjection proj = null;
80
    private boolean available = true;
330 81

  
331
					//contour = EcwFile.getContour(fName, files[i], proj);
332
					layer1.add(contour);
333
//					mapview.loadECW(hName+"/"+fName);
334
					extent.add(contour.getExtent());
335
				}
336
				if (contour != null) {
337
					contour = new PxContour(extent, hName, name, proj);
338
					contour.c(color);
339
					contour.fillColor(fillColor);
340
					layer.add(contour);
341
				}
342
			}
343
		} else {
344
			if (!GeoRasterFile.fileIsSupported(hName) ) return;
345
			fName = hName;
346
			System.out.println("Analizo '"+name+"' ...");
347
			//contour = EcwFile.getContour(fName, name, proj);
348
			eFile = GeoRasterFile.openFile(null, fName);
349
			contour = new PxContour(eFile.getExtent(), fName, name, proj);
350
			eFile.close();
351
			contour.c(color);
352
			contour.fillColor(fillColor);
353
			layer.add(contour);
354
//			mapview.loadECW(hName+"/"+fName);
355
		}		
356
	}
357
	
358
	/**
359
	 * Devuelve los ficheros que incluye la hoja.
360
	 * @param hoja hoja que se busca.
361
	 * @return nombre(s) de fichero(s).
362
	 */
363
	
364
	public ArrayList getFileNames(String hoja) {
365
		ArrayList fNames = new ArrayList();
366
		
367
		if (!loadable) return null;
368
		String fName = null;
369
		Object obj = hojas.get(hoja);
370
		String hCode = null;
371
		String hDName = null;
372
		File dir = null;
373
		if (obj != null) {
374
			if (obj instanceof String) {
375
				hCode = (String) obj;
376
			} else if (obj instanceof Hoja) {
377
				hCode = ((Hoja) obj).getCode();
378
			}
379
			hDName = dName+"/"+hCode;
380
			System.out.print("Explorando '"+hDName+"' ("+hoja+") ... " );
381
			dir = new File(hDName);
382
		}
383
		if (obj == null ||
384
			(!hDName.startsWith("ecwp:") && !dir.exists()) ) {
385
			System.err.println("Que dice que no existe");
386
			return null;
387
		}
388
    
389
		String[] files;/* = dir.list();
390
/*		if (children == null) {
391
			// Either dir does not exist or is not a directory
392
		} else {
393
			for (int i=0; i<children.length; i++) {
394
				// Get filename of file or directory
395
				String filename = children[i];
396
			}
397
		} */
398
    
399
		// It is also possible to filter the list of returned files.
400
		// This example does not return any files that start with `.'.
401
		if (dir.isDirectory()) {
402
			FilenameFilter filter = new FilenameFilter() {
403
				public boolean accept(File dir, String fName) {
404
					return GeoRasterFile.fileIsSupported(fName);
405
				}
406
			};
407
			files = dir.list(filter);
408
			System.out.print(files.length+" ficheros.");
409
	
410
			if (files.length > 0) {
411
				//PxLayer layer = app.createLayer(name+hoja, proj);
412
				for (int i=0; i<files.length; i++) {
413
					fName = files[i];
414
					System.out.println("Cargo ...'"+fName+"'");
415
					fNames.add(hDName+"/"+fName);
416
					//mapview.canvas.zoomExtents();
417
					//app.getCanvas().repaint();
418
				}
419
			}
420
		} else {
421
			//PxLayer layer = app.getLayerByName(name);
422
			//if (layer == null) {
423
			//	layer = app.createLayer(name, proj);
424
			//}
425
			//app.setCurrentLayer(layer);
426
			fName = hDName;
427
			if (!GeoRasterFile.fileIsSupported(fName)) return null;
428
			System.out.println("Cargo ...'"+fName+"'");
429
			fNames.add(fName);
430
			//mapview.canvas.zoomExtents();
431
			//app.getCanvas().repaint();
432
		}
433
		return fNames;
434
	}
435
	
436
	public void loadHoja(CQApp app, String hoja) {
437
		if (!loadable) return;
438
		String fName = null;
439
		Object obj = hojas.get(hoja);
440
		String hCode=null;
441
		if (obj.getClass() == String.class) {
442
			hCode = (String) obj;
443
		} else if (obj.getClass() == Hoja.class) {
444
			hCode = ((Hoja) obj).getCode();
445
		}
446
		String hDName = dName+"/"+hCode;
447
		System.out.print("Explorando '"+hDName+"' ("+hoja+") ... " );
448
		File dir = new File(hDName);
449
		if ((!hDName.startsWith("ecwp:") && !dir.exists()) ||
450
			hojas.get(hoja) == null) {
451
			System.err.println("Que dice que no existe");
452
			return;
453
		}
454
    
455
		String[] files;/* = dir.list();
456
/*		if (children == null) {
457
			// Either dir does not exist or is not a directory
458
		} else {
459
			for (int i=0; i<children.length; i++) {
460
				// Get filename of file or directory
461
				String filename = children[i];
462
			}
463
		} */
464
    
465
		// It is also possible to filter the list of returned files.
466
		// This example does not return any files that start with `.'.
467
		if (dir.isDirectory()) {
468
			FilenameFilter filter = new FilenameFilter() {
469
				public boolean accept(File dir, String fName) {
470
					return GeoRasterFile.fileIsSupported(fName);
471
				}
472
			};
473
			files = dir.list(filter);
474
			System.out.print(files.length+" ficheros.");
475
	
476
			if (files.length > 0) {
477
				PxLayer layer = app.createLayer(name+hoja, proj);
478
				for (int i=0; i<files.length; i++) {
479
					fName = files[i];
480
					System.out.println("Cargo ...'"+fName+"'");
481
					app.loadFile(hDName+"/"+fName, proj);
482
					//mapview.canvas.zoomExtents();
483
					app.getCanvas().repaint();
484
				}
485
			}
486
		} else {
487
			PxLayer layer = app.getLayerByName(name);
488
			if (layer == null) {
489
				layer = app.createLayer(name, proj);
490
			}
491
			app.setCurrentLayer(layer);
492
			fName = hDName;
493
			if (!GeoRasterFile.fileIsSupported(fName)) return;
494
			System.out.println("Cargo ...'"+fName+"'");
495
			app.loadFile(fName, proj);
496
			//mapview.canvas.zoomExtents();
497
			app.getCanvas().repaint();
498
		}
499
	}
82
    public Coverage() {
83
        hojas = new Hashtable();
84
        files = new Hashtable();
85
    }
86

  
87
    public String getName() {
88
        return name;
89
    }
90

  
91
    public Hashtable getHojas() {
92
        return hojas;
93
    }
94

  
95
    public IProjection getProjection() {
96
        return proj;
97
    }
98

  
99
    public void setProjection(IProjection p) {
100
        proj = p;
101
    }
102

  
103
    public void reProject(ICoordTrans rp) {
104
        // TODO metodo reProject pendiente de implementar
105
    }
106

  
107
    /**
108
     * Asigna el estado de disponibilidad.
109
     * Cuando una cobertura no esta disponible (la unidad est?
110
     * inactiva, no tiene ficheros, etc...) deber? ponerse a false.
111
     * Es true por defecto
112
     * @param av Disponibilidad.
113
     */
114
    public void setAvailable(boolean av) {
115
        available = av;
116
    }
117

  
118
    /**
119
     * Devuelve el estado de disponibilidad.
120
     * @return Disponibilidad.
121
     */
122
    public boolean getAvailable() {
123
        return available;
124
    }
125

  
126
    /**
127
     * Especifica el tipo de los ficheros que forman la cobertura.
128
     * Es un string que ser? procesado por la aplicaci?n. La clase
129
     * Coverage no hace ning?n tratamiento de este valor.
130
     * @param fType Tipo de ficheros.
131
     */
132
    public void setFileType(String fType) {
133
        this.fType = fType;
134
    }
135

  
136
    /**
137
     * Devuelve el tipo de fichero.
138
     * @return Tipo de fichero.
139
     */
140
    public String getFileType() {
141
        return fType;
142
    }
143

  
144
    public void catalogue(String[] files) {
145
        String hName = null;
146

  
147
        for (int i = 0; i < files.length; i++) {
148
            hName = hojaPrefix + files[i];
149
            hojas.put(hName, files[i]);
150

  
151
            if (debug) {
152
                System.out.println("Coverage: hojas.put('" + hName + "'");
153
            }
154
        }
155
    }
156

  
157
    public void catalogue() {
158
        catalogue(dName);
159
    }
160

  
161
    /**
162
     * Hace el cat?logo a partir de la lista de ficheros.
163
     * @param files
164
     */
165
    public void catalogueList(String[][] files) {
166
        IProjection prj = proj;
167
        String hName = null;
168

  
169
        for (int i = 0; i < files.length; i++) {
170
            if (files[i][2] != null) {
171
                if (proj instanceof Projection) {
172
                    prj = (Projection) Projection.getProjectionByName(proj.getDatum(),
173
                                                                      files[i][2]);
174
                } else if (proj instanceof CoordSys) {
175
                    prj = ProjectionPool.get(files[i][2]);
176
                }
177
            }
178

  
179
            hName = files[i][0];
180
            hojas.put(hName, new Hoja(prj, files[i][1], files[i][0]));
181

  
182
            if (debug) {
183
                System.out.println("Coverage: hojas.put('" + hName + "'");
184
            }
185
        }
186
    }
187

  
188
    /**
189
     * Hace el cat?logo recorriendo un directorio.
190
     * @param dName
191
     */
192
    public void catalogue(String dName) {
193
        System.out.println("Catalogando '" + dName + "' ...");
194

  
195
        File dir = new File(dName);
196

  
197
        if (!dir.exists()) {
198
            System.err.println("Que dice que '" + dName + "'no existe");
199

  
200
            return;
201
        }
202

  
203
        String[] files = dir.list();
204

  
205
        if (files != null) {
206
            catalogue(files);
207
        }
208
    }
209

  
210
    public IObjList[] loadMinuteo() {
211
        IObjList[] minuteo = null;
212

  
213
        return minuteo;
214
    }
215

  
216
    public void saveMinuteo(IObjList[] minuteo) {
217
        for (int i = 0; i < minuteo.length; i++) {
218
        }
219
    }
220

  
221
    /**
222
     * Genera el minuteo, reproyectado.
223
     * @param targetProj proyeccion de destino
224
     * @return array de minuteos
225
     */
226
    public IObjList[] generateMinuteo(IProjection targetProj) {
227
        IObjList[] minuteo = loadMinuteo();
228

  
229
        if (minuteo != null) {
230
            return minuteo;
231
        }
232

  
233
        minuteo = new IObjList[nLevels];
234

  
235
        for (int i = 0; i < minuteo.length; i++)
236
            minuteo[i] = new PxObjList();
237

  
238
        if (hojas.size() == 0) {
239
            catalogue(this.dName);
240
        }
241

  
242
        marcos = new PxObjList();
243

  
244
        IObjList layer = minuteo[0];
245
        IObjList layer1 = null;
246

  
247
        if (nLevels > 1) {
248
            layer1 = minuteo[1];
249
        }
250

  
251
        Enumeration enum = hojas.keys();
252
        String hName;
253
        String hCode;
254
        Hoja h;
255
        Object obj = null;
256

  
257
        while (enum.hasMoreElements()) {
258
            hName = (String) enum.nextElement();
259

  
260
            try {
261
                obj = hojas.get(hName);
262

  
263
                if (obj instanceof String) {
264
                    hCode = (String) obj;
265
                    generateMinuteoHoja(dName + "/" + hCode, hName, layer,
266
                                        layer1);
267
                } else if (obj instanceof Hoja) {
268
                    h = (Hoja) obj;
269
                    generateMinuteoHoja(dName + "/" + h.getCode(), h, layer,
270
                                        layer1);
271
                }
272
            } catch (Exception e) {
273
                // TODO Tengo que tratar los errores de una forma mejor.
274
                System.err.println("Error al cargar la hoja " + hName);
275
                e.printStackTrace();
276
            }
277
        }
278

  
279
        saveMinuteo(minuteo);
280

  
281
        //app.setCurrentMinuteo(layer);
282
        if (proj != targetProj) {
283
            ICoordTrans rp = null;
284

  
285
            if (proj instanceof Projection) {
286
                rp = new ReProjection(((Projection) proj),
287
                                      ((Projection) targetProj));
288
            } else if (proj instanceof CoordSys) {
289
                rp = new CoordTrans((CoordSys) proj, (CoordSys) targetProj);
290
            }
291

  
292
            layer.reProject(rp);
293

  
294
            if (layer1 != null) {
295
                layer1.reProject(rp);
296
            }
297
        }
298

  
299
        return minuteo;
300
    }
301

  
302
    public void generateMinuteo(CQApp app, String lName, String lName1) {
303
        PxLayer layer1 = null;
304

  
305
        if (color == null) {
306
            color = new Color(64, 220, 64, 255);
307
        }
308

  
309
        if (fillColor == null) {
310
            fillColor = new Color(128, 220, 128, 32);
311
        }
312

  
313
        if (hojas.size() == 0) {
314
            catalogue(this.dName);
315
        }
316

  
317
        marcos = new PxObjList();
318

  
319
        if (nLevels > 0) {
320
            layer1 = app.createLayer(name + lName1, proj);
321
            layer1.setColor(color);
322
            layer1.setFillColor(fillColor);
323
        }
324

  
325
        PxLayer layer = app.createLayer(name + lName, proj);
326
        layer.setColor(color);
327
        layer.setFillColor(fillColor);
328

  
329
        Enumeration enum = hojas.keys();
330
        String hName;
331
        String hCode;
332
        Hoja h;
333
        Object obj = null;
334

  
335
        while (enum.hasMoreElements()) {
336
            hName = (String) enum.nextElement();
337
            obj = hojas.get(hName);
338

  
339
            if (obj.getClass() == String.class) {
340
                hCode = (String) obj;
341
                generateMinuteoHoja(dName + "/" + hCode, hName, layer, layer1);
342
            } else if (obj.getClass() == Hoja.class) {
343
                h = (Hoja) obj;
344
                generateMinuteoHoja(dName + "/" + h.getCode(), h, layer, layer1);
345
            }
346
        }
347

  
348
        app.setCurrentMinuteo(layer);
349

  
350
        if (proj != app.getCurrentProjection()) {
351
            ICoordTrans rp = null;
352

  
353
            if (proj instanceof Projection) {
354
                rp = new ReProjection(((Projection) proj),
355
                                      ((Projection) app.getCurrentProjection()));
356
            }
357

  
358
            layer.reProject(rp);
359

  
360
            if (layer1 != null) {
361
                layer1.reProject(rp);
362
            }
363
        }
364
    }
365

  
366
    public void generateMinuteoHoja(String hFName, Hoja h, IObjList layer,
367
                                    IObjList layer1) {
368
        GeoRasterFile eFile = null;
369
        PxContour contour = null;
370
        String fName = null;
371
        File dir = new File(hFName);
372

  
373
        if (!hFName.startsWith("ecwp:") && !dir.exists()) {
374
            System.err.println("Hoja '" + hFName + "' Inexistente");
375

  
376
            return;
377
        }
378

  
379
        if (dir.isDirectory()) {
380
        } else {
381
            if (!GeoRasterFile.fileIsSupported(hFName)) {
382
                return;
383
            }
384

  
385
            fName = hFName;
386
            System.out.println("Analizo '" + h.getName() + "' ...");
387
            eFile = GeoRasterFile.openFile(null, fName);
388
            contour = new PxContour(eFile.getExtent(), fName, h.getName(),
389
                                    h.getProjection());
390

  
391
            if (proj != h.getProjection()) {
392
                ICoordTrans rp = null;
393

  
394
                if (proj instanceof Projection) {
395
                    rp = new ReProjection(((Projection) h.getProjection()),
396
                                          ((Projection) proj));
397
                } else if (proj instanceof CoordSys) {
398
                    rp = new CoordTrans((CoordSys) h.getProjection(),
399
                                        (CoordSys) proj);
400
                }
401

  
402
                contour.reProject(rp);
403
            }
404

  
405
            eFile.close();
406
            contour.c(color);
407
            contour.fillColor(fillColor);
408
            layer.add(contour);
409
        }
410
    }
411

  
412
    public void generateMinuteoHoja(String hName, String name, IObjList layer,
413
                                    IObjList layer1) {
414
        GeoRasterFile eFile = null;
415
        PxContour contour = null;
416
        String fName = null;
417
        File dir = new File(hName);
418

  
419
        if (!hName.startsWith("ecwp:") && !dir.exists()) {
420
            System.err.println("Hoja '" + hName + "' Inexistente");
421

  
422
            return;
423
        }
424

  
425
        if (dir.isDirectory()) {
426
            FilenameFilter filter = new FilenameFilter() {
427
                public boolean accept(File dir, String fName) {
428
                    return GeoRasterFile.fileIsSupported(fName);
429
                }
430
            };
431

  
432
            String[] files = dir.list(filter);
433
            System.out.print(files.length + " ficheros.");
434

  
435
            if (files.length > 0) {
436
                Extent extent = new Extent();
437

  
438
                for (int i = 0; i < files.length; i++) {
439
                    fName = hName + "/" + files[i];
440
                    System.out.println("Analizo '" + fName + "' ...");
441
                    eFile = GeoRasterFile.openFile(null, fName);
442
                    contour = new PxContour(eFile.getExtent(), fName, files[i],
443
                                            proj);
444
                    eFile.close();
445

  
446
                    //contour = EcwFile.getContour(fName, files[i], proj);
447
                    layer1.add(contour);
448

  
449
                    //					mapview.loadECW(hName+"/"+fName);
450
                    extent.add(contour.getExtent());
451
                }
452

  
453
                if (contour != null) {
454
                    contour = new PxContour(extent, hName, name, proj);
455
                    contour.c(color);
456
                    contour.fillColor(fillColor);
457
                    layer.add(contour);
458
                }
459
            }
460
        } else {
461
            if (!GeoRasterFile.fileIsSupported(hName)) {
462
                return;
463
            }
464

  
465
            fName = hName;
466
            System.out.println("Analizo '" + name + "' ...");
467

  
468
            //contour = EcwFile.getContour(fName, name, proj);
469
            eFile = GeoRasterFile.openFile(null, fName);
470
            contour = new PxContour(eFile.getExtent(), fName, name, proj);
471
            eFile.close();
472
            contour.c(color);
473
            contour.fillColor(fillColor);
474
            layer.add(contour);
475

  
476
            //			mapview.loadECW(hName+"/"+fName);
477
        }
478
    }
479

  
480
    /**
481
     * Devuelve los ficheros que incluye la hoja.
482
     * @param hoja hoja que se busca.
483
     * @return nombre(s) de fichero(s).
484
     */
485
    public ArrayList getFileNames(String hoja) {
486
        ArrayList fNames = new ArrayList();
487

  
488
        if (!loadable) {
489
            return null;
490
        }
491

  
492
        String fName = null;
493
        Object obj = hojas.get(hoja);
494
        String hCode = null;
495
        String hDName = null;
496
        File dir = null;
497

  
498
        if (obj != null) {
499
            if (obj instanceof String) {
500
                hCode = (String) obj;
501
            } else if (obj instanceof Hoja) {
502
                hCode = ((Hoja) obj).getCode();
503
            }
504

  
505
            hDName = dName + "/" + hCode;
506
            System.out.print("Explorando '" + hDName + "' (" + hoja + ") ... ");
507
            dir = new File(hDName);
508
        }
509

  
510
        if ((obj == null) || (!hDName.startsWith("ecwp:") && !dir.exists())) {
511
            System.err.println("Que dice que no existe");
512

  
513
            return null;
514
        }
515

  
516
        String[] files; /* = dir.list();
517
        /*                if (children == null) {
518
        // Either dir does not exist or is not a directory
519
        } else {
520
        for (int i=0; i<children.length; i++) {
521
         // Get filename of file or directory
522
         String filename = children[i];
523
        }
524
        } */
525

  
526
        // It is also possible to filter the list of returned files.
527
        // This example does not return any files that start with `.'.
528
        if (dir.isDirectory()) {
529
            FilenameFilter filter = new FilenameFilter() {
530
                public boolean accept(File dir, String fName) {
531
                    return GeoRasterFile.fileIsSupported(fName);
532
                }
533
            };
534

  
535
            files = dir.list(filter);
536
            System.out.print(files.length + " ficheros.");
537

  
538
            if (files.length > 0) {
539
                //PxLayer layer = app.createLayer(name+hoja, proj);
540
                for (int i = 0; i < files.length; i++) {
541
                    fName = files[i];
542
                    System.out.println("Cargo ...'" + fName + "'");
543
                    fNames.add(hDName + "/" + fName);
544

  
545
                    //mapview.canvas.zoomExtents();
546
                    //app.getCanvas().repaint();
547
                }
548
            }
549
        } else {
550
            //PxLayer layer = app.getLayerByName(name);
551
            //if (layer == null) {
552
            //	layer = app.createLayer(name, proj);
553
            //}
554
            //app.setCurrentLayer(layer);
555
            fName = hDName;
556

  
557
            if (!GeoRasterFile.fileIsSupported(fName)) {
558
                return null;
559
            }
560

  
561
            System.out.println("Cargo ...'" + fName + "'");
562
            fNames.add(fName);
563

  
564
            //mapview.canvas.zoomExtents();
565
            //app.getCanvas().repaint();
566
        }
567

  
568
        return fNames;
569
    }
570

  
571
    public void loadHoja(CQApp app, String hoja) {
572
        if (!loadable) {
573
            return;
574
        }
575

  
576
        String fName = null;
577
        Object obj = hojas.get(hoja);
578
        String hCode = null;
579

  
580
        if (obj.getClass() == String.class) {
581
            hCode = (String) obj;
582
        } else if (obj.getClass() == Hoja.class) {
583
            hCode = ((Hoja) obj).getCode();
584
        }
585

  
586
        String hDName = dName + "/" + hCode;
587
        System.out.print("Explorando '" + hDName + "' (" + hoja + ") ... ");
588

  
589
        File dir = new File(hDName);
590

  
591
        if ((!hDName.startsWith("ecwp:") && !dir.exists()) ||
592
                (hojas.get(hoja) == null)) {
593
            System.err.println("Que dice que no existe");
594

  
595
            return;
596
        }
597

  
598
        String[] files; /* = dir.list();
599
        /*                if (children == null) {
600
        // Either dir does not exist or is not a directory
601
        } else {
602
        for (int i=0; i<children.length; i++) {
603
         // Get filename of file or directory
604
         String filename = children[i];
605
        }
606
        } */
607

  
608
        // It is also possible to filter the list of returned files.
609
        // This example does not return any files that start with `.'.
610
        if (dir.isDirectory()) {
611
            FilenameFilter filter = new FilenameFilter() {
612
                public boolean accept(File dir, String fName) {
613
                    return GeoRasterFile.fileIsSupported(fName);
614
                }
615
            };
616

  
617
            files = dir.list(filter);
618
            System.out.print(files.length + " ficheros.");
619

  
620
            if (files.length > 0) {
621
                PxLayer layer = app.createLayer(name + hoja, proj);
622

  
623
                for (int i = 0; i < files.length; i++) {
624
                    fName = files[i];
625
                    System.out.println("Cargo ...'" + fName + "'");
626
                    app.loadFile(hDName + "/" + fName, proj);
627

  
628
                    //mapview.canvas.zoomExtents();
629
                    app.getCanvas().repaint();
630
                }
631
            }
632
        } else {
633
            PxLayer layer = app.getLayerByName(name);
634

  
635
            if (layer == null) {
636
                layer = app.createLayer(name, proj);
637
            }
638

  
639
            app.setCurrentLayer(layer);
640
            fName = hDName;
641

  
642
            if (!GeoRasterFile.fileIsSupported(fName)) {
643
                return;
644
            }
645

  
646
            System.out.println("Cargo ...'" + fName + "'");
647
            app.loadFile(fName, proj);
648

  
649
            //mapview.canvas.zoomExtents();
650
            app.getCanvas().repaint();
651
        }
652
    }
500 653
}

Also available in: Unified diff