root / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / GeoRasterFile.java @ 157
History | View | Annotate | Download (4.08 KB)
1 |
/*
|
---|---|
2 |
* Created on 26-abr-2004
|
3 |
*
|
4 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
5 |
*/
|
6 |
package org.cresques.io; |
7 |
|
8 |
import java.awt.Component; |
9 |
import java.awt.Image; |
10 |
import java.lang.reflect.Constructor; |
11 |
import java.lang.reflect.InvocationTargetException; |
12 |
import java.util.TreeMap; |
13 |
|
14 |
import org.cresques.cts.ICoordTrans; |
15 |
import org.cresques.cts.IProjection; |
16 |
import org.cresques.px.Extent; |
17 |
import org.cresques.px.IObjList; |
18 |
import org.cresques.px.PxContour; |
19 |
import org.cresques.px.PxObjList; |
20 |
|
21 |
/**
|
22 |
* Manejador de ficheros raster georeferenciados.
|
23 |
*
|
24 |
* Esta clase abstracta es el ancestro de todas las clases que proporcionan
|
25 |
* soporte para ficheros raster georeferenciados.<br>
|
26 |
* Actua tambien como una 'Fabrica', ocultando al cliente la manera en que
|
27 |
* se ha implementado ese manejo. Una clase nueva que soportara un nuevo
|
28 |
* tipo de raster tendr?a que registrar su extensi?n o extensiones usando
|
29 |
* el m?todo @see registerExtension.<br>
|
30 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>*
|
31 |
*/
|
32 |
|
33 |
public abstract class GeoRasterFile extends GeoFile { |
34 |
private static TreeMap supportedExtensions = null; |
35 |
protected Component updatable = null; |
36 |
static {
|
37 |
supportedExtensions = new TreeMap(); |
38 |
supportedExtensions.put("ecw", EcwFile.class);
|
39 |
supportedExtensions.put("tif", TifGeoRefFile.class);
|
40 |
supportedExtensions.put("tiff", TifGeoRefFile.class);
|
41 |
supportedExtensions.put("jpg", TifGeoRefFile.class);
|
42 |
supportedExtensions.put("png", TifGeoRefFile.class);
|
43 |
} |
44 |
|
45 |
/**
|
46 |
* Factoria para abrir distintos tipos de raster.
|
47 |
*
|
48 |
* @param proj Proyecci?n en la que est? el raster.
|
49 |
* @param fName Nombre del fichero.
|
50 |
* @return GeoRasterFile, o null si hay problemas.
|
51 |
*/
|
52 |
public static GeoRasterFile openFile(IProjection proj, String fName) { |
53 |
String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
54 |
GeoRasterFile grf = null;
|
55 |
// TODO NotSupportedExtensionException
|
56 |
if (!supportedExtensions.containsKey(ext)) return grf; |
57 |
/**/
|
58 |
Class clase = (Class) supportedExtensions.get(ext); |
59 |
Class [] args = {IProjection.class, String.class}; |
60 |
try {
|
61 |
Constructor hazNuevo = clase.getConstructor(args);
|
62 |
Object [] args2 = {proj, fName}; |
63 |
grf = (GeoRasterFile) hazNuevo.newInstance(args2); |
64 |
} catch (SecurityException e) { |
65 |
// TODO Auto-generated catch block
|
66 |
e.printStackTrace(); |
67 |
} catch (NoSuchMethodException e) { |
68 |
// TODO Auto-generated catch block
|
69 |
e.printStackTrace(); |
70 |
} catch (IllegalArgumentException e) { |
71 |
// TODO Auto-generated catch block
|
72 |
e.printStackTrace(); |
73 |
} catch (InstantiationException e) { |
74 |
// TODO Auto-generated catch block
|
75 |
e.printStackTrace(); |
76 |
} catch (IllegalAccessException e) { |
77 |
// TODO Auto-generated catch block
|
78 |
e.printStackTrace(); |
79 |
} catch (InvocationTargetException e) { |
80 |
// TODO Auto-generated catch block
|
81 |
e.printStackTrace(); |
82 |
}/**/
|
83 |
|
84 |
/* * /
|
85 |
if (ext.compareTo("ecw") == 0) {
|
86 |
grf = new EcwFile(proj, fName);
|
87 |
} else if (ext.compareTo("tif") == 0 || ext.compareTo("tiff") == 0 || ext.compareTo("jpg") == 0 || ext.compareTo("png") == 0 ) {
|
88 |
grf = new TifGeoRefFile(proj, fName);
|
89 |
}/ * */
|
90 |
|
91 |
return grf;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* Registra una clase que soporta una extensi?n raster.
|
96 |
* @param ext extensi?n soportada.
|
97 |
* @param clase clase que la soporta.
|
98 |
*/
|
99 |
public static void registerExtension(String ext, Class clase) { |
100 |
ext = ext.toLowerCase(); |
101 |
supportedExtensions.put(ext, clase); |
102 |
} |
103 |
|
104 |
public GeoRasterFile(IProjection proj, String name) { |
105 |
super(proj, name);
|
106 |
} |
107 |
|
108 |
abstract public GeoFile load(); |
109 |
|
110 |
public static PxContour getContour(String fName, String name, IProjection proj) { |
111 |
PxContour contour = null;
|
112 |
return contour;
|
113 |
} |
114 |
|
115 |
abstract public int getWidth(); |
116 |
abstract public int getHeight(); |
117 |
|
118 |
abstract public void reProject(ICoordTrans rp); |
119 |
|
120 |
abstract public void setView(Extent e); |
121 |
abstract public Extent getView(); |
122 |
|
123 |
abstract public void setTransparency(boolean t); |
124 |
|
125 |
public void setUpdatable(Component c) { updatable = c; } |
126 |
|
127 |
abstract public Image updateImage(int width, int height, ICoordTrans rp); |
128 |
|
129 |
public IObjList getObjects() {
|
130 |
// TODO hay que a?adir el raster a la lista de objetos
|
131 |
IObjList oList = new PxObjList(proj);
|
132 |
return oList;
|
133 |
} |
134 |
} |