svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / StatusLayerRaster.java @ 10450
History | View | Annotate | Download (6.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
|
45 |
import org.cresques.filter.RasterFilterStackManager; |
46 |
import org.cresques.io.GeoRasterFile; |
47 |
|
48 |
import com.iver.utiles.XMLEntity; |
49 |
|
50 |
/**
|
51 |
* Esta clase almacena el estado de un raster en cuanto a las caracteristicas de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y getXMLEntity
|
52 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
53 |
*/
|
54 |
public class StatusLayerRaster implements StatusRasterInterface{ |
55 |
|
56 |
public static String defaultClass = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
57 |
|
58 |
//Valor de opacidad global de la imagen
|
59 |
public int transparency = 0; |
60 |
|
61 |
//(Selecci?n de bandas)N?mero de banda asignado al Rojo, verde y azul
|
62 |
public int bandR = 0; |
63 |
public int bandG = 1; |
64 |
public int bandB = 2; |
65 |
|
66 |
//Ficheros cargados en un PxRaster
|
67 |
public ArrayList files = new ArrayList(); |
68 |
|
69 |
//Filtros para poder montar una nueva pila
|
70 |
/**
|
71 |
* @uml.property name="filters"
|
72 |
*/
|
73 |
public ArrayList filters = new ArrayList(); |
74 |
|
75 |
/* (non-Javadoc)
|
76 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
77 |
*/
|
78 |
public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException { |
79 |
|
80 |
//Recuperamos las propiedades de los filtros
|
81 |
for(int i=0;i<xml.getPropertyCount();i++){ |
82 |
if(xml.getPropertyName(i).startsWith("filter.")) |
83 |
filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
84 |
} |
85 |
|
86 |
if (xml.contains("raster.opacityLevel")) { |
87 |
transparency = xml.getIntProperty("raster.opacityLevel");
|
88 |
} |
89 |
if (xml.contains("raster.bandR")) { |
90 |
bandR = xml.getIntProperty("raster.bandR");
|
91 |
} |
92 |
if (xml.contains("raster.bandG")) { |
93 |
bandG = xml.getIntProperty("raster.bandG");
|
94 |
} |
95 |
if (xml.contains("raster.bandB")) { |
96 |
bandB = xml.getIntProperty("raster.bandB");
|
97 |
} |
98 |
|
99 |
int cont = 0; |
100 |
while(true && cont<50){ |
101 |
if (xml.contains("raster.file"+cont)) { |
102 |
files.add(xml.getStringProperty("raster.file"+cont));
|
103 |
cont++; |
104 |
}else
|
105 |
break;
|
106 |
} |
107 |
} |
108 |
|
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
112 |
*/
|
113 |
public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer) throws XMLException { |
114 |
|
115 |
if(loadClass)
|
116 |
xml.putProperty("raster.class", StatusLayerRaster.defaultClass);
|
117 |
|
118 |
if(transparency!=255) |
119 |
xml.putProperty("raster.opacityLevel", ""+transparency); |
120 |
|
121 |
xml.putProperty("raster.bandR", ""+bandR); |
122 |
xml.putProperty("raster.bandG", ""+bandG); |
123 |
xml.putProperty("raster.bandB", ""+bandB); |
124 |
|
125 |
|
126 |
if(files!=null && files.size()!=0){ |
127 |
for(int i=0;i<files.size();i++) |
128 |
xml.putProperty("raster.file"+i, ""+((String)files.get(i))); |
129 |
} |
130 |
|
131 |
//Salvamos la pila de filtros.
|
132 |
//Si la pila es null (esto puede ocurrir cuando se abre un
|
133 |
//proyecto que tiene WCS y no se abre la vista de este) entonces hay que leer los filtros
|
134 |
//que van a salvarse a disco directamente de la variable filters que es la que se ha cargado
|
135 |
//al hacer el setXMLEntity.
|
136 |
|
137 |
RasterFilterStackManager stackManager = null;
|
138 |
ArrayList l = null; |
139 |
if(layer.getFilterStack()!=null){ |
140 |
stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
141 |
l = stackManager.getStringsFromStack(); |
142 |
if(l == null || l.size() == 0) |
143 |
l = filters; |
144 |
}else
|
145 |
l = filters; |
146 |
|
147 |
for(int i=0;i<l.size();i++) |
148 |
xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Obtiene el valor de una cadena de la forma elemento=valor
|
153 |
* @param cadena
|
154 |
* @return
|
155 |
*/
|
156 |
private String getValue(String cadena){ |
157 |
if(cadena!=null) |
158 |
return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
159 |
else
|
160 |
return null; |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Obtiene el elemento de una cadena de la forma elemento=valor
|
165 |
* @param cadena
|
166 |
* @return
|
167 |
*/
|
168 |
private String getElem(String cadena){ |
169 |
if(cadena!=null) |
170 |
return cadena.substring(0, cadena.indexOf("=")); |
171 |
else
|
172 |
return null; |
173 |
} |
174 |
|
175 |
/* (non-Javadoc)
|
176 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters()
|
177 |
*/
|
178 |
/**
|
179 |
* @return
|
180 |
* @uml.property name="filters"
|
181 |
*/
|
182 |
public ArrayList getFilters(){ |
183 |
return this.filters; |
184 |
} |
185 |
|
186 |
|
187 |
/* (non-Javadoc)
|
188 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
189 |
*/
|
190 |
public void applyStatus(RasterOperations layer){ |
191 |
|
192 |
//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
193 |
//en el orden correcto
|
194 |
if(layer instanceof FLyrRaster){ |
195 |
if(files.size()!=0){ |
196 |
((FLyrRaster)layer).delFile((String)files.get(0)); |
197 |
for(int i=0;i<files.size();i++) |
198 |
((FLyrRaster)layer).addFiles((String)files.get(i));
|
199 |
} |
200 |
} |
201 |
|
202 |
//Asigna las bandas
|
203 |
if(bandR==-1)bandR=0; |
204 |
if(bandG==-1)bandG=0; |
205 |
if(bandB==-1)bandB=0; |
206 |
layer.setBand(GeoRasterFile.RED_BAND, bandR); |
207 |
layer.setBand(GeoRasterFile.GREEN_BAND, bandG); |
208 |
layer.setBand(GeoRasterFile.BLUE_BAND, bandB); |
209 |
|
210 |
//Asigna la transparencia
|
211 |
if(transparency != 255) |
212 |
layer.setTransparency(transparency); |
213 |
|
214 |
//Crea la pila de filtros a partir de las propiedades recuperadas desde el XML
|
215 |
if(layer.getFilterStack() != null){ |
216 |
RasterFilterStackManager stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
217 |
if(layer instanceof FLyrRaster) |
218 |
stackManager.createStackFromStrings(this.filters, ((FLyrRaster)layer).getSource().getFiles());
|
219 |
else
|
220 |
stackManager.createStackFromStrings(this.filters, new Integer(0)); |
221 |
} |
222 |
|
223 |
} |
224 |
} |