root / trunk / extensions / extRasterTools-SE / src / org / gvsig / fmap / layers / FLyrRasterSE.java @ 12284
History | View | Annotate | Download (31.2 KB)
1 | 10740 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 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 | package org.gvsig.fmap.layers; |
||
20 | |||
21 | import java.awt.Dimension; |
||
22 | import java.awt.Graphics2D; |
||
23 | import java.awt.Point; |
||
24 | import java.awt.Rectangle; |
||
25 | import java.awt.geom.AffineTransform; |
||
26 | import java.awt.geom.NoninvertibleTransformException; |
||
27 | import java.awt.geom.Point2D; |
||
28 | import java.awt.geom.Rectangle2D; |
||
29 | import java.awt.image.BufferedImage; |
||
30 | import java.io.File; |
||
31 | import java.io.IOException; |
||
32 | import java.lang.reflect.Constructor; |
||
33 | import java.lang.reflect.InvocationTargetException; |
||
34 | import java.util.ArrayList; |
||
35 | |||
36 | import javax.print.attribute.PrintRequestAttributeSet; |
||
37 | import javax.swing.ImageIcon; |
||
38 | |||
39 | import org.cresques.cts.IProjection; |
||
40 | 11647 | nacho | import org.gvsig.raster.RasterLibrary; |
41 | 11084 | nacho | import org.gvsig.raster.buffer.BufferFactory; |
42 | 11594 | nacho | import org.gvsig.raster.dataset.FileNotOpenException; |
43 | 11827 | nacho | import org.gvsig.raster.dataset.IBuffer; |
44 | 11594 | nacho | import org.gvsig.raster.dataset.InvalidSetViewException; |
45 | 11579 | nacho | import org.gvsig.raster.dataset.MultiRasterDataset; |
46 | 11647 | nacho | import org.gvsig.raster.dataset.NotSupportedExtensionException; |
47 | import org.gvsig.raster.dataset.RasterDataset; |
||
48 | 10940 | nacho | import org.gvsig.raster.dataset.RasterDriverException; |
49 | import org.gvsig.raster.dataset.properties.DatasetMetadata; |
||
50 | 11579 | nacho | import org.gvsig.raster.grid.Grid; |
51 | 12066 | nacho | import org.gvsig.raster.grid.GridPalette; |
52 | 10740 | nacho | import org.gvsig.raster.grid.GridTransparency; |
53 | import org.gvsig.raster.grid.filter.RasterFilterList; |
||
54 | 11827 | nacho | import org.gvsig.raster.grid.filter.RasterFilterListManager; |
55 | 12066 | nacho | import org.gvsig.raster.grid.filter.bands.ColorTableListManager; |
56 | 11827 | nacho | import org.gvsig.raster.grid.filter.enhancement.EnhancementListManager; |
57 | 10740 | nacho | import org.gvsig.raster.grid.render.Rendering; |
58 | import org.gvsig.raster.shared.Extent; |
||
59 | import org.gvsig.raster.shared.IRasterDataset; |
||
60 | import org.gvsig.raster.shared.IRasterProperties; |
||
61 | 12253 | nacho | import org.gvsig.raster.shared.IStatistics; |
62 | 11647 | nacho | import org.gvsig.raster.shared.ViewPortData; |
63 | 10740 | nacho | |
64 | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
||
65 | 11594 | nacho | import com.iver.andami.PluginServices; |
66 | 10740 | nacho | import com.iver.andami.messages.NotificationManager; |
67 | 12225 | nacho | import com.iver.andami.ui.mdiManager.IWindow; |
68 | 11647 | nacho | import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
69 | 10740 | nacho | import com.iver.cit.gvsig.fmap.MapControl; |
70 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
71 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
72 | import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
||
73 | import com.iver.cit.gvsig.fmap.layers.LayerListener; |
||
74 | import com.iver.cit.gvsig.fmap.layers.Tiling; |
||
75 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
76 | 11647 | nacho | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
77 | 10740 | nacho | import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
78 | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
||
79 | 11594 | nacho | import com.iver.cit.gvsig.project.documents.view.gui.IView; |
80 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
81 | 10740 | nacho | import com.iver.utiles.XMLEntity; |
82 | import com.iver.utiles.swing.threads.Cancellable; |
||
83 | /**
|
||
84 | 11647 | nacho | * Capa raster
|
85 | 10740 | nacho | * @author Nacho Brodin (nachobrodin@gmail.com)
|
86 | */
|
||
87 | 11647 | nacho | public class FLyrRasterSE extends FLyrDefault implements IRasterProperties, IRasterDataset, InfoByPoint { |
88 | 12108 | bsanchez | 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 boolean removeRasterFlag = true; |
||
98 | private Object params = null; |
||
99 | private MultiRasterDataset dataset = null; |
||
100 | private Rendering render = null; |
||
101 | private BufferFactory bufferFactory = null; |
||
102 | private int posX = 0; |
||
103 | private int posY = 0; |
||
104 | private double posXWC = 0; |
||
105 | private int posYWC = 0; |
||
106 | private int r = 0; |
||
107 | private int g = 0; |
||
108 | private int b = 0; |
||
109 | 10740 | nacho | |
110 | 12284 | bsanchez | |
111 | 11647 | nacho | static {
|
112 | RasterLibrary.wakeUp(); |
||
113 | } |
||
114 | 12050 | bsanchez | |
115 | 10740 | nacho | /**
|
116 | * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n.
|
||
117 | * @param layerName Nombre de la capa.
|
||
118 | * @param d RasterDriver.
|
||
119 | * @param f Fichero.
|
||
120 | * @param proj Proyecci?n.
|
||
121 | * @return Nueva capa de tipo raster.
|
||
122 | * @throws DriverIOException
|
||
123 | */
|
||
124 | 12050 | bsanchez | public static FLyrRasterSE createLayer(String layerName, Object params, |
125 | 11647 | nacho | IProjection proj) throws LoadLayerException {
|
126 | 10740 | nacho | FLyrRasterSE capa = new FLyrRasterSE();
|
127 | 11647 | nacho | capa.setLoadParams(params); |
128 | 10740 | nacho | capa.setName(layerName); |
129 | capa.setProjection(proj); |
||
130 | capa.load(); |
||
131 | return capa;
|
||
132 | } |
||
133 | 12050 | bsanchez | |
134 | 10740 | nacho | /**
|
135 | 11647 | nacho | * Asigna los par?metros para la carga de la capa
|
136 | * @param param Par?metros.
|
||
137 | 10740 | nacho | */
|
138 | 11647 | nacho | public void setLoadParams(Object param){ |
139 | this.params = param;
|
||
140 | 10740 | nacho | } |
141 | |||
142 | /**
|
||
143 | 12182 | nacho | * Obtiene los par?metros para la carga de la capa
|
144 | * @return param Par?metros.
|
||
145 | */
|
||
146 | public Object getLoadParams() { |
||
147 | return params;
|
||
148 | } |
||
149 | 12284 | bsanchez | |
150 | 12182 | nacho | /**
|
151 | 11647 | nacho | * Redefine wakeUp de FLyrDefault
|
152 | 10740 | nacho | */
|
153 | public void wakeUp(){ |
||
154 | } |
||
155 | |||
156 | /**
|
||
157 | * Asignar el estado del raster
|
||
158 | * @param status
|
||
159 | */
|
||
160 | public void setStatus(StatusRasterInterface status){ |
||
161 | this.status = status;
|
||
162 | } |
||
163 | |||
164 | /**
|
||
165 | * Obtiene el estado del raster
|
||
166 | * @return
|
||
167 | */
|
||
168 | public StatusRasterInterface getStatus(){
|
||
169 | return this.status; |
||
170 | } |
||
171 | |||
172 | 11647 | nacho | /*
|
173 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
||
174 | 10740 | nacho | */
|
175 | 11647 | nacho | public void load() throws LoadLayerException{ |
176 | if (getProjection() != null) { |
||
177 | String fName = null; |
||
178 | int test = -1; |
||
179 | 12068 | bsanchez | if (params != null && params instanceof File) { |
180 | fName = ((File) params).getAbsolutePath();
|
||
181 | 11647 | nacho | test = fName.indexOf("ecwp:");
|
182 | } |
||
183 | 10740 | nacho | |
184 | 11647 | nacho | if (test != -1) { |
185 | 12068 | bsanchez | String urlECW = fName.substring(test + 6); |
186 | fName = "ecwp://" + urlECW;
|
||
187 | 11647 | nacho | System.err.println(test + " " + fName); |
188 | 12068 | bsanchez | } |
189 | 12050 | bsanchez | |
190 | 11647 | nacho | try {
|
191 | 12068 | bsanchez | if (params == null || params instanceof File) |
192 | 11647 | nacho | dataset = MultiRasterDataset.open(getProjection(), fName); |
193 | 12050 | bsanchez | else
|
194 | 11777 | nacho | dataset = MultiRasterDataset.open(getProjection(), params); |
195 | 11647 | nacho | } catch (NotSupportedExtensionException e) {
|
196 | throw new LoadLayerException("Formato no valido", e); |
||
197 | } catch (RasterDriverException e) {
|
||
198 | throw new LoadLayerException("Formato no valido", e); |
||
199 | } |
||
200 | 12068 | bsanchez | if (dataset == null) |
201 | 11647 | nacho | throw new LoadLayerException("Formato no valido", new IOException()); |
202 | bufferFactory = new BufferFactory(dataset);
|
||
203 | 11675 | nacho | getRender(); |
204 | 11827 | nacho | initFilters(); |
205 | 11647 | nacho | } else
|
206 | throw new LoadLayerException("Proyecci?n no asignada", new IOException()); |
||
207 | 10740 | nacho | } |
208 | 12050 | bsanchez | |
209 | 10740 | nacho | /**
|
210 | 11647 | nacho | * Crea el objeto renderizador de raster
|
211 | 12284 | bsanchez | * @return Rendering
|
212 | 10740 | nacho | */
|
213 | 11675 | nacho | public Rendering getRender() {
|
214 | 12068 | bsanchez | if (render == null) |
215 | 11647 | nacho | render = new Rendering(bufferFactory);
|
216 | 12050 | bsanchez | return render;
|
217 | 10740 | nacho | } |
218 | 12050 | bsanchez | |
219 | 11827 | nacho | /**
|
220 | * Filtros a?adidos por defecto en la pila para visualizaci?n.
|
||
221 | */
|
||
222 | private void initFilters() { |
||
223 | RasterFilterList filterList = new RasterFilterList();
|
||
224 | filterList.addParam("IStatistics", getGeoRasterMultiDataset().getStatistics());
|
||
225 | filterList.addParam("MultiRasterDataset", getGeoRasterMultiDataset());
|
||
226 | filterList.setInitDataType(getDataType()[0]);
|
||
227 | 12066 | nacho | RasterFilterListManager filterManager = new RasterFilterListManager(filterList);
|
228 | 12068 | bsanchez | |
229 | 12225 | nacho | if (this.getGeoRasterMultiDataset().getColorTables()[0] != null) { |
230 | GridPalette p = new GridPalette(getGeoRasterMultiDataset().getColorTables()[0]); |
||
231 | 12066 | nacho | ColorTableListManager ctm = new ColorTableListManager(filterManager);
|
232 | 12166 | bsanchez | ctm.addColorTableFilter(p); |
233 | 12066 | nacho | } else {
|
234 | 12068 | bsanchez | if (getDataType()[0] != IBuffer.TYPE_BYTE) { |
235 | 12066 | nacho | IStatistics stats = getGeoRasterMultiDataset().getStatistics(); |
236 | EnhancementListManager elm = new EnhancementListManager(filterManager);
|
||
237 | 12166 | bsanchez | elm.addEnhancedFilter(false, stats, 0.0, getRender().getRenderBands()); |
238 | 12066 | nacho | } |
239 | 11827 | nacho | } |
240 | 12050 | bsanchez | |
241 | 11827 | nacho | getRender().setFilterList(filterList); |
242 | } |
||
243 | 10740 | nacho | |
244 | /**
|
||
245 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
||
246 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
||
247 | * com.iver.utiles.swing.threads.Cancellable)
|
||
248 | */
|
||
249 | 12068 | bsanchez | public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel, double scale) { |
250 | 11647 | nacho | if (isWithinScale(scale)) {
|
251 | 12050 | bsanchez | |
252 | 12068 | bsanchez | if (status != null && firstLoad) { |
253 | if (mustTileDraw) {
|
||
254 | 10740 | nacho | Point2D p = vp.getOffset();
|
255 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
||
256 | Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
||
257 | tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
||
258 | 12068 | bsanchez | for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
259 | 10740 | nacho | // drawing part
|
260 | try {
|
||
261 | ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
||
262 | 12068 | bsanchez | // g.setClip(tiles.getClip(tileNr).x, tiles.getClip(tileNr).y, tiles.getClip(tileNr).width - 5, tiles.getClip(tileNr).height);
|
263 | 11647 | nacho | draw(image, g, vport, cancel); |
264 | 10740 | nacho | } catch (NoninvertibleTransformException e) { |
265 | e.printStackTrace(); |
||
266 | } |
||
267 | } |
||
268 | 12068 | bsanchez | } else
|
269 | 11647 | nacho | draw(image, g, vp, cancel); |
270 | 11670 | nacho | status.applyStatus(this);
|
271 | 10740 | nacho | firstLoad = false;
|
272 | } |
||
273 | |||
274 | 12068 | bsanchez | if (mustTileDraw) {
|
275 | 10740 | nacho | Point2D p = vp.getOffset();
|
276 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
||
277 | Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
||
278 | tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
||
279 | 12068 | bsanchez | for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
280 | 10740 | nacho | // drawing part
|
281 | try {
|
||
282 | ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
||
283 | 11647 | nacho | draw(image, g, vport, cancel); |
284 | 10740 | nacho | } catch (NoninvertibleTransformException e) { |
285 | e.printStackTrace(); |
||
286 | } |
||
287 | } |
||
288 | 12068 | bsanchez | } else
|
289 | 11647 | nacho | draw(image, g, vp, cancel); |
290 | 10740 | nacho | |
291 | 12068 | bsanchez | if (getVirtualLayers() != null) { |
292 | try {
|
||
293 | getVirtualLayers().draw(image, g, vp, cancel, scale); |
||
294 | } catch (ReadDriverException e) {
|
||
295 | NotificationManager.addError("Error dibujando", e);
|
||
296 | } |
||
297 | 10740 | nacho | } |
298 | } |
||
299 | } |
||
300 | 12050 | bsanchez | |
301 | 11647 | nacho | private void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) { |
302 | Extent e = new Extent(vp.getAdjustedExtent());
|
||
303 | Dimension imgSz = vp.getImageSize();
|
||
304 | ViewPortData vp2 = new ViewPortData(vp.getProjection(), e, imgSz );
|
||
305 | vp2.setMat(vp.getAffineTransform()); |
||
306 | 11675 | nacho | getRender().draw(g, vp2); |
307 | 11647 | nacho | } |
308 | 10740 | nacho | |
309 | /**
|
||
310 | * Inserta la proyecci?n.
|
||
311 | *
|
||
312 | * @param proj Proyecci?n.
|
||
313 | */
|
||
314 | public void setProjection(IProjection proj) { |
||
315 | super.setProjection(proj);
|
||
316 | } |
||
317 | |||
318 | /*
|
||
319 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
||
320 | */
|
||
321 | public Rectangle2D getFullExtent(){ |
||
322 | 11647 | nacho | return dataset.getExtent().toRectangle2D();
|
323 | 10740 | nacho | } |
324 | |||
325 | /**
|
||
326 | 11600 | nacho | * Obtiene el valor del pixel del Image en la posici?n real x,y
|
327 | 10740 | nacho | * @param x Posici?n x
|
328 | * @param y Posici?n y
|
||
329 | * @return valor de pixel
|
||
330 | */
|
||
331 | 11594 | nacho | public int[] getPixel(double wcx, double wcy) { |
332 | 12068 | bsanchez | int[] argb = { -1, -1, -1, -1 }; |
333 | if (wcx <= getMaxX() && wcx >= getMinX() && wcy <= getMaxY() && wcy >= getMinY()) {
|
||
334 | 11594 | nacho | View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
335 | 12068 | bsanchez | if (theView instanceof IView) { |
336 | // BufferedImage buf = ((IView) theView).getMapControl().getImage();
|
||
337 | 11594 | nacho | Point2D p = ((IView) theView).getMapControl().getViewPort().fromMapPoint(wcx, wcy);
|
338 | 12068 | bsanchez | return getPixel((int) p.getX(), (int) p.getY()); |
339 | 11600 | nacho | } |
340 | } |
||
341 | return argb;
|
||
342 | } |
||
343 | 12050 | bsanchez | |
344 | 11600 | nacho | /**
|
345 | * Obtiene el valor del pixel del Image en la posici?n x,y
|
||
346 | * @param x Posici?n x
|
||
347 | * @param y Posici?n y
|
||
348 | * @return valor de pixel
|
||
349 | */
|
||
350 | public int[] getPixel(int pxx, int pxy) { |
||
351 | 12068 | bsanchez | int[] argb = { -1, -1, -1, -1 }; |
352 | 11840 | nacho | View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
353 | BufferedImage buf = null; |
||
354 | 12068 | bsanchez | if (theView instanceof IView) |
355 | 11840 | nacho | buf = ((IView) theView).getMapControl().getImage(); |
356 | 12068 | bsanchez | if (pxx >= 0 && pxx < buf.getWidth() && pxy >= 0 && pxy < buf.getHeight()) { |
357 | if (theView instanceof IView) { |
||
358 | 11600 | nacho | int value = buf.getRGB(pxx, pxy);
|
359 | 11594 | nacho | argb[0] = ((value & 0xff000000) >> 24); |
360 | argb[1] = ((value & 0x00ff0000) >> 16); |
||
361 | argb[2] = ((value & 0x0000ff00) >> 8); |
||
362 | argb[3] = (value & 0x000000ff); |
||
363 | } |
||
364 | } |
||
365 | return argb;
|
||
366 | 10740 | nacho | } |
367 | |||
368 | 11647 | nacho | /*
|
369 | * (non-Javadoc)
|
||
370 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxX()
|
||
371 | */
|
||
372 | 10740 | nacho | public double getMaxX(){ |
373 | 12068 | bsanchez | return this.getFullExtent().getMaxX(); |
374 | 10740 | nacho | } |
375 | |||
376 | 11647 | nacho | /*
|
377 | * (non-Javadoc)
|
||
378 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxY()
|
||
379 | */
|
||
380 | 10740 | nacho | public double getMaxY(){ |
381 | return this.getFullExtent().getMaxY(); |
||
382 | } |
||
383 | |||
384 | 11647 | nacho | /*
|
385 | * (non-Javadoc)
|
||
386 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getMinX()
|
||
387 | */
|
||
388 | 10740 | nacho | public double getMinX(){ |
389 | 12068 | bsanchez | return this.getFullExtent().getMinX(); |
390 | 10740 | nacho | } |
391 | |||
392 | 11647 | nacho | /*
|
393 | * (non-Javadoc)
|
||
394 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getMinY()
|
||
395 | */
|
||
396 | 10740 | nacho | public double getMinY(){ |
397 | 12068 | bsanchez | return this.getFullExtent().getMinY(); |
398 | 10740 | nacho | } |
399 | |||
400 | /* (non-Javadoc)
|
||
401 | * @deprecated. See String getInfo(Point p) throws DriverException
|
||
402 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
|
||
403 | */
|
||
404 | 11647 | nacho | public String queryByPoint(Point p) { |
405 | 12068 | bsanchez | String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n"; |
406 | 10740 | nacho | |
407 | 11647 | nacho | ArrayList attr = getAttributes();
|
408 | 10740 | nacho | data += " <raster\n";
|
409 | 11647 | nacho | data += " File=\"" + getFile() + "\"\n"; |
410 | for (int i = 0; i < attr.size(); i++) { |
||
411 | 12068 | bsanchez | Object[] a = (Object[]) attr.get(i); |
412 | 10740 | nacho | |
413 | 11647 | nacho | data += " " + a[0].toString() + "="; |
414 | 10740 | nacho | if (a[1].toString() instanceof String) |
415 | 11647 | nacho | data += "\"" + a[1].toString() + "\"\n"; |
416 | 10740 | nacho | else
|
417 | 11647 | nacho | data += a[1].toString() + "\n"; |
418 | 10740 | nacho | } |
419 | 11647 | nacho | data += " Point=\"" + posX + " , " + posY + "\"\n"; |
420 | data += " Point_WC=\"" + posXWC + " , " + posYWC + "\"\n"; |
||
421 | data += " RGB=\"" + r + ", " + g + ", " + b + "\"\n"; |
||
422 | 10740 | nacho | data += " />\n";
|
423 | |||
424 | 11647 | nacho | data += "</file:" + normalizeAsXMLTag(getName()) + ">\n"; |
425 | 10740 | nacho | return data;
|
426 | } |
||
427 | |||
428 | public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) { |
||
429 | |||
430 | Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
|
||
431 | Point2D px = null; |
||
432 | if( pReal.getX() > this.getMinX() && |
||
433 | pReal.getX() < this.getMaxX() &&
|
||
434 | pReal.getY() > this.getMinY() &&
|
||
435 | 12068 | bsanchez | pReal.getY() < this.getMaxY()) {
|
436 | 11647 | nacho | ArrayList attr = getAttributes();
|
437 | 10740 | nacho | int w = 0, h = 0; |
438 | 11840 | nacho | for (int i = 0; i < attr.size(); i++) { |
439 | 12068 | bsanchez | Object[] a = (Object[]) attr.get(i); |
440 | if (a[0].toString().equals("Width")) |
||
441 | w = ((Integer) a[1]).intValue(); |
||
442 | if (a[0].toString().equals("Height")) |
||
443 | h = ((Integer) a[1]).intValue(); |
||
444 | 10740 | nacho | } |
445 | px = new Point2D.Double(); |
||
446 | 11647 | nacho | px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWCWidth(),
|
447 | ((this.getMaxY() - pReal.getY()) * h) / getWCHeight());
|
||
448 | 10740 | nacho | } |
449 | 12068 | bsanchez | int[] rgb = getPixel((int) p.getX(), (int) p.getY()); |
450 | 10740 | nacho | |
451 | StringXMLItem[] item = new StringXMLItem[1]; |
||
452 | 11840 | nacho | String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n"; |
453 | 10740 | nacho | |
454 | data += " <raster\n";
|
||
455 | 11840 | nacho | data += " View_Point=\"" + p.getX() + " , " + p.getY() + "\"\n"; |
456 | 12068 | bsanchez | data += " World_Point=\"" + pReal.getX() + " , " + pReal.getY() + "\"\n"; |
457 | if (px == null) |
||
458 | 10740 | nacho | data += " Pixel_Point=\"Out\"\n";
|
459 | else
|
||
460 | 12068 | bsanchez | data += " Pixel_Point=\"" + (int) px.getX() + " , " + (int) px.getY() + "\"\n"; |
461 | 11840 | nacho | data += " RGB=\"" + rgb[1] + " " + rgb[2] + " " + rgb[3] + "\"\n"; |
462 | 10740 | nacho | data += " Band_Value=\"";
|
463 | 11594 | nacho | try {
|
464 | 12174 | nacho | if (px != null) { |
465 | if(getDataType()[0] >= 0 && getDataType()[0] <= 3){ |
||
466 | for(int i = 0; i < getBandCount(); i++) |
||
467 | data += ((Integer)getGeoRasterMultiDataset().getData((int)px.getX(), (int)px.getY(), i)).intValue() + " "; |
||
468 | } |
||
469 | if(getDataType()[0] == 4){ |
||
470 | for(int i = 0; i < getBandCount(); i++) |
||
471 | data += ((Float)getGeoRasterMultiDataset().getData((int)px.getX(), (int)px.getY(), i)).floatValue() + " "; |
||
472 | } |
||
473 | if(getDataType()[0] == 5){ |
||
474 | for(int i = 0; i < getBandCount(); i++) |
||
475 | data += ((Double)getGeoRasterMultiDataset().getData((int)px.getX(), (int)px.getY(), i)).doubleValue() + " "; |
||
476 | } |
||
477 | 11594 | nacho | } |
478 | } catch (RasterDriverException ex) {
|
||
479 | 12050 | bsanchez | |
480 | 11594 | nacho | } catch (InvalidSetViewException ex) {
|
481 | 12050 | bsanchez | |
482 | 11594 | nacho | } catch (FileNotOpenException ex) {
|
483 | 12050 | bsanchez | |
484 | 10740 | nacho | } |
485 | data += "\"\n";
|
||
486 | data += " />\n";
|
||
487 | 11647 | nacho | data += "</file:" + normalizeAsXMLTag(getName()) + ">\n"; |
488 | 10740 | nacho | |
489 | item[0] = new StringXMLItem(data, this); |
||
490 | return item;
|
||
491 | } |
||
492 | |||
493 | /**
|
||
494 | * Filters a string for being suitable as XML Tag, erasing
|
||
495 | * all not alphabetic or numeric characters.
|
||
496 | * @param s
|
||
497 | * @return string normalized
|
||
498 | */
|
||
499 | public String normalizeAsXMLTag(String s) { |
||
500 | 11670 | nacho | return s.replaceAll("[^a-zA-Z0-9]", ""); |
501 | 10740 | nacho | } |
502 | |||
503 | /**
|
||
504 | * Obtiene atributos a partir de un georasterfile
|
||
505 | * @return
|
||
506 | */
|
||
507 | public ArrayList getAttributes() { |
||
508 | 11647 | nacho | ArrayList attr = new ArrayList(); |
509 | Object [][] a = { |
||
510 | {"Filename", dataset.getDataset(0).getFName()}, |
||
511 | {"Filesize", new Long(dataset.getFileSize())}, |
||
512 | {"Width", new Integer((int)dataset.getWidth()[0])}, |
||
513 | {"Height", new Integer((int)dataset.getHeight()[0])}, |
||
514 | {"Bands", new Integer(dataset.getBandCount())} |
||
515 | }; |
||
516 | for (int i = 0; i < a.length; i++) |
||
517 | attr.add(a[i]); |
||
518 | return attr;
|
||
519 | 10740 | nacho | } |
520 | |||
521 | /**
|
||
522 | 12225 | nacho | * Escribe en el proyecto la capa actual
|
523 | 10740 | nacho | * @throws XMLException
|
524 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
||
525 | */
|
||
526 | public XMLEntity getXMLEntity() throws XMLException { |
||
527 | XMLEntity xml = super.getXMLEntity();
|
||
528 | 11647 | nacho | xml.putProperty("file", getFile());
|
529 | xml.putProperty("driverName", "gvSIG Raster Driver"); |
||
530 | 10740 | nacho | |
531 | 12068 | bsanchez | // Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
|
532 | if (status == null) |
||
533 | 10740 | nacho | status = new StatusLayerRaster();
|
534 | 11670 | nacho | status.getXMLEntity(xml, true, this); |
535 | 12050 | bsanchez | |
536 | 10740 | nacho | return xml;
|
537 | } |
||
538 | |||
539 | 12068 | bsanchez | public void setXMLEntity03(XMLEntity xml) throws XMLException { |
540 | 10740 | nacho | } |
541 | |||
542 | 12225 | nacho | /**
|
543 | * Recupera de disco los datos de la capa.
|
||
544 | */
|
||
545 | 11670 | nacho | public void setXMLEntity(XMLEntity xml)throws XMLException { |
546 | 10740 | nacho | super.setXMLEntity(xml);
|
547 | 12050 | bsanchez | |
548 | 11670 | nacho | params = new File(xml.getStringProperty("file")); |
549 | 10740 | nacho | |
550 | 11647 | nacho | // Para notificar al adapter-driver cual es la proyecci?n.
|
551 | setProjection(super.getProjection());
|
||
552 | 10740 | nacho | |
553 | 11647 | nacho | //Inicializamos la clase a la que se usa por defecto para
|
554 | //compatibilidad con proyectos antiguos
|
||
555 | String claseStr = StatusLayerRaster.defaultClass;
|
||
556 | 12050 | bsanchez | if (xml.contains("raster.class")) |
557 | 11647 | nacho | claseStr = xml.getStringProperty("raster.class");
|
558 | 12050 | bsanchez | |
559 | 12068 | bsanchez | if (status != null) |
560 | 11670 | nacho | status.setXMLEntity(xml, this);
|
561 | 12068 | bsanchez | else {
|
562 | // Cuando cargamos un proyecto
|
||
563 | 10740 | nacho | |
564 | 12068 | bsanchez | if (claseStr != null && !claseStr.equals("")) { |
565 | try {
|
||
566 | 11647 | nacho | Class clase = Class.forName(claseStr); |
567 | Constructor constr = clase.getConstructor(null); |
||
568 | 12068 | bsanchez | status = (StatusRasterInterface) constr.newInstance(null);
|
569 | if (status != null) |
||
570 | 11670 | nacho | status.setXMLEntity(xml, this);
|
571 | 12068 | bsanchez | } catch (ClassNotFoundException exc) { |
572 | 11647 | nacho | exc.printStackTrace(); |
573 | 12068 | bsanchez | } catch (InstantiationException exc) { |
574 | 11647 | nacho | exc.printStackTrace(); |
575 | 12068 | bsanchez | } catch (IllegalAccessException exc) { |
576 | 11647 | nacho | exc.printStackTrace(); |
577 | 12068 | bsanchez | } catch (NoSuchMethodException exc) { |
578 | 11647 | nacho | exc.printStackTrace(); |
579 | 12068 | bsanchez | } catch (InvocationTargetException exc) { |
580 | 11647 | nacho | exc.printStackTrace(); |
581 | } |
||
582 | } |
||
583 | 10740 | nacho | } |
584 | 11647 | nacho | firstLoad = true;
|
585 | |||
586 | 10740 | nacho | } |
587 | |||
588 | /* (non-Javadoc)
|
||
589 | * @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)
|
||
590 | */
|
||
591 | 12068 | bsanchez | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties) { |
592 | 10740 | nacho | |
593 | 12068 | bsanchez | if (!isVisible() || !isWithinScale(scale))
|
594 | return;
|
||
595 | |||
596 | 10740 | nacho | isPrinting = true;
|
597 | if (!mustTilePrint) {
|
||
598 | 12068 | bsanchez | draw(null, g, viewPort, cancel,scale);
|
599 | 10740 | nacho | } else {
|
600 | 12068 | bsanchez | // Para no pedir imagenes demasiado grandes, vamos
|
601 | // a hacer lo mismo que hace EcwFile: chunkear.
|
||
602 | // Llamamos a drawView con cuadraditos m?s peque?os
|
||
603 | // del BufferedImage ni caso, cuando se imprime viene con null
|
||
604 | 10740 | nacho | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
|
605 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
606 | |||
607 | //Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n
|
||
608 | //de realce si la imagen es de 16 bits.
|
||
609 | |||
610 | //RasterStats stats = getSource().getFilterStack().getStats();
|
||
611 | //if(stats != null)
|
||
612 | 12068 | bsanchez | //stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));
|
613 | 10740 | nacho | |
614 | |||
615 | 12068 | bsanchez | for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
616 | // Parte que dibuja
|
||
617 | try {
|
||
618 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
619 | draw(null, g, vp, cancel, scale);
|
||
620 | 10740 | nacho | } catch (NoninvertibleTransformException e) { |
621 | e.printStackTrace(); |
||
622 | } |
||
623 | 12068 | bsanchez | } |
624 | 10740 | nacho | /*if(stats != null){
|
625 | getSource().getFilterStack().getStats().history.clear();
|
||
626 | stats = getSource().getFilterStack().getStats();
|
||
627 | }*/
|
||
628 | } |
||
629 | 12068 | bsanchez | isPrinting = false;
|
630 | 10740 | nacho | } |
631 | |||
632 | 12068 | bsanchez | public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) { |
633 | // Para no pedir imagenes demasiado grandes, vamos
|
||
634 | // a hacer lo mismo que hace EcwFile: chunkear.
|
||
635 | // Llamamos a drawView con cuadraditos m?s peque?os
|
||
636 | // del BufferedImage ni caso, cuando se imprime viene con null
|
||
637 | 10740 | nacho | |
638 | 12068 | bsanchez | int numW, numH;
|
639 | int stepX, stepY;
|
||
640 | int xProv, yProv;
|
||
641 | int A = 1500; |
||
642 | int H = 1500; |
||
643 | int altoAux, anchoAux;
|
||
644 | 10740 | nacho | |
645 | 12068 | bsanchez | AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone(); |
646 | 10740 | nacho | |
647 | 12068 | bsanchez | // Vamos a hacerlo en trozos de AxH
|
648 | Rectangle r = g.getClipBounds();
|
||
649 | numW = (int) (r.width) / A;
|
||
650 | numH = (int) (r.height) / H;
|
||
651 | 10740 | nacho | |
652 | 12068 | bsanchez | double[] srcPts = new double[8]; |
653 | double[] dstPts = new double[8]; |
||
654 | 10740 | nacho | |
655 | 12068 | bsanchez | yProv = (int) r.y;
|
656 | for (stepY = 0; stepY < numH + 1; stepY++) { |
||
657 | if ((yProv + H) > r.getMaxY())
|
||
658 | altoAux = (int) r.getMaxY() - yProv;
|
||
659 | else
|
||
660 | altoAux = H; |
||
661 | 10740 | nacho | |
662 | 12068 | bsanchez | xProv = (int) r.x;
|
663 | for (stepX = 0; stepX < numW + 1; stepX++) { |
||
664 | if ((xProv + A) > r.getMaxX())
|
||
665 | anchoAux = (int) r.getMaxX() - xProv;
|
||
666 | else
|
||
667 | anchoAux = A; |
||
668 | 10740 | nacho | |
669 | 12068 | bsanchez | //Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
|
670 | 10740 | nacho | |
671 | 12068 | bsanchez | // Parte que dibuja
|
672 | srcPts[0] = xProv;
|
||
673 | srcPts[1] = yProv;
|
||
674 | srcPts[2] = xProv + anchoAux + 1; |
||
675 | srcPts[3] = yProv;
|
||
676 | srcPts[4] = xProv + anchoAux + 1; |
||
677 | srcPts[5] = yProv + altoAux + 1; |
||
678 | srcPts[6] = xProv;
|
||
679 | srcPts[7] = yProv + altoAux + 1; |
||
680 | 10740 | nacho | |
681 | 12068 | bsanchez | try {
|
682 | mat.inverseTransform(srcPts, 0, dstPts, 0, 4); |
||
683 | Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(dstPts[0], dstPts[1], dstPts[2] - dstPts[0], dstPts[5] - dstPts[3]); |
||
684 | // Extent extent = new Extent(rectCuadricula);
|
||
685 | 10740 | nacho | |
686 | 12068 | bsanchez | Dimension tam = new Dimension(anchoAux + 1, altoAux + 1); |
687 | ViewPort vp = viewPort.cloneViewPort(); |
||
688 | vp.setImageSize(tam); |
||
689 | vp.setExtent(rectCuadricula); |
||
690 | vp.setAffineTransform(mat); |
||
691 | draw(null, g, vp, cancel, scale);
|
||
692 | 10740 | nacho | |
693 | 12068 | bsanchez | } catch (NoninvertibleTransformException e) { |
694 | e.printStackTrace(); |
||
695 | } |
||
696 | // Fin parte que dibuja
|
||
697 | xProv = xProv + A; |
||
698 | } |
||
699 | yProv = yProv + H; |
||
700 | } |
||
701 | 10740 | nacho | } |
702 | |||
703 | /**
|
||
704 | * Borra de la lista de listeners el que se pasa como par?metro.
|
||
705 | *
|
||
706 | * @param o LayerListener a borrar.
|
||
707 | *
|
||
708 | * @return True si ha sido correcto el borrado del Listener.
|
||
709 | */
|
||
710 | public boolean removeLayerListener(LayerListener o) { |
||
711 | 12281 | nacho | //Salva a RMF
|
712 | try {
|
||
713 | this.getGeoRasterMultiDataset().saveRmfModification();
|
||
714 | } catch (IOException e) { |
||
715 | //No se ha salvado nada
|
||
716 | } |
||
717 | 12284 | bsanchez | |
718 | 12281 | nacho | //Cierra todas las ventanas asociadas a la capa
|
719 | 12225 | nacho | IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
720 | for (int i = 0; i < wList.length; i++) { |
||
721 | String name = wList[i].getWindowInfo().getAdditionalInfo();
|
||
722 | if( name != null && name.compareTo(getName()) == 0) |
||
723 | PluginServices.getMDIManager().closeWindow(wList[i]); |
||
724 | } |
||
725 | 12284 | bsanchez | |
726 | 12068 | bsanchez | if (this.isRemoveRasterFlag()) { |
727 | 11647 | nacho | dataset.close(); |
728 | 10740 | nacho | this.setRemoveRasterFlag(true); |
729 | } |
||
730 | return super.layerListeners.remove(o); |
||
731 | } |
||
732 | |||
733 | /**
|
||
734 | * @return Returns the removeRasterFlag.
|
||
735 | */
|
||
736 | public boolean isRemoveRasterFlag() { |
||
737 | return removeRasterFlag;
|
||
738 | } |
||
739 | |||
740 | /**
|
||
741 | * Asigna el valor del flag que dice si destruimos la memoria del raster
|
||
742 | * al eliminarlo del TOC o no.
|
||
743 | * @param removeRasterFlag The removeRasterFlag to set.
|
||
744 | */
|
||
745 | public void setRemoveRasterFlag(boolean removeRasterFlag) { |
||
746 | this.removeRasterFlag = removeRasterFlag;
|
||
747 | } |
||
748 | |||
749 | public ImageIcon getTocImageIcon() { |
||
750 | return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG")); |
||
751 | } |
||
752 | |||
753 | /*
|
||
754 | * (non-Javadoc)
|
||
755 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
||
756 | */
|
||
757 | public int[] getTileSize() { |
||
758 | int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
||
759 | return size;
|
||
760 | } |
||
761 | |||
762 | /*
|
||
763 | * (non-Javadoc)
|
||
764 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
||
765 | */
|
||
766 | public boolean isTiled() { |
||
767 | return mustTileDraw;
|
||
768 | } |
||
769 | |||
770 | /**
|
||
771 | * Obtiene el flag que dice si la imagen est? o no georreferenciada
|
||
772 | * @return true si est? georreferenciada y false si no lo est?.
|
||
773 | */
|
||
774 | public boolean isGeoreferenced() { |
||
775 | 11647 | nacho | return dataset.isGeoreferenced();
|
776 | 10740 | nacho | } |
777 | 12050 | bsanchez | |
778 | 10740 | nacho | /**
|
779 | * Get datasource object
|
||
780 | * @return
|
||
781 | */
|
||
782 | 11084 | nacho | public BufferFactory getDatasource(){
|
783 | 11647 | nacho | return bufferFactory;
|
784 | 12050 | bsanchez | } |
785 | |||
786 | 10740 | nacho | /*
|
787 | * (non-Javadoc)
|
||
788 | * @see org.gvsig.fmap.raster.IRasterOperations#getPXHeight()
|
||
789 | */
|
||
790 | public double getPxHeight() { |
||
791 | 11647 | nacho | return (dataset.getHeight() != null && dataset.getHeight().length >= 1) ? dataset.getHeight()[0] : 0; |
792 | 10740 | nacho | } |
793 | |||
794 | /*
|
||
795 | * (non-Javadoc)
|
||
796 | * @see org.gvsig.fmap.raster.IRasterOperations#getPxWidth()
|
||
797 | */
|
||
798 | public double getPxWidth() { |
||
799 | 11647 | nacho | return (dataset.getWidth() != null && dataset.getWidth().length >= 1) ? dataset.getWidth()[0] : 0; |
800 | 10740 | nacho | } |
801 | |||
802 | /*
|
||
803 | * (non-Javadoc)
|
||
804 | * @see org.gvsig.fmap.raster.IGeoDimension#getWCHeight()
|
||
805 | */
|
||
806 | public double getWCHeight() { |
||
807 | 11647 | nacho | return getFullExtent().getHeight();
|
808 | 10740 | nacho | } |
809 | |||
810 | /*
|
||
811 | * (non-Javadoc)
|
||
812 | * @see org.gvsig.fmap.raster.IGeoDimension#getWCWidth()
|
||
813 | */
|
||
814 | public double getWCWidth() { |
||
815 | 11647 | nacho | return getFullExtent().getWidth();
|
816 | 10740 | nacho | } |
817 | 12050 | bsanchez | |
818 | 10740 | nacho | /*
|
819 | * (non-Javadoc)
|
||
820 | * @see org.gvsig.fmap.raster.IRasterFile#getFileSize()
|
||
821 | */
|
||
822 | public long[] getFileSize(){ |
||
823 | 11647 | nacho | int nFiles = dataset.getDatasetCount();
|
824 | 10740 | nacho | long[] s = new long[nFiles]; |
825 | 12068 | bsanchez | for (int i = 0; i < nFiles; i++) |
826 | 11647 | nacho | s[i] = dataset.getDataset(i).getFileSize(); |
827 | 10740 | nacho | return s;
|
828 | } |
||
829 | 12050 | bsanchez | |
830 | 10740 | nacho | /*
|
831 | * (non-Javadoc)
|
||
832 | * @see org.gvsig.fmap.raster.IRasterFile#getFileName()
|
||
833 | */
|
||
834 | public String[] getFileName(){ |
||
835 | 11647 | nacho | int nFiles = dataset.getDatasetCount();
|
836 | 10740 | nacho | String[] s = new String[nFiles]; |
837 | 12068 | bsanchez | for (int i = 0; i < nFiles; i++) |
838 | 11647 | nacho | s[i] = dataset.getDataset(i).getFName(); |
839 | 10740 | nacho | return s;
|
840 | } |
||
841 | 12050 | bsanchez | |
842 | 10740 | nacho | /*
|
843 | * (non-Javadoc)
|
||
844 | * @see org.gvsig.fmap.raster.IRasterFile#getFileCount()
|
||
845 | */
|
||
846 | public int getFileCount(){ |
||
847 | 11647 | nacho | return dataset.getDatasetCount();
|
848 | 10740 | nacho | } |
849 | 12050 | bsanchez | |
850 | 10740 | nacho | /*
|
851 | * (non-Javadoc)
|
||
852 | * @see org.gvsig.fmap.raster.IRasterFile#getFileFormat()
|
||
853 | */
|
||
854 | public String getFileFormat(){ |
||
855 | 11647 | nacho | String fName = dataset.getDataset(0).getFName(); |
856 | 10740 | nacho | int index = fName.lastIndexOf(".") + 1; |
857 | String ext = null; |
||
858 | 12068 | bsanchez | if (index > 0) |
859 | 10740 | nacho | ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length()); |
860 | return ext;
|
||
861 | } |
||
862 | 12050 | bsanchez | |
863 | 10740 | nacho | /*
|
864 | * (non-Javadoc)
|
||
865 | * @see org.gvsig.fmap.raster.IRasterOperations#getBandCount()
|
||
866 | */
|
||
867 | public int getBandCount(){ |
||
868 | 11647 | nacho | return dataset.getBandCount();
|
869 | 10740 | nacho | } |
870 | 12050 | bsanchez | |
871 | 10740 | nacho | /*
|
872 | * (non-Javadoc)
|
||
873 | * @see org.gvsig.fmap.raster.IRasterOperations#getDatatype()
|
||
874 | */
|
||
875 | public int[] getDataType(){ |
||
876 | 11647 | nacho | return dataset.getDataType();
|
877 | 10740 | nacho | } |
878 | 12050 | bsanchez | |
879 | 10740 | nacho | /*
|
880 | * (non-Javadoc)
|
||
881 | * @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
|
||
882 | */
|
||
883 | public GridTransparency getRenderTransparency(){
|
||
884 | 11647 | nacho | return render.getLastTransparency();
|
885 | 10740 | nacho | } |
886 | |||
887 | /*
|
||
888 | * (non-Javadoc)
|
||
889 | * @see org.gvsig.fmap.raster.IRasterDataset#getGeoRasterMultiDataset()
|
||
890 | */
|
||
891 | 11482 | nacho | public MultiRasterDataset getGeoRasterMultiDataset() {
|
892 | 11647 | nacho | return dataset;
|
893 | 10740 | nacho | } |
894 | 12050 | bsanchez | |
895 | 10740 | nacho | /*
|
896 | * (non-Javadoc)
|
||
897 | * @see org.gvsig.fmap.raster.IRasterDataset#addFile(java.lang.String)
|
||
898 | */
|
||
899 | 11670 | nacho | public void addFile(String fileName) { |
900 | 12068 | bsanchez | try {
|
901 | if (getRender() != null) |
||
902 | 11647 | nacho | bufferFactory.addFile(RasterDataset.open(getProjection(), fileName)); |
903 | } catch (NotSupportedExtensionException e) {
|
||
904 | NotificationManager.addError("Formato no valido", e);
|
||
905 | } catch (RasterDriverException e) {
|
||
906 | NotificationManager.addError("Formato no valido", e);
|
||
907 | 10740 | nacho | } |
908 | } |
||
909 | |||
910 | /*
|
||
911 | * (non-Javadoc)
|
||
912 | * @see org.gvsig.fmap.raster.IRasterDataset#delFile(java.lang.String)
|
||
913 | */
|
||
914 | 11670 | nacho | public void delFile(String fileName) { |
915 | 12068 | bsanchez | if (getRender() != null) |
916 | 11647 | nacho | bufferFactory.removeFile(fileName); |
917 | 10740 | nacho | } |
918 | |||
919 | /*
|
||
920 | * (non-Javadoc)
|
||
921 | * @see org.gvsig.fmap.raster.IRasterDataset#getInfo(java.lang.String)
|
||
922 | */
|
||
923 | public Object getInfo(String key) { |
||
924 | 12068 | bsanchez | if (key.equals("DriverName")) |
925 | 11647 | nacho | return "gvSIG Raster Driver"; |
926 | 10740 | nacho | return null; |
927 | } |
||
928 | 12050 | bsanchez | |
929 | 10740 | nacho | /*
|
930 | * (non-Javadoc)
|
||
931 | * @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
|
||
932 | */
|
||
933 | public RasterFilterList getRenderFilterList(){
|
||
934 | 11675 | nacho | return getRender().getFilterList();
|
935 | 10740 | nacho | } |
936 | |||
937 | /*
|
||
938 | * (non-Javadoc)
|
||
939 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getPixelSizeX()
|
||
940 | */
|
||
941 | public double[] getPxWidthByDataset() { |
||
942 | 11647 | nacho | return dataset.getWidth();
|
943 | 10740 | nacho | } |
944 | |||
945 | /*
|
||
946 | * (non-Javadoc)
|
||
947 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getPixelSizeY()
|
||
948 | */
|
||
949 | public double[] getPxHeightByDataset() { |
||
950 | 11647 | nacho | return dataset.getHeight();
|
951 | 10740 | nacho | } |
952 | |||
953 | /*
|
||
954 | * (non-Javadoc)
|
||
955 | * @see org.gvsig.raster.shared.IRasterOperations#getMetadata()
|
||
956 | */
|
||
957 | public DatasetMetadata[] getMetadata() { |
||
958 | 11647 | nacho | int count = dataset.getDatasetCount();
|
959 | 10740 | nacho | DatasetMetadata[] metadata = new DatasetMetadata[count]; |
960 | 11647 | nacho | for (int i = 0; i < count; i++) { |
961 | metadata[i] = dataset.getDataset(i).getMetadata(); |
||
962 | 10740 | nacho | } |
963 | return metadata;
|
||
964 | } |
||
965 | |||
966 | /*
|
||
967 | * (non-Javadoc)
|
||
968 | * @see org.gvsig.raster.shared.IRasterOperations#getBandCountFromDataset()
|
||
969 | */
|
||
970 | public int[] getBandCountFromDataset() { |
||
971 | 11647 | nacho | int count = dataset.getDatasetCount();
|
972 | 10740 | nacho | int[] bands = new int[count]; |
973 | 11647 | nacho | for (int i = 0; i < count; i++) { |
974 | bands[i] = dataset.getDataset(i).getBandCount(); |
||
975 | 10740 | nacho | } |
976 | return bands;
|
||
977 | } |
||
978 | |||
979 | /*
|
||
980 | * (non-Javadoc)
|
||
981 | * @see org.gvsig.raster.shared.IRasterOperations#getColourInterpretation(int, int)
|
||
982 | */
|
||
983 | public String getColourInterpretation(int band, int dataset) { |
||
984 | 12050 | bsanchez | if (this.dataset.getColorInterpretation(dataset) == null) |
985 | 11647 | nacho | return "Undefined"; |
986 | return this.dataset.getColorInterpretation(dataset).get(band); |
||
987 | 10740 | nacho | } |
988 | 12050 | bsanchez | |
989 | 11647 | nacho | /*
|
990 | * (non-Javadoc)
|
||
991 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getStringProjection()
|
||
992 | */
|
||
993 | 10740 | nacho | public String getStringProjection() { |
994 | try {
|
||
995 | 11647 | nacho | return dataset.getStringProjection();
|
996 | 10740 | nacho | } catch (RasterDriverException e) {
|
997 | 11647 | nacho | NotificationManager.addError("No puedo obtener la proyecci?n asociada al dataset.", e);
|
998 | 10740 | nacho | } |
999 | return null; |
||
1000 | } |
||
1001 | 12050 | bsanchez | |
1002 | 11173 | nacho | /**
|
1003 | 11579 | nacho | * Obtiene el grid de la capa completa. Hay que tener cuidado porque cuando se hace esta
|
1004 | 12284 | bsanchez | * petici?n se carga un buffer con todos los datos de la capa. Este buffer puede ser
|
1005 | 11579 | nacho | * cacheado o no dependiendo del tama?o de esta.
|
1006 | * @param interpolated true si se solicita un grid interpolado y false si se solicita sin interpolar.
|
||
1007 | * @return Grid.
|
||
1008 | */
|
||
1009 | public Grid getFullGrid(boolean interpolated) { |
||
1010 | BufferFactory bf = getDatasource(); |
||
1011 | bf.clearDrawableBand(); |
||
1012 | bf.setAllDrawableBands(); |
||
1013 | bf.setAreaOfInterest(); |
||
1014 | return new Grid(bf, interpolated); |
||
1015 | } |
||
1016 | 11647 | nacho | |
1017 | 11670 | nacho | /*
|
1018 | * (non-Javadoc)
|
||
1019 | * @see org.gvsig.raster.shared.IRasterGeoOperations#getFullRasterExtent()
|
||
1020 | */
|
||
1021 | 11647 | nacho | public Extent getFullRasterExtent() {
|
1022 | return new Extent(getFullExtent()); |
||
1023 | } |
||
1024 | |||
1025 | 12050 | bsanchez | |
1026 | 11647 | nacho | /**
|
1027 | * Devuelve el fichero asociado a la capa o null si no tiene.
|
||
1028 | * @return Fichero.
|
||
1029 | */
|
||
1030 | public File getFile() { |
||
1031 | return (params instanceof File) ? ((File)params) : null; |
||
1032 | } |
||
1033 | 12050 | bsanchez | |
1034 | 11647 | nacho | /**
|
1035 | * Consulta si un fichero es aceptado o no para este tipo de capa.
|
||
1036 | * @param file Fichero a consultar
|
||
1037 | * @return true si es aceptado y false si no lo es.
|
||
1038 | */
|
||
1039 | public static boolean isFileAccepted(File file) { |
||
1040 | return RasterDataset.fileIsSupported(file.getName());
|
||
1041 | } |
||
1042 | 11713 | nacho | |
1043 | 12035 | nacho | /*
|
1044 | * (non-Javadoc)
|
||
1045 | * @see org.gvsig.raster.shared.IRasterRendering#existColorTable()
|
||
1046 | */
|
||
1047 | public boolean existColorTable() { |
||
1048 | return this.getRender().existColorTable(); |
||
1049 | } |
||
1050 | 10740 | nacho | } |