Revision 1407
org.gvsig.raster.gdal/tags/buildNumber_22/org.gvsig.raster.gdal/distribution/distribution.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
</assembly> |
|
0 | 3 |
org.gvsig.raster.gdal/tags/buildNumber_22/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.raster.gdal.io.DefaultGdalIOLibrary |
|
0 | 2 |
org.gvsig.raster.gdal/tags/buildNumber_22/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/memory/io/MemoryRasterProvider.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.memory.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.awt.geom.Rectangle2D; |
|
27 |
|
|
28 |
import org.cresques.cts.ICoordTrans; |
|
29 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
30 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
32 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
33 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
36 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
38 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
39 |
import org.gvsig.metadata.MetadataLocator; |
|
40 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
41 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
42 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
43 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
|
44 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
45 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
46 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
47 |
import org.gvsig.tools.ToolsLocator; |
|
48 |
import org.gvsig.tools.task.TaskStatus; |
|
49 |
|
|
50 |
/** |
|
51 |
* Driver para datos cargados en un objeto IBuffer |
|
52 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
53 |
* |
|
54 |
*/ |
|
55 |
public class MemoryRasterProvider extends DefaultRasterProvider { |
|
56 |
public static String NAME = "Gdal Store"; |
|
57 |
public static String DESCRIPTION = "Gdal Raster file"; |
|
58 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
|
59 |
|
|
60 |
private Extent v = null; |
|
61 |
protected Buffer buffer = null; |
|
62 |
private Extent extent = null; |
|
63 |
private boolean open = false; |
|
64 |
|
|
65 |
/** |
|
66 |
* Estado de transparencia del raster. |
|
67 |
*/ |
|
68 |
protected DataStoreTransparency fileTransparency = null; |
|
69 |
|
|
70 |
public static void register() { |
|
71 |
} |
|
72 |
|
|
73 |
/* |
|
74 |
* (non-Javadoc) |
|
75 |
* @see org.gvsig.raster.impl.provider.RasterProvider#registerTileProviderFormats(java.lang.Class) |
|
76 |
*/ |
|
77 |
public void registerTileProviderFormats(Class<RasterProvider> c) { |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Mandatory constructor to instantiate an empty provider |
|
83 |
*/ |
|
84 |
public MemoryRasterProvider() {} |
|
85 |
|
|
86 |
/** |
|
87 |
* Constructor. Asigna el buffer de datos y la extensi?n |
|
88 |
* @param proj Proyecci?n |
|
89 |
* @param buf Buffer |
|
90 |
* @throws NotSupportedExtensionException |
|
91 |
*/ |
|
92 |
public MemoryRasterProvider(AbstractRasterDataParameters params, |
|
93 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
|
94 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
95 |
.createDynObject( |
|
96 |
MetadataLocator.getMetadataManager().getDefinition( |
|
97 |
METADATA_DEFINITION_NAME))); |
|
98 |
setParam(storeServices, params); |
|
99 |
if(!(params instanceof MemoryDataParameters)) |
|
100 |
throw new NotSupportedExtensionException("Buffer not supported"); |
|
101 |
|
|
102 |
extent = ((MemoryDataParameters)params).getExtent(); |
|
103 |
this.buffer = ((MemoryDataParameters)params).getBuffer(); |
|
104 |
|
|
105 |
if(extent != null) { |
|
106 |
double psX = (extent.maxX() - extent.minX()) / buffer.getWidth(); |
|
107 |
double psY = (extent.minY() - extent.maxY()) / buffer.getHeight(); |
|
108 |
ownTransformation = new AffineTransform(psX, 0, 0, psY, extent.minX(), extent.maxY()); |
|
109 |
} else |
|
110 |
ownTransformation = new AffineTransform(1, 0, 0, -1, 0, buffer.getHeight()); |
|
111 |
|
|
112 |
if(buffer == null) |
|
113 |
throw new NotSupportedExtensionException("Buffer invalid"); |
|
114 |
|
|
115 |
load(); |
|
116 |
bandCount = buffer.getBandCount(); |
|
117 |
|
|
118 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf |
|
119 |
int[] dt = new int[buffer.getBandCount()]; |
|
120 |
for (int i = 0; i < dt.length; i++) |
|
121 |
dt[i] = buffer.getDataType(); |
|
122 |
setDataType(dt); |
|
123 |
open = true; |
|
124 |
} |
|
125 |
|
|
126 |
/* |
|
127 |
* (non-Javadoc) |
|
128 |
* @see org.gvsig.raster.dataset.GeoInfo#load() |
|
129 |
*/ |
|
130 |
public RasterProvider load() { |
|
131 |
return this; |
|
132 |
} |
|
133 |
|
|
134 |
/* |
|
135 |
* (non-Javadoc) |
|
136 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen() |
|
137 |
*/ |
|
138 |
public boolean isOpen() { |
|
139 |
return open; |
|
140 |
} |
|
141 |
|
|
142 |
/* |
|
143 |
* (non-Javadoc) |
|
144 |
* @see org.gvsig.raster.dataset.GeoInfo#close() |
|
145 |
*/ |
|
146 |
public void close() { |
|
147 |
buffer = null; |
|
148 |
open = false; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Asigna el extent de la vista actual. |
|
153 |
*/ |
|
154 |
public void setView(Extent e) { |
|
155 |
v = e; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Obtiene extent de la vista actual |
|
160 |
*/ |
|
161 |
public Extent getView() { |
|
162 |
return v; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Obtiene la anchura del fichero |
|
167 |
*/ |
|
168 |
public double getWidth() { |
|
169 |
return buffer.getWidth(); |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Obtiene la altura del fichero |
|
174 |
*/ |
|
175 |
public double getHeight() { |
|
176 |
return buffer.getHeight(); |
|
177 |
} |
|
178 |
|
|
179 |
/* |
|
180 |
* (non-Javadoc) |
|
181 |
* @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans) |
|
182 |
*/ |
|
183 |
public void reProject(ICoordTrans rp) { |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Obtiene la orientaci?n de la imagen a partir del signo del tama?o de pixel para poder |
|
188 |
* asignarlo en el setView. Esto es util para poder conocer como debe leerse la image, |
|
189 |
* de abajo a arriba, de arriba a abajo, de izquierda a derecha o de derecha a izquierda. |
|
190 |
* La posici?n habitual es la que el pixel size en X es positivo y en Y negativo leyendose |
|
191 |
* en este caso las X de menor a mayor y las Y de mayor a menor. Los casos posibles son: |
|
192 |
* <UL> |
|
193 |
* <LI><B>X > 0; Y < 0;</B> {true, false}</LI> |
|
194 |
* <LI><B>X > 0; Y > 0;</B> {true, true}</LI> |
|
195 |
* <LI><B>X < 0; Y > 0;</B> {false, true}</LI> |
|
196 |
* <LI><B>X < 0; Y < 0;</B> {false, false}</LI> |
|
197 |
* </UL> |
|
198 |
* |
|
199 |
* @return |
|
200 |
*/ |
|
201 |
/*private boolean[] getOrientation(){ |
|
202 |
boolean[] orientation = {true, false}; |
|
203 |
return orientation; |
|
204 |
}*/ |
|
205 |
|
|
206 |
/* (non-Javadoc) |
|
207 |
* @see org.cresques.io.GeoRasterFile#getData(int, int, int) |
|
208 |
*/ |
|
209 |
public Object getData(int x, int y, int band) { |
|
210 |
if(buffer.getDataType() == Buffer.TYPE_BYTE){ |
|
211 |
return new Integer(buffer.getElemByte(y, x, band)); |
|
212 |
}else if(buffer.getDataType() == Buffer.TYPE_SHORT){ |
|
213 |
return new Integer(buffer.getElemShort(y, x, band)); |
|
214 |
}else if(buffer.getDataType() == Buffer.TYPE_INT){ |
|
215 |
return new Integer(buffer.getElemInt(y, x, band)); |
|
216 |
}else if(buffer.getDataType() == Buffer.TYPE_FLOAT){ |
|
217 |
return new Float(buffer.getElemFloat(y, x, band)); |
|
218 |
}else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
|
219 |
return new Double(buffer.getElemDouble(y, x, band)); |
|
220 |
} |
|
221 |
return null; |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
/** |
|
226 |
* Devuelve el tama?o de bloque |
|
227 |
* @return Tama?o de bloque |
|
228 |
*/ |
|
229 |
public int getBlockSize(){ |
|
230 |
return 0; |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada |
|
235 |
* @return true si est? georreferenciada y false si no lo est?. |
|
236 |
*/ |
|
237 |
public boolean isGeoreferenced() { |
|
238 |
return (this.extent != null); |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar? |
|
243 |
* el valor de esta variable cada vez que dibuja. |
|
244 |
* @return true si se ha supersampleado y false si no se ha hecho. |
|
245 |
*/ |
|
246 |
public boolean isSupersampling() { |
|
247 |
return false; |
|
248 |
} |
|
249 |
|
|
250 |
/** |
|
251 |
* @return Returns the dataType. |
|
252 |
*/ |
|
253 |
public int[] getDataType() { |
|
254 |
int[] dt = new int[buffer.getBandCount()]; |
|
255 |
for (int i = 0; i < dt.length; i++) |
|
256 |
dt[i] = buffer.getDataType(); |
|
257 |
return dt; |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Ajusta los puntos pasados por par?metro a los l?mites del buffer. Es decir si alguno excede |
|
262 |
* los l?mites por arriba o por abajo los ajusta. |
|
263 |
* @param begin Punto inicial |
|
264 |
* @param end Punto final |
|
265 |
*/ |
|
266 |
private void adjustPointsToBufferLimits(Point2D begin, Point2D end) { |
|
267 |
if(begin.getX() < 0) |
|
268 |
begin.setLocation(0, begin.getY()); |
|
269 |
if(begin.getY() > buffer.getHeight()) |
|
270 |
begin.setLocation(begin.getX(), buffer.getHeight()); |
|
271 |
if(end.getY() < 0) |
|
272 |
end.setLocation(begin.getX(), 0); |
|
273 |
if(end.getX() > buffer.getWidth()) |
|
274 |
begin.setLocation(buffer.getWidth(), begin.getY()); |
|
275 |
} |
|
276 |
|
|
277 |
/* |
|
278 |
* (non-Javadoc) |
|
279 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener) |
|
280 |
*/ |
|
281 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
|
282 |
BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
/* |
|
287 |
* (non-Javadoc) |
|
288 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(double, double, double, double, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer) |
|
289 |
*/ |
|
290 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) { |
|
291 |
Point2D begin = worldToRaster(new Point2D.Double(ex.getULX(), ex.getULY())); |
|
292 |
Point2D end = worldToRaster(new Point2D.Double(ex.getLRX(), ex.getLRY())); |
|
293 |
setView(ex); |
|
294 |
|
|
295 |
adjustPointsToBufferLimits(begin, end); |
|
296 |
|
|
297 |
switch(buffer.getDataType()){ |
|
298 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
299 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
300 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
301 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
302 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
303 |
} |
|
304 |
return rasterBuf; |
|
305 |
} |
|
306 |
|
|
307 |
/* |
|
308 |
* (non-Javadoc) |
|
309 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(double, double, double, double, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer, boolean) |
|
310 |
*/ |
|
311 |
public Buffer getWindow(double x, double y, double w, double h, |
|
312 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) { |
|
313 |
Point2D begin = worldToRaster(new Point2D.Double(x, y)); |
|
314 |
Point2D end = worldToRaster(new Point2D.Double(x + w, y - h)); |
|
315 |
setView(new ExtentImpl(x, y, x + w, y - h)); |
|
316 |
|
|
317 |
adjustPointsToBufferLimits(begin, end); |
|
318 |
|
|
319 |
switch(buffer.getDataType()){ |
|
320 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
321 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
322 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
323 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
324 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break; |
|
325 |
} |
|
326 |
return rasterBuf; |
|
327 |
} |
|
328 |
|
|
329 |
/* |
|
330 |
* (non-Javadoc) |
|
331 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(double, double, double, double, int, int, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer, boolean) |
|
332 |
*/ |
|
333 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
334 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) { |
|
335 |
Point2D begin = worldToRaster(new Point2D.Double(extent.getMin().getX(), extent.getMax().getY())); |
|
336 |
Point2D end = worldToRaster(new Point2D.Double(extent.getMax().getX(), extent.getMin().getY())); |
|
337 |
setView(extent); |
|
338 |
|
|
339 |
adjustPointsToBufferLimits(begin, end); |
|
340 |
|
|
341 |
//Ancho y alto en pixels (double) del area seleccionada. |
|
342 |
double w = Math.abs(end.getX() - begin.getX()); |
|
343 |
double h = Math.abs(end.getY() - begin.getY()); |
|
344 |
|
|
345 |
//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino |
|
346 |
double stepX = w / ((double)bufWidth); |
|
347 |
double stepY = h / ((double)bufHeight); |
|
348 |
|
|
349 |
//Escritura separada en 5 llamadas para mejorar el rendimiento |
|
350 |
switch(buffer.getDataType()){ |
|
351 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
352 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
353 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
354 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
355 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
|
356 |
} |
|
357 |
|
|
358 |
/*int xPx = 0, yPx = 0; |
|
359 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) { |
|
360 |
yPx = 0; |
|
361 |
for(double row = begin.getY(); yPx < bufHeight; row += stepY) { |
|
362 |
xPx = 0; |
|
363 |
for(double col = begin.getX(); xPx < bufWidth; col += stepX) { |
|
364 |
switch(buffer.getDataType()){ |
|
365 |
case Buffer.TYPE_BYTE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); break; |
|
366 |
case Buffer.TYPE_SHORT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); break; |
|
367 |
case Buffer.TYPE_INT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); break; |
|
368 |
case Buffer.TYPE_FLOAT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); break; |
|
369 |
case Buffer.TYPE_DOUBLE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); break; |
|
370 |
} |
|
371 |
xPx ++; |
|
372 |
} |
|
373 |
yPx ++; |
|
374 |
} |
|
375 |
}*/ |
|
376 |
return rasterBuf; |
|
377 |
} |
|
378 |
|
|
379 |
/** |
|
380 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
381 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
382 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
383 |
* @param rasterBuf Buffer donde se escriben los datos |
|
384 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
385 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
386 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
387 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
388 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
389 |
* del pixel. Esto es util cuando se supersamplea. |
|
390 |
*/ |
|
391 |
private void writeByteBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
392 |
int xPx = 0, yPx = 0; |
|
393 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
394 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
395 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
396 |
continue; |
|
397 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
398 |
yPx = 0; |
|
399 |
for(double row = begin.getY(); (yPx < rasterBuf.getHeight() && row < buffer.getHeight()); row += stepY) { |
|
400 |
xPx = 0; |
|
401 |
for(double col = begin.getX(); (xPx < rasterBuf.getWidth() && col < buffer.getWidth()); col += stepX) { |
|
402 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); |
|
403 |
xPx ++; |
|
404 |
} |
|
405 |
yPx ++; |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
/** |
|
412 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
413 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
414 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
415 |
* @param rasterBuf Buffer donde se escriben los datos |
|
416 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
417 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
418 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
419 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
420 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
421 |
* del pixel. Esto es util cuando se supersamplea. |
|
422 |
*/ |
|
423 |
private void writeShortBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
424 |
int xPx = 0, yPx = 0; |
|
425 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
426 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
427 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
428 |
continue; |
|
429 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
430 |
yPx = 0; |
|
431 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
432 |
xPx = 0; |
|
433 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
434 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); |
|
435 |
xPx ++; |
|
436 |
} |
|
437 |
yPx ++; |
|
438 |
} |
|
439 |
} |
|
440 |
} |
|
441 |
} |
|
442 |
|
|
443 |
/** |
|
444 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
445 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
446 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
447 |
* @param rasterBuf Buffer donde se escriben los datos |
|
448 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
449 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
450 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
451 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
452 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
453 |
* del pixel. Esto es util cuando se supersamplea. |
|
454 |
*/ |
|
455 |
private void writeIntBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
456 |
int xPx = 0, yPx = 0; |
|
457 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
458 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
459 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
460 |
continue; |
|
461 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
462 |
yPx = 0; |
|
463 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
464 |
xPx = 0; |
|
465 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
466 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); |
|
467 |
xPx ++; |
|
468 |
} |
|
469 |
yPx ++; |
|
470 |
} |
|
471 |
} |
|
472 |
} |
|
473 |
} |
|
474 |
|
|
475 |
/** |
|
476 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
477 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
478 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
479 |
* @param rasterBuf Buffer donde se escriben los datos |
|
480 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
481 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
482 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
483 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
484 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
485 |
* del pixel. Esto es util cuando se supersamplea. |
|
486 |
*/ |
|
487 |
private void writeFloatBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
488 |
int xPx = 0, yPx = 0; |
|
489 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
490 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
491 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
492 |
continue; |
|
493 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
494 |
yPx = 0; |
|
495 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
496 |
xPx = 0; |
|
497 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
498 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); |
|
499 |
xPx ++; |
|
500 |
} |
|
501 |
yPx ++; |
|
502 |
} |
|
503 |
} |
|
504 |
} |
|
505 |
} |
|
506 |
|
|
507 |
/** |
|
508 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores |
|
509 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a |
|
510 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento. |
|
511 |
* @param rasterBuf Buffer donde se escriben los datos |
|
512 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario |
|
513 |
* ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino. |
|
514 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario |
|
515 |
* ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino. |
|
516 |
* @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio |
|
517 |
* del pixel. Esto es util cuando se supersamplea. |
|
518 |
*/ |
|
519 |
private void writeDoubleBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
|
520 |
int xPx = 0, yPx = 0; |
|
521 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
522 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
523 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
524 |
continue; |
|
525 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
526 |
yPx = 0; |
|
527 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
|
528 |
xPx = 0; |
|
529 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
|
530 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); |
|
531 |
xPx ++; |
|
532 |
} |
|
533 |
yPx ++; |
|
534 |
} |
|
535 |
} |
|
536 |
} |
|
537 |
} |
|
538 |
|
|
539 |
/* |
|
540 |
* (non-Javadoc) |
|
541 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(int, int, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer) |
|
542 |
*/ |
|
543 |
// public Buffer getWindow(int x, int y, BandList bandList, Buffer rasterBuf) { |
|
544 |
// int w = rasterBuf.getWidth(); |
|
545 |
// int h = rasterBuf.getHeight(); |
|
546 |
// setView( |
|
547 |
// new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
548 |
// getWidth(), |
|
549 |
// getHeight(), |
|
550 |
// new Rectangle2D.Double(x, y, w, h))) |
|
551 |
// ); |
|
552 |
// |
|
553 |
// for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++){ |
|
554 |
// int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
|
555 |
// if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
556 |
// continue; |
|
557 |
// if(buffer.getDataType() == Buffer.TYPE_BYTE) { |
|
558 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
|
559 |
// for(int line = y; line < (y + h); line ++) |
|
560 |
// for(int col = x; col < (x + w); col ++) |
|
561 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemByte(line, col, drawableBands[drawBands])); |
|
562 |
// } |
|
563 |
// }else if(buffer.getDataType() == Buffer.TYPE_SHORT){ |
|
564 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
565 |
// for(int line = y; line < (y + h); line ++) |
|
566 |
// for(int col = x; col < (x + w); col ++) |
|
567 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemShort(line, col, drawableBands[drawBands])); |
|
568 |
// } |
|
569 |
// }else if(buffer.getDataType() == Buffer.TYPE_INT){ |
|
570 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
571 |
// for(int line = y; line < (y + h); line ++) |
|
572 |
// for(int col = x; col < (x + w); col ++) |
|
573 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemInt(line, col, drawableBands[drawBands])); |
|
574 |
// } |
|
575 |
// }else if(buffer.getDataType() == Buffer.TYPE_FLOAT){ |
|
576 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
577 |
// for(int line = y; line < (y + h); line ++) |
|
578 |
// for(int col = x; col < (x + w); col ++) |
|
579 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemFloat(line, col, drawableBands[drawBands])); |
|
580 |
// } |
|
581 |
// }else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
|
582 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){ |
|
583 |
// for(int line = y; line < (y + h); line ++) |
|
584 |
// for(int col = x; col < (x + w); col ++) |
|
585 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemDouble(line, col, drawableBands[drawBands])); |
|
586 |
// } |
|
587 |
// } |
|
588 |
// } |
|
589 |
// return rasterBuf; |
|
590 |
// } |
|
591 |
|
|
592 |
/* |
|
593 |
* (non-Javadoc) |
|
594 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(int, int, int, int, int, int, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer) |
|
595 |
*/ |
|
596 |
public Buffer getWindow(int x, int y, int w, int h, |
|
597 |
BandList bandList, Buffer rasterBuf, TaskStatus status) { |
|
598 |
setView( |
|
599 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
600 |
getWidth(), |
|
601 |
getHeight(), |
|
602 |
new Rectangle2D.Double(x, y, w, h))) |
|
603 |
); |
|
604 |
|
|
605 |
//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino |
|
606 |
double stepX = w / ((double)rasterBuf.getWidth()); |
|
607 |
double stepY = h / ((double)rasterBuf.getHeight()); |
|
608 |
switch(buffer.getDataType()){ |
|
609 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
610 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
611 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
612 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
613 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
|
614 |
} |
|
615 |
return rasterBuf; |
|
616 |
} |
|
617 |
|
|
618 |
/* |
|
619 |
* (non-Javadoc) |
|
620 |
* @see org.gvsig.raster.dataset.RasterDataset#readCompleteLine(int, int) |
|
621 |
*/ |
|
622 |
public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
623 |
switch(buffer.getDataType()){ |
|
624 |
case Buffer.TYPE_BYTE: return buffer.getLineFromBandByte(line, band); |
|
625 |
case Buffer.TYPE_SHORT: return buffer.getLineFromBandShort(line, band); |
|
626 |
case Buffer.TYPE_INT: return buffer.getLineFromBandInt(line, band); |
|
627 |
case Buffer.TYPE_FLOAT: return buffer.getLineFromBandFloat(line, band); |
|
628 |
case Buffer.TYPE_DOUBLE: return buffer.getLineFromBandDouble(line, band); |
|
629 |
} |
|
630 |
return null; |
|
631 |
} |
|
632 |
|
|
633 |
/* |
|
634 |
* (non-Javadoc) |
|
635 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int, double) |
|
636 |
*/ |
|
637 |
public Object readBlock(int pos, int blockHeight, double scale) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
638 |
if(pos < 0) |
|
639 |
throw new InvalidSetViewException("Request out of grid"); |
|
640 |
|
|
641 |
if((pos + blockHeight) > buffer.getHeight()) |
|
642 |
blockHeight = Math.abs(buffer.getHeight() - pos); |
|
643 |
|
|
644 |
switch(buffer.getDataType()){ |
|
645 |
case Buffer.TYPE_BYTE: |
|
646 |
byte[][][] bufb = new byte[getBandCount()][][]; |
|
647 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
648 |
for (int row = 0; row < blockHeight; row++) { |
|
649 |
bufb[iBand][row] = buffer.getLineFromBandByte(row, iBand); |
|
650 |
} |
|
651 |
} |
|
652 |
return bufb; |
|
653 |
case Buffer.TYPE_SHORT: |
|
654 |
short[][][] bufs = new short[getBandCount()][][]; |
|
655 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
656 |
for (int row = 0; row < blockHeight; row++) { |
|
657 |
bufs[iBand][row] = buffer.getLineFromBandShort(row, iBand); |
|
658 |
} |
|
659 |
} |
|
660 |
return bufs; |
|
661 |
case Buffer.TYPE_INT: |
|
662 |
int[][][] bufi = new int[getBandCount()][][]; |
|
663 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
664 |
for (int row = 0; row < blockHeight; row++) { |
|
665 |
bufi[iBand][row] = buffer.getLineFromBandInt(row, iBand); |
|
666 |
} |
|
667 |
} |
|
668 |
return bufi; |
|
669 |
case Buffer.TYPE_FLOAT: |
|
670 |
float[][][] buff = new float[getBandCount()][][]; |
|
671 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
672 |
for (int row = 0; row < blockHeight; row++) { |
|
673 |
buff[iBand][row] = buffer.getLineFromBandFloat(row, iBand); |
|
674 |
} |
|
675 |
} |
|
676 |
return buff; |
|
677 |
case Buffer.TYPE_DOUBLE: |
|
678 |
double[][][] bufd = new double[getBandCount()][][]; |
|
679 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
680 |
for (int row = 0; row < blockHeight; row++) { |
|
681 |
bufd[iBand][row] = buffer.getLineFromBandDouble(row, iBand); |
|
682 |
} |
|
683 |
} |
|
684 |
return bufd; |
|
685 |
} |
|
686 |
return null; |
|
687 |
} |
|
688 |
|
|
689 |
/** |
|
690 |
* Obtiene el objeto que contiene el estado de la transparencia |
|
691 |
*/ |
|
692 |
public DataStoreTransparency getTransparency() { |
|
693 |
if(fileTransparency == null) |
|
694 |
fileTransparency = new DataStoreTransparency(); |
|
695 |
return fileTransparency; |
|
696 |
} |
|
697 |
|
|
698 |
/* |
|
699 |
* (non-Javadoc) |
|
700 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewCount(int) |
|
701 |
*/ |
|
702 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
|
703 |
if(band >= getBandCount()) |
|
704 |
throw new BandAccessException("Wrong band"); |
|
705 |
return 0; |
|
706 |
} |
|
707 |
|
|
708 |
/* |
|
709 |
* (non-Javadoc) |
|
710 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewWidth(int, int) |
|
711 |
*/ |
|
712 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
|
713 |
if (band >= getBandCount()) |
|
714 |
throw new BandAccessException("Wrong band"); |
|
715 |
return 0; |
|
716 |
} |
|
717 |
|
|
718 |
/* |
|
719 |
* (non-Javadoc) |
|
720 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewWidth(int, int) |
|
721 |
*/ |
|
722 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
|
723 |
if (band >= getBandCount()) |
|
724 |
throw new BandAccessException("Wrong band"); |
|
725 |
return 0; |
|
726 |
} |
|
727 |
|
|
728 |
/* |
|
729 |
* (non-Javadoc) |
|
730 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isOverviewsSupported() |
|
731 |
*/ |
|
732 |
public boolean isOverviewsSupported() { |
|
733 |
return false; |
|
734 |
} |
|
735 |
|
|
736 |
/* |
|
737 |
* (non-Javadoc) |
|
738 |
* @see org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider#getName() |
|
739 |
*/ |
|
740 |
public String getName() { |
|
741 |
return NAME; |
|
742 |
} |
|
743 |
|
|
744 |
/* |
|
745 |
* (non-Javadoc) |
|
746 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider) |
|
747 |
*/ |
|
748 |
public void setStatus(RasterProvider provider) { |
|
749 |
if(provider instanceof MemoryRasterProvider) { |
|
750 |
//Not implemented yet |
|
751 |
} |
|
752 |
} |
|
753 |
|
|
754 |
/* |
|
755 |
* (non-Javadoc) |
|
756 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer() |
|
757 |
*/ |
|
758 |
public TileServer getTileServer() { |
|
759 |
return null; |
|
760 |
} |
|
761 |
} |
|
0 | 762 |
org.gvsig.raster.gdal/tags/buildNumber_22/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/memory/io/MemoryDataParameters.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.raster.memory.io; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
32 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
33 |
|
|
34 |
/** |
|
35 |
* Parameters for the memory provider |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class MemoryDataParameters extends AbstractRasterFileDataParameters { |
|
39 |
private final String id = "memory"; |
|
40 |
private Buffer buffer = null; |
|
41 |
private Extent extent = null; |
|
42 |
|
|
43 |
/** |
|
44 |
* Constructor vacio |
|
45 |
*/ |
|
46 |
public MemoryDataParameters() { |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* Contructor |
|
51 |
* @param buf buffer del driver |
|
52 |
* @param ext extensi?n del buffer |
|
53 |
*/ |
|
54 |
public MemoryDataParameters(Buffer buf, Extent ext) { |
|
55 |
this.buffer = buf; |
|
56 |
this.extent = ext; |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Obtiene el buffer de datos |
|
61 |
* @return Buffer |
|
62 |
*/ |
|
63 |
public Buffer getBuffer() { |
|
64 |
return buffer; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Asigna el buffer de datos |
|
69 |
* @param buffer Buffer |
|
70 |
*/ |
|
71 |
public void setBuffer(Buffer buffer) { |
|
72 |
this.buffer = buffer; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Obtiene la extensi?n del buffer de datos |
|
77 |
* @return Extent |
|
78 |
*/ |
|
79 |
public Extent getExtent() { |
|
80 |
return extent; |
|
81 |
} |
|
82 |
|
|
83 |
/**O |
|
84 |
* Asigna la extensi?n del buffer de datos |
|
85 |
* @param extent |
|
86 |
*/ |
|
87 |
public void setExtent(Extent extent) { |
|
88 |
this.extent = extent; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Obtiene el identificador del driver |
|
93 |
* @return String |
|
94 |
*/ |
|
95 |
public String getFormatID() { |
|
96 |
return id; |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName() |
|
102 |
*/ |
|
103 |
public String getDataStoreName() { |
|
104 |
return MemoryRasterProvider.NAME; |
|
105 |
} |
|
106 |
|
|
107 |
/* |
|
108 |
* (non-Javadoc) |
|
109 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDescription() |
|
110 |
*/ |
|
111 |
public String getDescription() { |
|
112 |
return MemoryRasterProvider.DESCRIPTION; |
|
113 |
} |
|
114 |
} |
|
0 | 115 |
org.gvsig.raster.gdal/tags/buildNumber_22/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalProvider.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.gdal.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.awt.geom.Rectangle2D; |
|
27 |
import java.io.BufferedReader; |
|
28 |
import java.io.File; |
|
29 |
import java.io.FileNotFoundException; |
|
30 |
import java.io.FileReader; |
|
31 |
import java.io.IOException; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
|
35 |
import org.gvsig.fmap.dal.DataStore; |
|
36 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
37 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
38 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
39 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
40 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
41 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
42 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
43 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
44 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
45 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
46 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
47 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
48 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
49 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
50 |
import org.gvsig.jgdal.GdalException; |
|
51 |
import org.gvsig.metadata.MetadataLocator; |
|
52 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
53 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
54 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
55 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
|
56 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
57 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
|
58 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
59 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
60 |
import org.gvsig.raster.impl.store.properties.DataStoreMetadata; |
|
61 |
import org.gvsig.tools.ToolsLocator; |
|
62 |
import org.gvsig.tools.dynobject.DynObject; |
|
63 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
64 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
65 |
import org.gvsig.tools.task.TaskStatus; |
|
66 |
import org.slf4j.Logger; |
|
67 |
import org.slf4j.LoggerFactory; |
|
68 |
/** |
|
69 |
* This class represents the data access for gdal formats. |
|
70 |
* |
|
71 |
* @author Luis W. Sevilla |
|
72 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
73 |
*/ |
|
74 |
public class GdalProvider extends DefaultRasterProvider { |
|
75 |
public static String NAME = "Gdal Store"; |
|
76 |
public static String DESCRIPTION = "Gdal Raster file"; |
|
77 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
|
78 |
private static final Logger logger = LoggerFactory.getLogger(GdalProvider.class); |
|
79 |
|
|
80 |
public static final String FORMAT_GTiff = "GTiff"; |
|
81 |
public static final String FORMAT_VRT = "VRT"; |
|
82 |
public static final String FORMAT_NITF = "NITF"; |
|
83 |
public static final String FORMAT_HFA = "HFA"; |
|
84 |
public static final String FORMAT_ELAS = "ELAS"; |
|
85 |
public static final String FORMAT_MEM = "MEM"; |
|
86 |
public static final String FORMAT_BMP = "BMP"; |
|
87 |
public static final String FORMAT_PCIDSK = "PCIDSK"; |
|
88 |
public static final String FORMAT_ILWIS = "ILWIS"; |
|
89 |
public static final String FORMAT_HDF4 = "HDF4Image"; |
|
90 |
public static final String FORMAT_PNM = "PNM"; |
|
91 |
public static final String FORMAT_ENVI = "ENVI"; |
|
92 |
public static final String FORMAT_EHDR = "EHdr"; |
|
93 |
public static final String FORMAT_PAUX = "PAux"; |
|
94 |
public static final String FORMAT_MFF = "MFF"; |
|
95 |
public static final String FORMAT_MFF2 = "MFF2"; |
|
96 |
public static final String FORMAT_BT = "BT"; |
|
97 |
public static final String FORMAT_IDA = "IDA"; |
|
98 |
public static final String FORMAT_RMF = "RMF"; |
|
99 |
public static final String FORMAT_RST = "RST"; |
|
100 |
public static final String FORMAT_LEVELLER = "Leveller"; |
|
101 |
public static final String FORMAT_TERRAGEN = "Terragen"; |
|
102 |
public static final String FORMAT_ERS = "ERS"; |
|
103 |
public static final String FORMAT_INGR = "INGR"; |
|
104 |
public static final String FORMAT_GSAG = "GSAG"; |
|
105 |
public static final String FORMAT_GSBG = "GSBG"; |
|
106 |
public static final String FORMAT_ADRG = "ADRG"; |
|
107 |
public static final int BAND_HEIGHT = 64; |
|
108 |
protected GdalNative file = null; |
|
109 |
private Extent viewRequest = null; |
|
110 |
protected static String[] formatList = null; |
|
111 |
|
|
112 |
public static void register() { |
|
113 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
114 |
registerFormats(); |
|
115 |
|
|
116 |
ExtensionPoint point = extensionPoints.get("DefaultRasterProvider"); |
|
117 |
point.append("reader", GdalProvider.NAME, GdalProvider.class); |
|
118 |
|
|
119 |
RasterLocator.getManager().registerFileProvidersTiled(GdalProvider.class); |
|
120 |
|
|
121 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
122 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
123 |
dataman.registerStoreProvider(NAME, |
|
124 |
GdalProvider.class, GdalDataParameters.class); |
|
125 |
} |
|
126 |
|
|
127 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
128 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
129 |
NAME, DESCRIPTION, |
|
130 |
GdalFilesystemServerExplorer.class); |
|
131 |
|
|
132 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
133 |
} |
|
134 |
|
|
135 |
private static void registerFormats() { |
|
136 |
formatList = new String[] { |
|
137 |
"bmp", |
|
138 |
"gif", |
|
139 |
"tif", |
|
140 |
"tiff", |
|
141 |
"jpg", |
|
142 |
"jpeg", |
|
143 |
"png", |
|
144 |
"vrt", |
|
145 |
"dat", // Envi |
|
146 |
"lan", // Erdas |
|
147 |
"gis", // Erdas |
|
148 |
"img", // Erdas |
|
149 |
"pix", // PCI Geomatics |
|
150 |
"aux", // PCI Geomatics |
|
151 |
"adf", // ESRI Grids |
|
152 |
"mpr", // Ilwis |
|
153 |
"mpl", // Ilwis |
|
154 |
"map", // PC Raster |
|
155 |
"asc", |
|
156 |
"pgm", //Ficheros PNM en escala de grises |
|
157 |
"ppm", //Ficheros PNM en RGB |
|
158 |
"rst", //IDRISIS |
|
159 |
"rmf", //Raster Matrix Format |
|
160 |
"nos", |
|
161 |
"kap", |
|
162 |
"hdr", |
|
163 |
"raw", |
|
164 |
"ers", |
|
165 |
"xml"}; |
|
166 |
for (int i = 0; i < formatList.length; i++) |
|
167 |
RasterLocator.getManager().addFormat(formatList[i], GdalProvider.class); |
|
168 |
} |
|
169 |
|
|
170 |
/* |
|
171 |
* (non-Javadoc) |
|
172 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList() |
|
173 |
*/ |
|
174 |
public String[] getFormatList() { |
|
175 |
return formatList; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Returns true if the extension is supported and false if doesn't |
|
180 |
* @param ext |
|
181 |
* @return |
|
182 |
*/ |
|
183 |
public boolean isExtensionSupported(String ext) { |
|
184 |
if(ext.indexOf(".") != -1) |
|
185 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
|
186 |
for (int i = 0; i < formatList.length; i++) { |
|
187 |
if(formatList[i].compareTo(ext) == 0) |
|
188 |
return true; |
|
189 |
} |
|
190 |
return false; |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Mandatory constructor to instantiate an empty provider |
|
195 |
*/ |
|
196 |
public GdalProvider() { |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Constructor. Abre el dataset. |
|
201 |
* @param proj Proyecci?n |
|
202 |
* @param fName Nombre del fichero |
|
203 |
* @throws NotSupportedExtensionException |
|
204 |
*/ |
|
205 |
public GdalProvider(String params) throws NotSupportedExtensionException { |
|
206 |
super(params); |
|
207 |
if(params instanceof String) { |
|
208 |
GdalDataParameters p = new GdalDataParameters(); |
|
209 |
p.setURI((String)params); |
|
210 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
|
211 |
.createDynObject( |
|
212 |
MetadataLocator.getMetadataManager().getDefinition( |
|
213 |
DataStore.METADATA_DEFINITION_NAME))); |
|
214 |
init(p, null); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
public GdalProvider (GdalDataParameters params, |
|
219 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
|
220 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
221 |
.createDynObject( |
|
222 |
MetadataLocator.getMetadataManager().getDefinition( |
|
223 |
DataStore.METADATA_DEFINITION_NAME))); |
|
224 |
init(params, storeServices); |
|
225 |
} |
|
226 |
|
|
227 |
public GdalProvider(AbstractRasterDataParameters params, |
|
228 |
DataStoreProviderServices storeServices, DynObject metadata) { |
|
229 |
super(params, storeServices, metadata); |
|
230 |
} |
|
231 |
|
|
232 |
/** |
|
233 |
* Creates file references and loads structures with the information and metadata |
|
234 |
* @param params load parameters |
|
235 |
* @throws NotSupportedExtensionException |
|
236 |
*/ |
|
237 |
public void init (AbstractRasterDataParameters params, |
|
238 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
|
239 |
try { |
|
240 |
setParam(storeServices, params); |
|
241 |
validRmf(params.getURI()); |
|
242 |
file = new GdalNative(translateFileName(params.getURI())); |
|
243 |
setColorInterpretation(file.colorInterpr); |
|
244 |
setColorTable(file.palette); |
|
245 |
noData = file.getNoDataValue(); |
|
246 |
wktProjection = file.getProjectionRef(); |
|
247 |
if(wktProjection != null && wktProjection != "") { |
|
248 |
try { |
|
249 |
proj = RasterLocator.getManager().getCRSUtils().convertWktToIProjection(wktProjection); |
|
250 |
} catch (Exception e) { |
|
251 |
logger.info("Error reading WKT from the raster provider", e); |
|
252 |
} |
|
253 |
} |
|
254 |
//CrsWkt crs = new CrsWkt(wktProjection); |
|
255 |
//IProjection proj = CRSFactory.getCRS("EPSG:23030"); |
|
256 |
ownTransformation = file.getOwnTransformation(); |
|
257 |
externalTransformation = (AffineTransform)ownTransformation.clone(); |
|
258 |
load(); |
|
259 |
|
|
260 |
if(file != null) |
|
261 |
bandCount = file.getRasterCount(); |
|
262 |
} catch (GdalException e) { |
|
263 |
throw new NotSupportedExtensionException("Extension not supported", e); |
|
264 |
} catch(Exception e) { |
|
265 |
System.out.println("Error en GdalOpen"); |
|
266 |
e.printStackTrace(); |
|
267 |
file = null; |
|
268 |
} |
|
269 |
|
|
270 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf |
|
271 |
int[] dt = new int[file.getDataType().length]; |
|
272 |
for (int i = 0; i < dt.length; i++) |
|
273 |
dt[i] = rasterUtil.getRasterBufTypeFromGdalType(file.getDataType()[i]); |
|
274 |
setDataType(dt); |
|
275 |
|
|
276 |
super.init(); |
|
277 |
|
|
278 |
try { |
|
279 |
loadFromRmf(getRmfBlocksManager()); |
|
280 |
} catch (ParsingException e) { |
|
281 |
//No lee desde rmf |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Comprueba si el fichero abierto es un RasterMetaFile o una imagen |
|
287 |
* raster. |
|
288 |
* @throws GdalException |
|
289 |
*/ |
|
290 |
private void validRmf(String file) throws GdalException { |
|
291 |
if(file.endsWith(".rmf")) { |
|
292 |
File f = new File(file); |
|
293 |
FileReader fr; |
|
294 |
try { |
|
295 |
fr = new FileReader(f); |
|
296 |
BufferedReader br = new BufferedReader(fr); |
|
297 |
char[] buffer = new char[5]; |
|
298 |
br.read(buffer); |
|
299 |
StringBuffer st = new StringBuffer(new String(buffer)); |
|
300 |
if(st.toString().equals("<?xml")) |
|
301 |
throw new GdalException("RasterMetaFile"); |
|
302 |
} catch (FileNotFoundException e) { |
|
303 |
throw new GdalException("File Not Found"); |
|
304 |
} catch (IOException e) { |
|
305 |
throw new GdalException(""); |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
/* |
|
311 |
* (non-Javadoc) |
|
312 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load() |
|
313 |
*/ |
|
314 |
public RasterProvider load() { |
|
315 |
return this; |
|
316 |
} |
|
317 |
|
|
318 |
/* |
|
319 |
* (non-Javadoc) |
|
320 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen() |
|
321 |
*/ |
|
322 |
public boolean isOpen() { |
|
323 |
if(file != null && file.isOpen()) |
|
324 |
return true; |
|
325 |
return false; |
|
326 |
} |
|
327 |
|
|
328 |
/* |
|
329 |
* (non-Javadoc) |
|
330 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String) |
|
331 |
*/ |
|
332 |
public String translateFileName(String fileName) { |
|
333 |
if(fileName.endsWith("hdr")) |
|
334 |
return fileName.substring(0, fileName.lastIndexOf(".")); |
|
335 |
return fileName; |
|
336 |
} |
|
337 |
|
|
338 |
/** |
|
339 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n |
|
340 |
* de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v) |
|
341 |
* ha de estar en coordenadas del fichero. |
|
342 |
*/ |
|
343 |
public void setView(Extent e) { |
|
344 |
viewRequest = new ExtentImpl(e); |
|
345 |
} |
|
346 |
|
|
347 |
/* |
|
348 |
* (non-Javadoc) |
|
349 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView() |
|
350 |
*/ |
|
351 |
public Extent getView() { |
|
352 |
return viewRequest; |
|
353 |
} |
|
354 |
|
|
355 |
/* |
|
356 |
* (non-Javadoc) |
|
357 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth() |
|
358 |
*/ |
|
359 |
public double getWidth() { |
|
360 |
return file.width; |
|
361 |
} |
|
362 |
|
|
363 |
/* |
|
364 |
* (non-Javadoc) |
|
365 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight() |
|
366 |
*/ |
|
367 |
public double getHeight() { |
|
368 |
return file.height; |
|
369 |
} |
|
370 |
|
|
371 |
/** |
|
372 |
* Read a line from the file |
|
373 |
* @param line |
|
374 |
* @param band |
|
375 |
* @return |
|
376 |
* @throws InvalidSetViewException |
|
377 |
* @throws FileNotOpenException |
|
378 |
* @throws RasterDriverException |
|
379 |
* @Deprecated This operation is deprecated because is not useful and in the future |
|
380 |
* it will not be maintained. The abstract operation has dissapear |
|
381 |
*/ |
|
382 |
public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
383 |
if(line > this.getHeight() || band > this.getBandCount()) |
|
384 |
throw new InvalidSetViewException("Request out of grid"); |
|
385 |
|
|
386 |
try{ |
|
387 |
return file.readCompleteLine(line, band); |
|
388 |
}catch(GdalException e){ |
|
389 |
throw new RasterDriverException("Error reading data from Gdal library"); |
|
390 |
} |
|
391 |
} |
|
392 |
|
|
393 |
/* |
|
394 |
* (non-Javadoc) |
|
395 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int) |
|
396 |
*/ |
|
397 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
398 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
399 |
if(pos < 0) |
|
400 |
throw new InvalidSetViewException("Request out of grid"); |
|
401 |
|
|
402 |
if((pos + blockHeight) > getHeight()) |
|
403 |
blockHeight = Math.abs(((int)getHeight()) - pos); |
|
404 |
try{ |
|
405 |
return file.readBlock(pos, blockHeight, scale); |
|
406 |
}catch(GdalException e){ |
|
407 |
throw new RasterDriverException("Error reading data from Gdal library"); |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
/* |
|
412 |
* (non-Javadoc) |
|
413 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int) |
|
414 |
*/ |
|
415 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
416 |
if(file != null){ |
|
417 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
|
418 |
throw new InvalidSetViewException("Request out of grid"); |
|
419 |
Object[] data = file.getData(x, y); |
|
420 |
return data[band]; |
|
421 |
} |
|
422 |
throw new FileNotOpenException("GdalNative not exist"); |
|
423 |
} |
|
424 |
|
|
425 |
/* |
|
426 |
* (non-Javadoc) |
|
427 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener) |
|
428 |
*/ |
|
429 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
|
430 |
BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
431 |
|
|
432 |
} |
|
433 |
|
|
434 |
/* |
|
435 |
* (non-Javadoc) |
|
436 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
437 |
*/ |
|
438 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) |
|
439 |
throws ProcessInterruptedException, RasterDriverException { |
|
440 |
setView(ex); |
|
441 |
|
|
442 |
try { |
|
443 |
file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), |
|
444 |
rasterBuf.getWidth(), rasterBuf.getHeight(), true, status); |
|
445 |
} catch (GdalException e) { |
|
446 |
throw new RasterDriverException("Error reading data", e); |
|
447 |
} |
|
448 |
|
|
449 |
return rasterBuf; |
|
450 |
} |
|
451 |
|
|
452 |
/* |
|
453 |
* (non-Javadoc) |
|
454 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean) |
|
455 |
*/ |
|
456 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
|
457 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
458 |
//El incremento o decremento de las X e Y depende de los signos de rotaci?n y escala en la matriz de transformaci?n. Por esto |
|
459 |
//tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h |
|
460 |
Extent ext = getExtent(); |
|
461 |
Point2D pInit = rasterToWorld(new Point2D.Double(0, 0)); |
|
462 |
Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight())); |
|
463 |
double wRaster = Math.abs(pEnd.getX() - pInit.getX()); |
|
464 |
double hRaster = Math.abs(pEnd.getY() - pInit.getY()); |
|
465 |
double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w); |
|
466 |
double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h); |
|
467 |
|
|
468 |
Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry); |
|
469 |
setView(selectedExtent); |
|
470 |
|
|
471 |
try { |
|
472 |
file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), |
|
473 |
rasterBuf.getWidth(), rasterBuf.getHeight(), adjustToExtent, status); |
|
474 |
} catch (GdalException e) { |
|
475 |
throw new RasterDriverException("Error reading data"); |
|
476 |
} |
|
477 |
|
|
478 |
return rasterBuf; |
|
479 |
} |
|
480 |
|
|
481 |
/* |
|
482 |
* (non-Javadoc) |
|
483 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean) |
|
484 |
*/ |
|
485 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
486 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
487 |
//draw method |
|
488 |
setView(extent); |
|
489 |
|
|
490 |
double width = 0; |
|
491 |
double height = 0; |
|
492 |
|
|
493 |
Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY()); |
|
494 |
Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY()); |
|
495 |
ul = worldToRaster(ul); |
|
496 |
lr = worldToRaster(lr); |
|
497 |
ul.setLocation(ul.getX() < 0 ? 1 : ul.getX(), ul.getY() < 0 ? 1 : ul.getY()); |
|
498 |
lr.setLocation(lr.getX() < 0 ? 1 : lr.getX(), lr.getY() < 0 ? 1 : lr.getY()); |
|
499 |
|
|
500 |
ul.setLocation(ul.getX() - 0.5, ul.getY() - 0.5); |
|
501 |
lr.setLocation(lr.getX() - 0.5, lr.getY() - 0.5); |
|
502 |
|
|
503 |
adjustPoints(ul, lr); |
|
504 |
|
|
505 |
width = Math.abs(((int)lr.getX()) - ((int)ul.getX())) + 1; |
|
506 |
height = Math.abs(((int)lr.getY()) - ((int)ul.getY())) + 1; |
|
507 |
|
|
508 |
try { |
|
509 |
file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), |
|
510 |
width, height, bufWidth, bufHeight, adjustToExtent, status); |
|
511 |
} catch (GdalException e) { |
|
512 |
throw new RasterDriverException("Error reading data"); |
|
513 |
} |
|
514 |
|
|
515 |
return rasterBuf; |
|
516 |
} |
|
517 |
|
|
518 |
|
|
519 |
private void adjustPoints(Point2D ul, Point2D lr) { |
|
520 |
double a = (ul.getX() - (int)ul.getX()); |
|
521 |
double b = (ul.getY() - (int)ul.getY()); |
|
522 |
ul.setLocation( (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), |
|
523 |
(b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY()); |
|
524 |
lr.setLocation( (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(), |
|
525 |
(b > 0.95 || b < 0.05) ? Math.round(lr.getY()) : lr.getY()); |
|
526 |
} |
|
527 |
|
|
528 |
/* |
|
529 |
* (non-Javadoc) |
|
530 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
531 |
*/ |
|
532 |
public Buffer getWindow(int x, int y, int w, int h, |
|
533 |
BandList bandList, Buffer rasterBuf, TaskStatus status) |
|
534 |
throws ProcessInterruptedException, RasterDriverException { |
|
535 |
try { |
|
536 |
setView( |
|
537 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
538 |
getWidth(), |
|
539 |
getHeight(), |
|
540 |
new Rectangle2D.Double(x, y, w, h))) |
|
541 |
); |
|
542 |
file.readWindow(rasterBuf, bandList, x, y, w, h, status); |
|
543 |
} catch (GdalException e) { |
|
544 |
throw new RasterDriverException("Error reading data"); |
|
545 |
} |
|
546 |
return rasterBuf; |
|
547 |
} |
|
548 |
|
|
549 |
/* |
|
550 |
* (non-Javadoc) |
|
551 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize() |
|
552 |
*/ |
|
553 |
public int getBlockSize(){ |
|
554 |
if(file != null) |
|
555 |
return file.getBlockSize(); |
|
556 |
else |
|
557 |
return 0; |
|
558 |
} |
|
559 |
|
|
560 |
/* |
|
561 |
* (non-Javadoc) |
|
562 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getMetadata() |
|
563 |
*/ |
|
564 |
public DataStoreMetadata getMetadata() { |
|
565 |
if(file != null) |
|
566 |
return file.metadata; |
|
567 |
else |
|
568 |
return null; |
|
569 |
} |
|
570 |
|
|
571 |
/* |
|
572 |
* (non-Javadoc) |
Also available in: Unified diff