Revision 13074
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/StatusRasterInterface.java | ||
---|---|---|
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 com.iver.utiles.XMLEntity; |
|
46 |
|
|
47 |
public interface StatusRasterInterface{ |
|
48 |
|
|
49 |
/** |
|
50 |
* Recupera en fichero XML algunas propiedades y filtros del raster |
|
51 |
* @param xml |
|
52 |
* @throws XMLException |
|
53 |
*/ |
|
54 |
public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException; |
|
55 |
|
|
56 |
/** |
|
57 |
* Salva en fichero XML algunas propiedades y filtros de raster |
|
58 |
* @param xml |
|
59 |
* @throws XMLException |
|
60 |
*/ |
|
61 |
public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer)throws XMLException; |
|
62 |
|
|
63 |
/** |
|
64 |
* Aplica el estado almacenado al FLyrRaster pasado por par?metro |
|
65 |
* @param adapter |
|
66 |
*/ |
|
67 |
public void applyStatus(RasterOperations layer); |
|
68 |
|
|
69 |
/** |
|
70 |
* Obtiene el listado de filtros para poder montar una pila |
|
71 |
* despu?s de la recuperaci?n desde el XML |
|
72 |
* @return |
|
73 |
*/ |
|
74 |
public ArrayList getFilters(); |
|
75 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrRaster.java | ||
---|---|---|
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.awt.Dimension; |
|
44 |
import java.awt.Graphics2D; |
|
45 |
import java.awt.Point; |
|
46 |
import java.awt.Rectangle; |
|
47 |
import java.awt.geom.AffineTransform; |
|
48 |
import java.awt.geom.NoninvertibleTransformException; |
|
49 |
import java.awt.geom.Point2D; |
|
50 |
import java.awt.geom.Rectangle2D; |
|
51 |
import java.awt.image.BufferedImage; |
|
52 |
import java.io.File; |
|
53 |
import java.lang.reflect.Constructor; |
|
54 |
import java.lang.reflect.InvocationTargetException; |
|
55 |
import java.util.ArrayList; |
|
56 |
|
|
57 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
58 |
import javax.swing.ImageIcon; |
|
59 |
|
|
60 |
import org.cresques.cts.IProjection; |
|
61 |
import org.cresques.filter.RasterFilterStack; |
|
62 |
import org.cresques.filter.RasterStats; |
|
63 |
import org.cresques.px.Extent; |
|
64 |
|
|
65 |
import com.hardcode.driverManager.Driver; |
|
66 |
import com.hardcode.driverManager.DriverLoadException; |
|
67 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
68 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
|
69 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
|
70 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
71 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
72 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
73 |
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver; |
|
74 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
|
75 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
|
76 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
|
77 |
import com.iver.utiles.XMLEntity; |
|
78 |
import com.iver.utiles.swing.threads.Cancellable; |
|
79 |
|
|
80 |
|
|
81 |
/** |
|
82 |
* Clase b?sica de capa raster. |
|
83 |
* |
|
84 |
* @author Vicente Caballero Navarro |
|
85 |
*/ |
|
86 |
public class FLyrRaster extends FLyrDefault implements RasterOperations { |
|
87 |
private RasterAdapter source; |
|
88 |
boolean isPrinting = false; |
|
89 |
boolean mustTileDraw = false; |
|
90 |
boolean mustTilePrint = true; |
|
91 |
private int maxTileDrawWidth = 200; |
|
92 |
private int maxTileDrawHeight = 200; |
|
93 |
int maxTilePrintWidth = 1500; |
|
94 |
int maxTilePrintHeight = 1500; |
|
95 |
private StatusRasterInterface status = null; |
|
96 |
private boolean firstLoad = false; |
|
97 |
private int posX = 0, posY = 0; |
|
98 |
private double posXWC = 0, posYWC = 0; |
|
99 |
private int r = 0, g = 0, b = 0; |
|
100 |
private boolean removeRasterFlag = true; |
|
101 |
|
|
102 |
/** |
|
103 |
* Devuelve el RasterAdapter de la capa. |
|
104 |
* |
|
105 |
* @return RasterAdapter. |
|
106 |
*/ |
|
107 |
public RasterAdapter getSource() { |
|
108 |
return source; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
*Redefine wakeUp de FLyrDefault |
|
113 |
*/ |
|
114 |
public void wakeUp(){ |
|
115 |
/*setName(getName()); |
|
116 |
setProjection(getProjection()); |
|
117 |
try { |
|
118 |
load(); |
|
119 |
} catch (DriverIOException e) { |
|
120 |
e.printStackTrace(); |
|
121 |
}*/ |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Inserta el RasterAdapter. |
|
126 |
* |
|
127 |
* @param ra RasterAdapter. |
|
128 |
*/ |
|
129 |
public void setSource(RasterAdapter ra) { |
|
130 |
source = ra; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Devuelve la pila de filtros aplicada sobre la capa raster. |
|
135 |
* |
|
136 |
* @return RasterFilterStack. |
|
137 |
*/ |
|
138 |
public RasterFilterStack getFilterStack(){ |
|
139 |
return source.getFilterStack(); |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Asignar el estado del raster |
|
144 |
* @param status |
|
145 |
*/ |
|
146 |
public void setStatus(StatusRasterInterface status){ |
|
147 |
this.status = status; |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Asigna la pila de filtros aplicada al raster |
|
152 |
* @return |
|
153 |
*/ |
|
154 |
public void setFilterStack(RasterFilterStack stack){ |
|
155 |
source.setFilterStack(stack); |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Obtiene el estado del raster |
|
160 |
* @return |
|
161 |
*/ |
|
162 |
public StatusRasterInterface getStatus(){ |
|
163 |
return this.status; |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Asigna la posici?n en la que se ha hecho click al mostrar |
|
168 |
* informaci?n del raster. |
|
169 |
* @param x Posici?n en X |
|
170 |
* @param y Posici?n en Y |
|
171 |
*/ |
|
172 |
public void setPos(int x, int y){ |
|
173 |
this.posX = x; |
|
174 |
this.posY = y; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Asigna la posici?n en coordenadas del mundo real en la que se ha |
|
179 |
* hecho click al mostrar informaci?n del raster. |
|
180 |
* @param x Posici?n en X |
|
181 |
* @param y Posici?n en Y |
|
182 |
*/ |
|
183 |
public void setPosWC(double x, double y){ |
|
184 |
this.posXWC = x; |
|
185 |
this.posYWC = y; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Asigna RGB en la posici?n en la que se ha |
|
190 |
* hecho click al mostrar informaci?n del raster. |
|
191 |
* @param r valor de rojo |
|
192 |
* @param g valor de verde |
|
193 |
* @param b valor de azul |
|
194 |
*/ |
|
195 |
public void setRGB(int r, int g, int b){ |
|
196 |
this.r = r; |
|
197 |
this.g = g; |
|
198 |
this.b = b; |
|
199 |
} |
|
200 |
|
|
201 |
/* |
|
202 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load() |
|
203 |
*/ |
|
204 |
public void load() throws LoadLayerException { |
|
205 |
((RasterFileAdapter) source).start(); |
|
206 |
((RasterFileAdapter) source).setTransparency(getTransparency()); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage, |
|
211 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, |
|
212 |
* com.iver.utiles.swing.threads.Cancellable) |
|
213 |
*/ |
|
214 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
|
215 |
Cancellable cancel,double scale) throws ReadDriverException { |
|
216 |
if (isWithinScale(scale)){ |
|
217 |
try { |
|
218 |
if(status!=null && firstLoad){ |
|
219 |
if(mustTileDraw){ |
|
220 |
Point2D p = vp.getOffset(); |
|
221 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
|
222 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r); |
|
223 |
tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone()); |
|
224 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
|
225 |
// drawing part |
|
226 |
try { |
|
227 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
|
228 |
//g.setClip(tiles.getClip(tileNr).x, tiles.getClip(tileNr).y, tiles.getClip(tileNr).width - 5, tiles.getClip(tileNr).height); |
|
229 |
((RasterFileAdapter) source).draw(image, g, vport, cancel); |
|
230 |
} catch (NoninvertibleTransformException e) { |
|
231 |
e.printStackTrace(); |
|
232 |
} |
|
233 |
} |
|
234 |
}else |
|
235 |
((RasterFileAdapter) source).draw(image, g, vp, cancel); |
|
236 |
status.applyStatus(this); |
|
237 |
firstLoad = false; |
|
238 |
} |
|
239 |
|
|
240 |
if(mustTileDraw){ |
|
241 |
Point2D p = vp.getOffset(); |
|
242 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
|
243 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r); |
|
244 |
tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone()); |
|
245 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
|
246 |
// drawing part |
|
247 |
try { |
|
248 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
|
249 |
((RasterFileAdapter) source).draw(image, g, vport, cancel); |
|
250 |
} catch (NoninvertibleTransformException e) { |
|
251 |
e.printStackTrace(); |
|
252 |
} |
|
253 |
} |
|
254 |
}else |
|
255 |
((RasterFileAdapter) source).draw(image, g, vp, cancel); |
|
256 |
|
|
257 |
} catch (DriverIOException e) { |
|
258 |
throw new ReadDriverException(getName(),e); |
|
259 |
} |
|
260 |
|
|
261 |
if (getVirtualLayers() != null) { |
|
262 |
getVirtualLayers().draw(image, g, vp, cancel,scale); |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Inserta la proyecci?n. |
|
269 |
* |
|
270 |
* @param proj Proyecci?n. |
|
271 |
*/ |
|
272 |
public void setProjection(IProjection proj) { |
|
273 |
super.setProjection(proj); |
|
274 |
|
|
275 |
if (source != null && source.getDriver() != null && source.getDriver() instanceof GeorreferencedRasterDriver) { |
|
276 |
GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver(); |
|
277 |
|
|
278 |
if (geoDrv.getProjection() == null) { |
|
279 |
geoDrv.setProjection(proj); |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
public void setTransparency(int trans) { |
|
285 |
super.setTransparency(trans); |
|
286 |
((RasterFileAdapter) source).setTransparency(trans); |
|
287 |
if (getMapContext() != null){ |
|
288 |
getMapContext().invalidate(); |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
292 |
public int getTransparency() { |
|
293 |
return ((RasterFileAdapter) source).getTransparency(); |
|
294 |
} |
|
295 |
|
|
296 |
/* |
|
297 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent() |
|
298 |
*/ |
|
299 |
public Rectangle2D getFullExtent() { |
|
300 |
return ((RasterFileAdapter) source).getFullExtent(); |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Obtiene el valor del pixel del Image en la posici?n x,y |
|
305 |
* @param x Posici?n x |
|
306 |
* @param y Posici?n y |
|
307 |
* @return valor de pixel |
|
308 |
*/ |
|
309 |
public int[] getPixel(double wcx, double wcy){ |
|
310 |
return ((RasterFileAdapter) source).getPixel(wcx, wcy); |
|
311 |
} |
|
312 |
|
|
313 |
public double getMaxX(){ |
|
314 |
return this.getFullExtent().getMaxX(); |
|
315 |
} |
|
316 |
|
|
317 |
public double getMaxY(){ |
|
318 |
return this.getFullExtent().getMaxY(); |
|
319 |
} |
|
320 |
|
|
321 |
public double getMinX(){ |
|
322 |
return this.getFullExtent().getMinX(); |
|
323 |
} |
|
324 |
|
|
325 |
public double getMinY(){ |
|
326 |
return this.getFullExtent().getMinY(); |
|
327 |
} |
|
328 |
|
|
329 |
public double getHeight(){ |
|
330 |
return this.getFullExtent().getHeight(); |
|
331 |
} |
|
332 |
|
|
333 |
public double getWidth(){ |
|
334 |
return this.getFullExtent().getWidth(); |
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
/* (non-Javadoc) |
|
339 |
* @deprecated. See String getInfo(Point p) throws DriverException |
|
340 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point) |
|
341 |
*/ |
|
342 |
public String queryByPoint(Point p) throws ReadDriverException { |
|
343 |
String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
|
344 |
|
|
345 |
ArrayList attr = source.getAttributes(); |
|
346 |
data += " <raster\n"; |
|
347 |
data += " File=\""+((RasterFileAdapter) source).getFile()+"\"\n"; |
|
348 |
for (int i=0; i<attr.size(); i++) { |
|
349 |
Object [] a = (Object []) attr.get(i); |
|
350 |
|
|
351 |
data += " "+a[0].toString()+"="; |
|
352 |
if (a[1].toString() instanceof String) |
|
353 |
data += "\""+a[1].toString()+"\"\n"; |
|
354 |
else |
|
355 |
data += a[1].toString()+"\n"; |
|
356 |
} |
|
357 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
|
358 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
|
359 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
|
360 |
data += " />\n"; |
|
361 |
|
|
362 |
data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
|
363 |
//System.out.println(data); |
|
364 |
return data; |
|
365 |
} |
|
366 |
|
|
367 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException { |
|
368 |
|
|
369 |
Point2D pReal = getMapContext().getViewPort().toMapPoint(p); |
|
370 |
Point2D px = null; |
|
371 |
if( pReal.getX() > this.getMinX() && |
|
372 |
pReal.getX() < this.getMaxX() && |
|
373 |
pReal.getY() > this.getMinY() && |
|
374 |
pReal.getY() < this.getMaxY()){ |
|
375 |
ArrayList attr = source.getAttributes(); |
|
376 |
int w = 0, h = 0; |
|
377 |
for (int i=0; i<attr.size(); i++) { |
|
378 |
Object [] a = (Object []) attr.get(i); |
|
379 |
if(a[0].toString().equals("Width")) |
|
380 |
w = ((Integer)a[1]).intValue(); |
|
381 |
if(a[0].toString().equals("Height")) |
|
382 |
h = ((Integer)a[1]).intValue(); |
|
383 |
} |
|
384 |
px = new Point2D.Double(); |
|
385 |
px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWidth(), |
|
386 |
((this.getMaxY() - pReal.getY()) * h) / getHeight()); |
|
387 |
} |
|
388 |
|
|
389 |
int[] rgb = this.getPixel(pReal.getX(), pReal.getY()); |
|
390 |
|
|
391 |
StringXMLItem[] item = new StringXMLItem[1]; |
|
392 |
String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
|
393 |
|
|
394 |
data += " <raster\n"; |
|
395 |
data += " View_Point=\""+p.getX()+" , "+p.getY()+"\"\n"; |
|
396 |
data += " World_Point=\""+pReal.getX()+" , "+pReal.getY()+"\"\n"; |
|
397 |
if(px == null) |
|
398 |
data += " Pixel_Point=\"Out\"\n"; |
|
399 |
else |
|
400 |
data += " Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n"; |
|
401 |
|
|
402 |
if (rgb==null) |
|
403 |
data+=" RGB=\""+" "+" "+" "+" "+" "+"\"\n"; |
|
404 |
else { |
|
405 |
data += " RGB=\""+rgb[1]+" "+rgb[2]+" "+rgb[3]+"\"\n"; |
|
406 |
} |
|
407 |
|
|
408 |
data += " Band_Value=\""; |
|
409 |
if(this.getSource().getDataType() >= 0 && this.getSource().getDataType() <= 3){ |
|
410 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
|
411 |
data += ((Integer)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).intValue()+" "; |
|
412 |
} |
|
413 |
if(this.getSource().getDataType() >= 4){ |
|
414 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
|
415 |
data += ((Float)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).floatValue()+" "; |
|
416 |
} |
|
417 |
if(this.getSource().getDataType() >= 5){ |
|
418 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
|
419 |
data += ((Double)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).doubleValue()+" "; |
|
420 |
} |
|
421 |
data += "\"\n"; |
|
422 |
data += " />\n"; |
|
423 |
data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
|
424 |
|
|
425 |
item[0] = new StringXMLItem(data, this); |
|
426 |
return item; |
|
427 |
|
|
428 |
} |
|
429 |
|
|
430 |
/** |
|
431 |
* Filters a string for being suitable as XML Tag, erasing |
|
432 |
* all not alphabetic or numeric characters. |
|
433 |
* @param s |
|
434 |
* @return string normalized |
|
435 |
*/ |
|
436 |
public String normalizeAsXMLTag(String s) { |
|
437 |
return s.replaceAll("[^a-zA-Z0-9]",""); |
|
438 |
} |
|
439 |
|
|
440 |
/** |
|
441 |
* Obtiene atributos a partir de un georasterfile |
|
442 |
* @return |
|
443 |
*/ |
|
444 |
public ArrayList getAttributes() { |
|
445 |
return source.getAttributes(); |
|
446 |
} |
|
447 |
|
|
448 |
/** |
|
449 |
* @throws XMLException |
|
450 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties() |
|
451 |
*/ |
|
452 |
public XMLEntity getXMLEntity() throws XMLException { |
|
453 |
XMLEntity xml = super.getXMLEntity(); |
|
454 |
|
|
455 |
if (source instanceof RasterFileAdapter) { |
|
456 |
xml.putProperty("file", ((RasterFileAdapter) source).getFile()); |
|
457 |
} |
|
458 |
|
|
459 |
xml.putProperty("driverName", getSource().getDriver().getName()); |
|
460 |
|
|
461 |
//Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto |
|
462 |
if(status == null) |
|
463 |
status = new StatusLayerRaster(); |
|
464 |
|
|
465 |
status.getXMLEntity(xml, true, this); |
|
466 |
|
|
467 |
|
|
468 |
return xml; |
|
469 |
} |
|
470 |
|
|
471 |
public void setXMLEntity03(XMLEntity xml) |
|
472 |
throws XMLException { |
|
473 |
super.setXMLEntity(xml); |
|
474 |
try { |
|
475 |
Driver d = LayerFactory.getDM().getDriver( |
|
476 |
xml.getStringProperty("driverName")); |
|
477 |
File f = new File(xml.getStringProperty("file")); |
|
478 |
RasterAdapter adapter = new RasterFileAdapter(f); |
|
479 |
adapter.setDriver(d); |
|
480 |
setSource(adapter); |
|
481 |
// Para notificar al adapter-driver cual es la proyecci?n. |
|
482 |
setProjection(super.getProjection()); |
|
483 |
} catch (DriverLoadException e) { |
|
484 |
throw new XMLException(e); |
|
485 |
} |
|
486 |
} |
|
487 |
|
|
488 |
public void setXMLEntity(XMLEntity xml) |
|
489 |
throws XMLException { |
|
490 |
super.setXMLEntity(xml); |
|
491 |
try { |
|
492 |
Driver d = LayerFactory.getDM().getDriver( |
|
493 |
xml.getStringProperty("driverName")); |
|
494 |
File f = new File(xml.getStringProperty("file")); |
|
495 |
RasterAdapter adapter = new RasterFileAdapter(f); |
|
496 |
adapter.setDriver(d); |
|
497 |
setSource(adapter); |
|
498 |
// Para notificar al adapter-driver cual es la proyecci?n. |
|
499 |
setProjection(super.getProjection()); |
|
500 |
|
|
501 |
//Inicializamos la clase a la que se usa por defecto para |
|
502 |
//compatibilidad con proyectos antiguos |
|
503 |
String claseStr = StatusLayerRaster.defaultClass; |
|
504 |
if (xml.contains("raster.class")) { |
|
505 |
claseStr = xml.getStringProperty("raster.class"); |
|
506 |
} |
|
507 |
if(status!=null) |
|
508 |
status.setXMLEntity(xml, this); |
|
509 |
else{ |
|
510 |
|
|
511 |
//Cuando cargamos un proyecto |
|
512 |
|
|
513 |
if(claseStr!=null && !claseStr.equals("")){ |
|
514 |
try{ |
|
515 |
Class clase = Class.forName(claseStr); |
|
516 |
Constructor constr = clase.getConstructor(null); |
|
517 |
status = (StatusRasterInterface)constr.newInstance(null); |
|
518 |
if(status!=null) |
|
519 |
status.setXMLEntity(xml, this); |
|
520 |
}catch(ClassNotFoundException exc){ |
|
521 |
exc.printStackTrace(); |
|
522 |
}catch(InstantiationException exc){ |
|
523 |
exc.printStackTrace(); |
|
524 |
}catch(IllegalAccessException exc){ |
|
525 |
exc.printStackTrace(); |
|
526 |
}catch(NoSuchMethodException exc){ |
|
527 |
exc.printStackTrace(); |
|
528 |
}catch(InvocationTargetException exc){ |
|
529 |
exc.printStackTrace(); |
|
530 |
} |
|
531 |
} |
|
532 |
} |
|
533 |
firstLoad = true; |
|
534 |
|
|
535 |
|
|
536 |
} catch (DriverLoadException e) { |
|
537 |
throw new XMLException(e); |
|
538 |
} |
|
539 |
} |
|
540 |
|
|
541 |
/* (non-Javadoc) |
|
542 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable) |
|
543 |
*/ |
|
544 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties) |
|
545 |
throws ReadDriverException { |
|
546 |
|
|
547 |
if (isVisible() && isWithinScale(scale)){ |
|
548 |
isPrinting = true; |
|
549 |
if (!mustTilePrint) { |
|
550 |
draw(null, g, viewPort, cancel,scale); |
|
551 |
} else { |
|
552 |
// Para no pedir imagenes demasiado grandes, vamos |
|
553 |
// a hacer lo mismo que hace EcwFile: chunkear. |
|
554 |
// Llamamos a drawView con cuadraditos m?s peque?os |
|
555 |
// del BufferedImage ni caso, cuando se imprime viene con null |
|
556 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds()); |
|
557 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone()); |
|
558 |
|
|
559 |
//Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n |
|
560 |
//de realce si la imagen es de 16 bits. |
|
561 |
|
|
562 |
RasterStats stats = getSource().getFilterStack().getStats(); |
|
563 |
if(stats != null) |
|
564 |
stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue)); |
|
565 |
|
|
566 |
|
|
567 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
|
568 |
// Parte que dibuja |
|
569 |
try { |
|
570 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
|
571 |
draw(null, g, vp, cancel,scale); |
|
572 |
} catch (NoninvertibleTransformException e) { |
|
573 |
// TODO Auto-generated catch block |
|
574 |
e.printStackTrace(); |
|
575 |
} |
|
576 |
} |
|
577 |
|
|
578 |
if(stats != null){ |
|
579 |
getSource().getFilterStack().getStats().history.clear(); |
|
580 |
stats = getSource().getFilterStack().getStats(); |
|
581 |
} |
|
582 |
|
|
583 |
} |
|
584 |
isPrinting = false; |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
588 |
public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
|
589 |
throws ReadDriverException { |
|
590 |
// Para no pedir imagenes demasiado grandes, vamos |
|
591 |
// a hacer lo mismo que hace EcwFile: chunkear. |
|
592 |
// Llamamos a drawView con cuadraditos m?s peque?os |
|
593 |
// del BufferedImage ni caso, cuando se imprime viene con null |
|
594 |
|
|
595 |
int numW, numH; |
|
596 |
int stepX, stepY; |
|
597 |
int xProv, yProv, wProv, hProv; |
|
598 |
double xProvD, yProvD, wProvD, hProvD; |
|
599 |
int A = 1500; |
|
600 |
int H = 1500; |
|
601 |
int altoAux, anchoAux; |
|
602 |
|
|
603 |
AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone(); |
|
604 |
|
|
605 |
// Vamos a hacerlo en trozos de AxH |
|
606 |
Rectangle r = g.getClipBounds(); |
|
607 |
numW = (int) (r.width) / A; |
|
608 |
numH = (int) (r.height) / H; |
|
609 |
|
|
610 |
|
|
611 |
double[] srcPts = new double[8]; |
|
612 |
double[] dstPts= new double[8]; |
|
613 |
|
|
614 |
yProv = (int) r.y; |
|
615 |
for (stepY=0; stepY < numH+1; stepY++) |
|
616 |
{ |
|
617 |
if ((yProv + H) > r.getMaxY()) |
|
618 |
altoAux = (int) r.getMaxY() - yProv; |
|
619 |
else |
|
620 |
altoAux = H; |
|
621 |
|
|
622 |
xProv = (int) r.x; |
|
623 |
for (stepX=0; stepX < numW+1; stepX++) |
|
624 |
{ |
|
625 |
if ((xProv + A) > r.getMaxX()) |
|
626 |
anchoAux = (int) r.getMaxX() - xProv; |
|
627 |
else |
|
628 |
anchoAux = A; |
|
629 |
|
|
630 |
Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux); |
|
631 |
|
|
632 |
// Parte que dibuja |
|
633 |
srcPts[0] = xProv; |
|
634 |
srcPts[1] = yProv; |
|
635 |
srcPts[2] = xProv + anchoAux+1; |
|
636 |
srcPts[3] = yProv; |
|
637 |
srcPts[4] = xProv + anchoAux+1; |
|
638 |
srcPts[5] = yProv + altoAux+1; |
|
639 |
srcPts[6] = xProv; |
|
640 |
srcPts[7] = yProv + altoAux+1; |
|
641 |
|
|
642 |
try { |
|
643 |
mat.inverseTransform(srcPts, 0, dstPts, 0, 4); |
|
644 |
Rectangle2D.Double rectCuadricula = new Rectangle2D.Double( |
|
645 |
dstPts[0], dstPts[1], |
|
646 |
dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]); |
|
647 |
Extent extent = new Extent(rectCuadricula); |
|
648 |
|
|
649 |
Dimension tam = new Dimension(anchoAux+1, altoAux+1); |
|
650 |
ViewPort vp = viewPort.cloneViewPort(); |
|
651 |
vp.setImageSize(tam); |
|
652 |
vp.setExtent(rectCuadricula); |
|
653 |
vp.setAffineTransform(mat); |
|
654 |
// ViewPortData vp = new ViewPortData(getProjection(), extent, tam); |
|
655 |
// vp.setMat(mat); |
|
656 |
// rasterList.draw(g2, vp); |
|
657 |
|
|
658 |
/*System.out.println("FLyrRaster.print(): fila "+stepX+" de " |
|
659 |
+ numW + " , col "+stepY+" de " + numH + |
|
660 |
"\n, Extent = "+vp.getExtent() + " imageSize: " |
|
661 |
+ tam);*/ |
|
662 |
draw(null, g, vp, cancel,scale); |
|
663 |
|
|
664 |
} catch (NoninvertibleTransformException e) { |
|
665 |
// TODO Auto-generated catch block |
|
666 |
e.printStackTrace(); |
|
667 |
} |
|
668 |
// Fin parte que dibuja |
|
669 |
xProv = xProv + A; |
|
670 |
} |
|
671 |
yProv = yProv + H; |
|
672 |
} |
|
673 |
|
|
674 |
} |
|
675 |
|
|
676 |
/** |
|
677 |
* A?ade un fichero a la capa raster |
|
678 |
* @param fileName Nombre del fichero |
|
679 |
*/ |
|
680 |
public void addFiles(String fileName){ |
|
681 |
((RasterFileAdapter) source).addFile(fileName); |
|
682 |
} |
|
683 |
|
|
684 |
/** |
|
685 |
* Elimina un fichero a la capa raster |
|
686 |
* @param fileName Nombre del fichero |
|
687 |
*/ |
|
688 |
public void delFile(String fileName){ |
|
689 |
((RasterFileAdapter) source).delFile(fileName); |
|
690 |
} |
|
691 |
|
|
692 |
/* (non-Javadoc) |
|
693 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int) |
|
694 |
*/ |
|
695 |
public void setBand(int flag, int nBand) { |
|
696 |
this.getSource().setBand(flag, nBand); |
|
697 |
} |
|
698 |
|
|
699 |
/** |
|
700 |
* Borra de la lista de listeners el que se pasa como par?metro. |
|
701 |
* |
|
702 |
* @param o LayerListener a borrar. |
|
703 |
* |
|
704 |
* @return True si ha sido correcto el borrado del Listener. |
|
705 |
*/ |
|
706 |
public boolean removeLayerListener(LayerListener o) { |
|
707 |
if(this.isRemoveRasterFlag()){ |
|
708 |
/*try{ |
|
709 |
((RasterFileAdapter) source).stop(); |
|
710 |
}catch(DriverIOException exc){ |
|
711 |
|
|
712 |
}*/ |
|
713 |
this.setRemoveRasterFlag(true); |
|
714 |
} |
|
715 |
return super.layerListeners.remove(o); |
|
716 |
} |
|
717 |
|
|
718 |
/** |
|
719 |
* @return Returns the removeRasterFlag. |
|
720 |
*/ |
|
721 |
public boolean isRemoveRasterFlag() { |
|
722 |
return removeRasterFlag; |
|
723 |
} |
|
724 |
|
|
725 |
/** |
|
726 |
* Asigna el valor del flag que dice si destruimos la memoria del raster |
|
727 |
* al eliminarlo del TOC o no. |
|
728 |
* @param removeRasterFlag The removeRasterFlag to set. |
|
729 |
*/ |
|
730 |
public void setRemoveRasterFlag(boolean removeRasterFlag) { |
|
731 |
this.removeRasterFlag = removeRasterFlag; |
|
732 |
} |
|
733 |
|
|
734 |
public ImageIcon getTocImageIcon() { |
|
735 |
return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG")); |
|
736 |
} |
|
737 |
|
|
738 |
/* |
|
739 |
* (non-Javadoc) |
|
740 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize() |
|
741 |
*/ |
|
742 |
public int[] getTileSize() { |
|
743 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
|
744 |
return size; |
|
745 |
} |
|
746 |
|
|
747 |
/* |
|
748 |
* (non-Javadoc) |
|
749 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled() |
|
750 |
*/ |
|
751 |
public boolean isTiled() { |
|
752 |
return mustTileDraw; |
|
753 |
} |
|
754 |
|
|
755 |
/** |
|
756 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada |
|
757 |
* @return true si est? georreferenciada y false si no lo est?. |
|
758 |
*/ |
|
759 |
public boolean isGeoreferenced() { |
|
760 |
return getSource().isGeoreferenced(); |
|
761 |
} |
|
762 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/StatusLayerRaster.java | ||
---|---|---|
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 |
|
52 |
* de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a |
|
53 |
* un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y |
|
54 |
* getXMLEntity |
|
55 |
* |
|
56 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
57 |
*/ |
|
58 |
public class StatusLayerRaster implements StatusRasterInterface{ |
|
59 |
|
|
60 |
public static String defaultClass = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
|
61 |
|
|
62 |
//Valor de opacidad global de la imagen |
|
63 |
public int transparency = 0; |
|
64 |
|
|
65 |
//(Selecci?n de bandas)N?mero de banda asignado al Rojo, verde y azul |
|
66 |
public int bandR = 0; |
|
67 |
public int bandG = 1; |
|
68 |
public int bandB = 2; |
|
69 |
|
|
70 |
//Ficheros cargados en un PxRaster |
|
71 |
public ArrayList files = new ArrayList(); |
|
72 |
|
|
73 |
//Filtros para poder montar una nueva pila |
|
74 |
public ArrayList filters = new ArrayList(); |
|
75 |
|
|
76 |
/* (non-Javadoc) |
|
77 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity) |
|
78 |
*/ |
|
79 |
public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException { |
|
80 |
|
|
81 |
//Recuperamos las propiedades de los filtros |
|
82 |
for(int i=0;i<xml.getPropertyCount();i++){ |
|
83 |
if(xml.getPropertyName(i).startsWith("filter.")) |
|
84 |
filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i)); |
|
85 |
} |
|
86 |
|
|
87 |
if (xml.contains("raster.opacityLevel")) { |
|
88 |
transparency = xml.getIntProperty("raster.opacityLevel"); |
|
89 |
} |
|
90 |
if (xml.contains("raster.bandR")) { |
|
91 |
bandR = xml.getIntProperty("raster.bandR"); |
|
92 |
} |
|
93 |
if (xml.contains("raster.bandG")) { |
|
94 |
bandG = xml.getIntProperty("raster.bandG"); |
|
95 |
} |
|
96 |
if (xml.contains("raster.bandB")) { |
|
97 |
bandB = xml.getIntProperty("raster.bandB"); |
|
98 |
} |
|
99 |
|
|
100 |
int cont = 0; |
|
101 |
while(true && cont<50){ |
|
102 |
if (xml.contains("raster.file"+cont)) { |
|
103 |
files.add(xml.getStringProperty("raster.file"+cont)); |
|
104 |
cont++; |
|
105 |
}else |
|
106 |
break; |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/* (non-Javadoc) |
|
112 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity) |
|
113 |
*/ |
|
114 |
public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer) throws XMLException { |
|
115 |
|
|
116 |
if(loadClass) |
|
117 |
xml.putProperty("raster.class", StatusLayerRaster.defaultClass); |
|
118 |
|
|
119 |
if(transparency!=255) |
|
120 |
xml.putProperty("raster.opacityLevel", ""+transparency); |
|
121 |
|
|
122 |
xml.putProperty("raster.bandR", ""+bandR); |
|
123 |
xml.putProperty("raster.bandG", ""+bandG); |
|
124 |
xml.putProperty("raster.bandB", ""+bandB); |
|
125 |
|
|
126 |
|
|
127 |
if(files!=null && files.size()!=0){ |
|
128 |
for(int i=0;i<files.size();i++) |
|
129 |
xml.putProperty("raster.file"+i, ""+((String)files.get(i))); |
|
130 |
} |
|
131 |
|
|
132 |
//Salvamos la pila de filtros. |
|
133 |
//Si la pila es null (esto puede ocurrir cuando se abre un |
|
134 |
//proyecto que tiene WCS y no se abre la vista de este) entonces hay que leer los filtros |
|
135 |
//que van a salvarse a disco directamente de la variable filters que es la que se ha cargado |
|
136 |
//al hacer el setXMLEntity. |
|
137 |
|
|
138 |
RasterFilterStackManager stackManager = null; |
|
139 |
ArrayList l = null; |
|
140 |
if(layer.getFilterStack()!=null){ |
|
141 |
stackManager = new RasterFilterStackManager(layer.getFilterStack()); |
|
142 |
l = stackManager.getStringsFromStack(); |
|
143 |
if(l == null || l.size() == 0) |
|
144 |
l = filters; |
|
145 |
}else |
|
146 |
l = filters; |
|
147 |
|
|
148 |
for(int i=0;i<l.size();i++) |
|
149 |
xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Obtiene el valor de una cadena de la forma elemento=valor |
|
154 |
* @param cadena |
|
155 |
* @return |
|
156 |
*/ |
|
157 |
private String getValue(String cadena){ |
|
158 |
if(cadena!=null) |
|
159 |
return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
|
160 |
else |
|
161 |
return null; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Obtiene el elemento de una cadena de la forma elemento=valor |
|
166 |
* @param cadena |
|
167 |
* @return |
|
168 |
*/ |
|
169 |
private String getElem(String cadena){ |
|
170 |
if(cadena!=null) |
|
171 |
return cadena.substring(0, cadena.indexOf("=")); |
|
172 |
else |
|
173 |
return null; |
|
174 |
} |
|
175 |
|
|
176 |
/* (non-Javadoc) |
|
177 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters() |
|
178 |
*/ |
|
179 |
public ArrayList getFilters(){ |
|
180 |
return this.filters; |
|
181 |
} |
|
182 |
|
|
183 |
|
|
184 |
/* (non-Javadoc) |
|
185 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter) |
|
186 |
*/ |
|
187 |
public void applyStatus(RasterOperations layer){ |
|
188 |
|
|
189 |
//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen |
|
190 |
//en el orden correcto |
|
191 |
if(layer instanceof FLyrRaster){ |
|
192 |
if(files.size()!=0){ |
|
193 |
((FLyrRaster)layer).delFile((String)files.get(0)); |
|
194 |
for(int i=0;i<files.size();i++) |
|
195 |
((FLyrRaster)layer).addFiles((String)files.get(i)); |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
//Asigna las bandas |
|
200 |
if(bandR==-1)bandR=0; |
|
201 |
if(bandG==-1)bandG=0; |
|
202 |
if(bandB==-1)bandB=0; |
|
203 |
layer.setBand(GeoRasterFile.RED_BAND, bandR); |
|
204 |
layer.setBand(GeoRasterFile.GREEN_BAND, bandG); |
|
205 |
layer.setBand(GeoRasterFile.BLUE_BAND, bandB); |
|
206 |
|
|
207 |
//Asigna la transparencia |
|
208 |
if(transparency != 255) |
|
209 |
layer.setTransparency(transparency); |
|
210 |
|
|
211 |
//Crea la pila de filtros a partir de las propiedades recuperadas desde el XML |
|
212 |
if(layer.getFilterStack() != null){ |
|
213 |
RasterFilterStackManager stackManager = new RasterFilterStackManager(layer.getFilterStack()); |
|
214 |
if(layer instanceof FLyrRaster) |
|
215 |
stackManager.createStackFromStrings(this.filters, ((FLyrRaster)layer).getSource().getFiles()); |
|
216 |
else |
|
217 |
stackManager.createStackFromStrings(this.filters, new Integer(0)); |
|
218 |
} |
|
219 |
|
|
220 |
} |
|
221 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/RasterAdapter.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 20-dic-2004 |
|
3 |
*/ |
|
4 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
package com.iver.cit.gvsig.fmap.layers; |
|
45 |
|
|
46 |
import java.awt.Dimension; |
|
47 |
import java.awt.Graphics2D; |
|
48 |
import java.awt.Image; |
|
49 |
import java.awt.geom.Rectangle2D; |
|
50 |
import java.awt.image.BufferedImage; |
|
51 |
import java.util.ArrayList; |
|
52 |
|
|
53 |
import org.cresques.cts.ICoordTrans; |
|
54 |
import org.cresques.filter.RasterFilterStack; |
|
55 |
import org.cresques.io.GeoRasterFile; |
|
56 |
|
|
57 |
import com.hardcode.driverManager.Driver; |
|
58 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
59 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
|
60 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
61 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
|
62 |
import com.iver.utiles.swing.threads.Cancellable; |
|
63 |
|
|
64 |
/** |
|
65 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
|
66 |
*/ |
|
67 |
public class RasterAdapter { |
|
68 |
private boolean driverInitialized = false; |
|
69 |
private RasterDriver driver; |
|
70 |
|
|
71 |
/** |
|
72 |
* Establece el driver sobre el que act?a el adaptador |
|
73 |
*/ |
|
74 |
public void setDriver(Driver driver) { |
|
75 |
this.driver = (RasterDriver) driver; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Obtiene una referencia al objeto que implementa la interfaz vectorial con |
|
80 |
* el fin de que las Strategy puedan optimizar en funci?n del driver. |
|
81 |
*/ |
|
82 |
public Driver getDriver(){ |
|
83 |
return driver; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Obtiene una imagen de tama?o especificado, de la zona (en |
|
88 |
* coordenadas de usuario) que se le pide. |
|
89 |
* @param size Tama?o (en p?xeles de im?gen). |
|
90 |
* @param userSize Zona especificada (en coordenadas de usuario). |
|
91 |
* @param rp Reproyecci?n. |
|
92 |
* @return La imagen. |
|
93 |
*/ |
|
94 |
public Image getImage(Dimension size, Rectangle2D userSize, ICoordTrans rp) { |
|
95 |
return ((RasterDriver) driver).getImage(size, userSize, rp); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Obtiene el valor de transparencia |
|
100 |
* @return entero que representa el valor de transparencia |
|
101 |
*/ |
|
102 |
public int getTransparency() { |
|
103 |
return ((RasterDriver) driver).getTransparency(); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Asigna el valor de transparencia |
|
108 |
* @param trans entero que representa el valor de transparencia |
|
109 |
*/ |
|
110 |
public void setTransparency(int trans) { |
|
111 |
((RasterDriver) driver).setTransparency(trans); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage, ISymbol) |
|
116 |
*/ |
|
117 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverIOException { |
|
118 |
((RasterDriver) driver).draw(image,g, vp); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Obtiene la lista de atributos de raster |
|
123 |
* @return lista de atributos. Cada elmento de la lista es un array Object |
|
124 |
* con dos elementos. El primero el nombre del atributo y el segundo el valor |
|
125 |
* del mismo. |
|
126 |
*/ |
|
127 |
public ArrayList getAttributes() { |
|
128 |
return ((RasterDriver) driver).getAttributes(); |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Devuelve el colorBand activo en la banda especificada. |
|
133 |
* @param flag banda. |
|
134 |
* @return color de banda activo |
|
135 |
*/ |
|
136 |
public int getBand(int flag){ |
|
137 |
return ((RasterDriver) driver).getBand(flag); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* Devuelve la posici?n del fichero para la banda especificada. |
|
142 |
* @param flag banda. |
|
143 |
* @return posici?n del fichero |
|
144 |
*/ |
|
145 |
public int getPosFile(int flag){ |
|
146 |
return ((RasterDriver) driver).getPosFile(flag); |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* Activa o desactiva la transparencia |
|
151 |
* @param t true activa la transparencia y false la desactiva |
|
152 |
*/ |
|
153 |
public void setTransparency(boolean t){ |
|
154 |
((RasterDriver) driver).setTransparency(t); |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* Asocia un colorBand al rojo, verde o azul. |
|
159 |
* @param flag cual (o cuales) de las bandas. |
|
160 |
* @param nBand que colorBand |
|
161 |
*/ |
|
162 |
public void setBand(int flag, int nBand){ |
|
163 |
((RasterDriver) driver).setBand(flag, nBand); |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Obtiene el tipo de dato de la imagen |
|
168 |
* @return entero que representa el tipo de dato. La clase RasterBuf |
|
169 |
* tiene accesible de forma est?tica todos los tipos de datos permitidos |
|
170 |
*/ |
|
171 |
public int getDataType(){ |
|
172 |
return ((RasterDriver) driver).getRasterDataType(); |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Obtiene la pila de filtros |
|
177 |
* @return pila de filtros |
|
178 |
*/ |
|
179 |
public RasterFilterStack getFilterStack(){ |
|
180 |
return ((RasterDriver) driver).getFilterStack(); |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Asigna la pila de filtros |
|
185 |
* @param pila de filtros |
|
186 |
*/ |
|
187 |
public void setFilterStack(RasterFilterStack stack){ |
|
188 |
((RasterDriver) driver).setFilterStack(stack); |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* |
|
193 |
* @return |
|
194 |
*/ |
|
195 |
public GeoRasterFile[] getFiles(){ |
|
196 |
return ((RasterDriver) driver).getFiles(); |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Obtiene el n?mero de bandas de la imagen |
|
201 |
* @return n?mero de bandas |
|
202 |
*/ |
|
203 |
public int getNumBands(){ |
|
204 |
return ((RasterDriver)driver).getNumBands(); |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Obtiene el extent de la vista |
|
209 |
* @return extent |
|
210 |
*/ |
|
211 |
public Rectangle2D getFullExtent(){ |
|
212 |
return ((RasterDriver)driver).getFullExtent(); |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* Asigna un fichero al PxRaster |
|
217 |
* @param fileName Nombre del fichero |
|
218 |
*/ |
|
219 |
public void addFile(String fileName){ |
|
220 |
((RasterDriver)driver).addFile(fileName); |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Elimina un fichero al PxRaster |
|
225 |
* @param fileName Nombre del fichero |
|
226 |
*/ |
|
227 |
public void delFile(String fileName){ |
|
228 |
((RasterDriver)driver).delFile(fileName); |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Obtiene el valor del pixel del Image en la posici?n x,y |
|
233 |
* @param x Posici?n x |
|
234 |
* @param y Posici?n y |
|
235 |
* @return valor de pixel |
|
236 |
*/ |
|
237 |
public int[] getPixel(double wcx, double wcy){ |
|
238 |
return ((RasterDriver)driver).getPixel(wcx, wcy); |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada |
|
243 |
* @return true si est? georreferenciada y false si no lo est?. |
|
244 |
*/ |
|
245 |
public boolean isGeoreferenced() { |
|
246 |
return ((RasterDriver)driver).isGeoreferenced(); |
|
247 |
} |
|
248 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/RasterFileAdapter.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 20-dic-2004 |
|
3 |
*/ |
|
4 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
package com.iver.cit.gvsig.fmap.layers; |
|
45 |
|
|
46 |
import java.awt.geom.Rectangle2D; |
|
47 |
import java.io.File; |
|
48 |
import java.io.IOException; |
|
49 |
|
|
50 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
|
51 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
52 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* Adapta un driver de fichero vectorial a la interfaz vectorial, manteniendo |
|
57 |
* adem?s el estado necesario por una capa vectorial de fichero (el nombre del |
|
58 |
* fichero) |
|
59 |
*/ |
|
60 |
public class RasterFileAdapter extends RasterAdapter { |
|
61 |
private boolean driverInitialized = false; |
|
62 |
private File file; |
|
63 |
|
|
64 |
//private FileWriterDriver writeDriver; |
|
65 |
|
|
66 |
/** |
|
67 |
* Crea un nuevo VectorialFileAdapter. |
|
68 |
* |
|
69 |
* @param file Fichero. |
|
70 |
*/ |
|
71 |
public RasterFileAdapter(File file) { |
|
72 |
this.file = file; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Devuelve el Driver Raster. |
|
77 |
* |
|
78 |
* @return RasterDriver. |
|
79 |
*/ |
|
80 |
private RasterDriver getFileDriver() { |
|
81 |
return (RasterDriver) getDriver(); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* incrementa el contador de las veces que se ha abierto el fichero. |
|
86 |
* Solamente cuando el contador est? a cero pide al driver que abra el |
|
87 |
* fichero |
|
88 |
* @throws LoadLayerException TODO |
|
89 |
*/ |
|
90 |
public void start() throws LoadLayerException { |
|
91 |
try { |
|
92 |
getFileDriver().open(file); |
|
93 |
|
|
94 |
if (!driverInitialized) { |
|
95 |
getFileDriver().initialize(); |
|
96 |
driverInitialized = true; |
|
97 |
} |
|
98 |
} catch (IOException e) { |
|
99 |
throw new LoadLayerException(file.getName(),e); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* decrementa el contador de n?mero de aperturas y cuando llega a cero pide |
|
105 |
* al driver que cierre el fichero |
|
106 |
* |
|
107 |
* @throws DriverIOException |
|
108 |
*/ |
|
109 |
public void stop() throws DriverIOException { |
|
110 |
try { |
|
111 |
driverInitialized = false; |
|
112 |
getFileDriver().close(); |
|
113 |
} catch (IOException e) { |
|
114 |
throw new DriverIOException(e); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Devuelve el n?mero de bandas de raster. |
|
120 |
* |
|
121 |
* @return N?mero de bandas. |
|
122 |
*/ |
|
123 |
public int getNumBands() { |
|
124 |
return getFileDriver().getNumBands(); |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Devuelve la extensi?n total de la capa. |
|
129 |
* |
|
130 |
* @return Extensi?n total. |
|
131 |
*/ |
|
132 |
public Rectangle2D getFullExtent() { |
|
133 |
return getFileDriver().getFullExtent(); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType() |
|
138 |
*/ |
|
139 |
public int getRasterDataType() { |
|
140 |
return getFileDriver().getRasterDataType(); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Obtiene una muestra del pixel que se pasa como par?metro en la banda que |
|
145 |
* se pasa como par?metro |
|
146 |
* |
|
147 |
* @param x Coordenada X |
|
148 |
* @param y Coordenada Y |
|
149 |
* @param band N?mero de banda. |
|
150 |
* |
|
151 |
* @return Objeto. |
|
152 |
*/ |
|
153 |
public Object getData(int x, int y, int band) { |
|
154 |
return getFileDriver().getData(x, y, band); |
|
155 |
} |
Also available in: Unified diff