Revision 157 trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GeoRasterFile.java
GeoRasterFile.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import java.awt.Component; |
9 | 9 |
import java.awt.Image; |
10 |
import java.lang.reflect.Constructor; |
|
11 |
import java.lang.reflect.InvocationTargetException; |
|
12 |
import java.util.TreeMap; |
|
10 | 13 |
|
11 | 14 |
import org.cresques.cts.ICoordTrans; |
12 | 15 |
import org.cresques.cts.IProjection; |
... | ... | |
15 | 18 |
import org.cresques.px.PxContour; |
16 | 19 |
import org.cresques.px.PxObjList; |
17 | 20 |
|
18 |
|
|
19 | 21 |
/** |
22 |
* Manejador de ficheros raster georeferenciados. |
|
20 | 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> |
|
21 | 30 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* |
22 | 31 |
*/ |
23 | 32 |
|
24 | 33 |
public abstract class GeoRasterFile extends GeoFile { |
34 |
private static TreeMap supportedExtensions = null; |
|
25 | 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 |
|
|
26 | 45 |
/** |
27 |
* Factoria para abrir distintos tipos de raster |
|
28 |
* @param fName |
|
29 |
* @return |
|
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. |
|
30 | 51 |
*/ |
31 | 52 |
public static GeoRasterFile openFile(IProjection proj, String fName) { |
32 | 53 |
String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
33 |
|
|
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 |
/* * / |
|
34 | 85 |
if (ext.compareTo("ecw") == 0) { |
35 |
return new EcwFile(proj, fName);
|
|
86 |
grf = new EcwFile(proj, fName);
|
|
36 | 87 |
} else if (ext.compareTo("tif") == 0 || ext.compareTo("tiff") == 0 || ext.compareTo("jpg") == 0 || ext.compareTo("png") == 0 ) { |
37 |
return new TifGeoRefFile(proj, fName); |
|
38 |
} |
|
39 |
/* // Copiado de WorldFile |
|
40 |
int lengthExtension = fName.length() - fName.lastIndexOf('.'); |
|
41 |
int l = fName.length(), le = lengthExtension-1; |
|
42 |
String wfExt = "."+fName.substring(l-le,l-(le-1))+fName.substring(l-1)+"w"; // ".tfw" |
|
43 |
String wfName = fName.substring(0, fName.length()-lengthExtension) + wfExt; |
|
44 |
File file = new File(wfName); |
|
45 |
|
|
46 |
if (ext.compareTo("ecw") == 0) { |
|
47 |
return new EcwFile(proj, fName); |
|
48 |
} else if (ext.compareTo("tif") == 0 || ext.compareTo("tiff") == 0 || ext.compareTo("jpg") == 0 || ext.compareTo("png") == 0) { |
|
49 |
// Si la imagen TIFF no lleva un fichero TFW asociado, el programa |
|
50 |
// entiende que se trata de una imagen en formato GeoTiff. La |
|
51 |
// aproximacion es correcta siempre que manejemos informacion |
|
52 |
// georeferenciada, puesto que cualquier TIFF Georeferenciado llevara |
|
53 |
// su correspondiente fichero TFW y si no lo lleva no sera una imagen |
|
54 |
// georeferenciada valida. |
|
55 |
// Para no meter la pata al contemplar TIFFs sin georeferenciar |
|
56 |
// debemos contemplar esta alternativa dentro de la categoria de los |
|
57 |
// GeoTiffs. |
|
58 |
if (!file.exists()) { |
|
59 |
return new GeoTiffFile(proj, fName); |
|
60 |
} else { |
|
61 |
return new TifGeoRefFile(proj, fName); |
|
62 |
} |
|
63 |
}*/ |
|
88 |
grf = new TifGeoRefFile(proj, fName); |
|
89 |
}/ * */ |
|
64 | 90 |
|
65 |
return (GeoRasterFile) null;
|
|
91 |
return grf;
|
|
66 | 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 |
|
|
67 | 104 |
public GeoRasterFile(IProjection proj, String name) { |
68 | 105 |
super(proj, name); |
69 | 106 |
} |
107 |
|
|
108 |
abstract public GeoFile load(); |
|
109 |
|
|
70 | 110 |
public static PxContour getContour(String fName, String name, IProjection proj) { |
71 | 111 |
PxContour contour = null; |
72 | 112 |
return contour; |
... | ... | |
77 | 117 |
|
78 | 118 |
abstract public void reProject(ICoordTrans rp); |
79 | 119 |
|
80 |
abstract public GeoFile load(); |
|
81 |
|
|
82 | 120 |
abstract public void setView(Extent e); |
83 | 121 |
abstract public Extent getView(); |
84 | 122 |
|
Also available in: Unified diff