svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / StatusLayerRaster.java @ 5222
History | View | Annotate | Download (6.72 KB)
1 | 2183 | fernando | /* 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.io.GeoRasterFile; |
||
46 | import org.cresques.io.raster.RasterFilterStackManager; |
||
47 | |||
48 | 4163 | nacho | import com.iver.cit.gvsig.fmap.MapControl; |
49 | 2183 | fernando | import com.iver.utiles.XMLEntity; |
50 | |||
51 | /**
|
||
52 | *
|
||
53 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
54 | *
|
||
55 | * Esta clase almacena el estado de un raster en cuanto a las caracteristicas
|
||
56 | * de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a
|
||
57 | * un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y
|
||
58 | * getXMLEntity
|
||
59 | */
|
||
60 | public class StatusLayerRaster implements StatusRasterInterface{ |
||
61 | |||
62 | 4091 | nacho | public static String defaultClass = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
63 | |||
64 | 2183 | fernando | //Valor de opacidad global de la imagen
|
65 | 2767 | nacho | public int transparency = 0; |
66 | 2183 | fernando | |
67 | //(Selecci?n de bandas)N?mero de banda asignado al Rojo, verde y azul
|
||
68 | public int bandR = 0; |
||
69 | public int bandG = 1; |
||
70 | public int bandB = 2; |
||
71 | |||
72 | //Ficheros cargados en un PxRaster
|
||
73 | public ArrayList files = new ArrayList(); |
||
74 | |||
75 | //Filtros para poder montar una nueva pila
|
||
76 | public ArrayList filters = new ArrayList(); |
||
77 | 4163 | nacho | |
78 | private boolean isPansharpInStack = false; |
||
79 | 2183 | fernando | |
80 | /* (non-Javadoc)
|
||
81 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
82 | */
|
||
83 | 2623 | nacho | public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException { |
84 | 4188 | nacho | |
85 | //Recuperamos las propiedades de los filtros
|
||
86 | for(int i=0;i<xml.getPropertyCount();i++){ |
||
87 | if(xml.getPropertyName(i).startsWith("filter.")){ |
||
88 | if(xml.getPropertyName(i).startsWith("filter.pansharpening")) |
||
89 | isPansharpInStack = true;
|
||
90 | filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
||
91 | } |
||
92 | } |
||
93 | |||
94 | 2183 | fernando | if (xml.contains("raster.opacityLevel")) { |
95 | transparency = xml.getIntProperty("raster.opacityLevel");
|
||
96 | } |
||
97 | if (xml.contains("raster.bandR")) { |
||
98 | bandR = xml.getIntProperty("raster.bandR");
|
||
99 | } |
||
100 | if (xml.contains("raster.bandG")) { |
||
101 | bandG = xml.getIntProperty("raster.bandG");
|
||
102 | } |
||
103 | if (xml.contains("raster.bandB")) { |
||
104 | bandB = xml.getIntProperty("raster.bandB");
|
||
105 | } |
||
106 | 2653 | nacho | |
107 | 2183 | fernando | int cont = 0; |
108 | while(true && cont<50){ |
||
109 | if (xml.contains("raster.file"+cont)) { |
||
110 | files.add(xml.getStringProperty("raster.file"+cont));
|
||
111 | cont++; |
||
112 | }else
|
||
113 | break;
|
||
114 | 4188 | nacho | } |
115 | 2183 | fernando | } |
116 | |||
117 | |||
118 | /* (non-Javadoc)
|
||
119 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
||
120 | */
|
||
121 | 2623 | nacho | public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer) throws XMLException { |
122 | 2183 | fernando | |
123 | if(loadClass)
|
||
124 | 4091 | nacho | xml.putProperty("raster.class", StatusLayerRaster.defaultClass);
|
125 | 2183 | fernando | |
126 | if(transparency!=255) |
||
127 | xml.putProperty("raster.opacityLevel", ""+transparency); |
||
128 | |||
129 | xml.putProperty("raster.bandR", ""+bandR); |
||
130 | xml.putProperty("raster.bandG", ""+bandG); |
||
131 | xml.putProperty("raster.bandB", ""+bandB); |
||
132 | |||
133 | 2647 | nacho | |
134 | 2183 | fernando | if(files!=null && files.size()!=0){ |
135 | for(int i=0;i<files.size();i++) |
||
136 | xml.putProperty("raster.file"+i, ""+((String)files.get(i))); |
||
137 | } |
||
138 | |||
139 | 2633 | nacho | //Salvamos la pila de filtros.
|
140 | //Si la pila es null (esto puede ocurrir cuando se abre un
|
||
141 | //proyecto que tiene WCS y no se abre la vista de este) entonces hay que leer los filtros
|
||
142 | //que van a salvarse a disco directamente de la variable filters que es la que se ha cargado
|
||
143 | //al hacer el setXMLEntity.
|
||
144 | 2183 | fernando | |
145 | 2633 | nacho | RasterFilterStackManager stackManager = null;
|
146 | ArrayList l = null; |
||
147 | if(layer.getFilterStack()!=null){ |
||
148 | stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
||
149 | l = stackManager.getStringsFromStack(); |
||
150 | 2647 | nacho | if(l == null || l.size() == 0) |
151 | l = filters; |
||
152 | 2633 | nacho | }else
|
153 | l = filters; |
||
154 | 2647 | nacho | |
155 | 2633 | nacho | |
156 | 4163 | nacho | for(int i=0;i<l.size();i++) |
157 | 2183 | fernando | xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
158 | } |
||
159 | |||
160 | /**
|
||
161 | * Obtiene el valor de una cadena de la forma elemento=valor
|
||
162 | * @param cadena
|
||
163 | * @return
|
||
164 | */
|
||
165 | private String getValue(String cadena){ |
||
166 | if(cadena!=null) |
||
167 | return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
||
168 | else
|
||
169 | return null; |
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * Obtiene el elemento de una cadena de la forma elemento=valor
|
||
174 | * @param cadena
|
||
175 | * @return
|
||
176 | */
|
||
177 | private String getElem(String cadena){ |
||
178 | if(cadena!=null) |
||
179 | return cadena.substring(0, cadena.indexOf("=")); |
||
180 | else
|
||
181 | return null; |
||
182 | } |
||
183 | |||
184 | /* (non-Javadoc)
|
||
185 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters()
|
||
186 | */
|
||
187 | public ArrayList getFilters(){ |
||
188 | return this.filters; |
||
189 | } |
||
190 | |||
191 | /* (non-Javadoc)
|
||
192 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
||
193 | */
|
||
194 | 2623 | nacho | public void applyStatus(RasterOperations layer){ |
195 | 4163 | nacho | |
196 | 2183 | fernando | //Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
197 | //en el orden correcto
|
||
198 | 2623 | nacho | if(layer instanceof FLyrRaster){ |
199 | if(files.size()!=0){ |
||
200 | ((FLyrRaster)layer).delFile(layer.getSource().getFiles()[0].getName());
|
||
201 | for(int i=0;i<files.size();i++) |
||
202 | ((FLyrRaster)layer).addFiles((String)files.get(i));
|
||
203 | } |
||
204 | 2183 | fernando | } |
205 | |||
206 | //Asigna las bandas
|
||
207 | 2372 | igbrotru | if(bandR==-1)bandR=0; |
208 | if(bandG==-1)bandG=0; |
||
209 | if(bandB==-1)bandB=0; |
||
210 | 2623 | nacho | layer.setBand(GeoRasterFile.RED_BAND, bandR); |
211 | layer.setBand(GeoRasterFile.GREEN_BAND, bandG); |
||
212 | layer.setBand(GeoRasterFile.BLUE_BAND, bandB); |
||
213 | 2378 | igbrotru | |
214 | //Asigna la transparencia
|
||
215 | if(transparency!=255) |
||
216 | layer.setTransparency(transparency); |
||
217 | 4163 | nacho | |
218 | //Crea la pila de filtros a partir de las propiedades recuperadas desde el XML
|
||
219 | if(layer.getFilterStack() != null){ |
||
220 | RasterFilterStackManager stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
||
221 | if(this.isPansharpInStack) |
||
222 | stackManager.createStackFromStrings(this.filters, ((FLyrRaster)layer).getSource().getFiles());
|
||
223 | else
|
||
224 | stackManager.createStackFromStrings(this.filters);
|
||
225 | } |
||
226 | |||
227 | 2183 | fernando | } |
228 | } |