gvsig-raster / org.gvsig.raster.gdal / trunk / org.gvsig.raster.gdal / org.gvsig.raster.gdal.io / src / main / java / org / gvsig / raster / memory / io / MemoryRasterProvider.java @ 2885
History | View | Annotate | Download (28.7 KB)
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.coverage.store.props.Transparency; |
39 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
40 |
import org.gvsig.metadata.MetadataLocator; |
41 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
42 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
43 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
44 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
45 |
import org.gvsig.raster.impl.provider.RasterProvider; |
46 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
47 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
48 |
import org.gvsig.tools.ToolsLocator; |
49 |
import org.gvsig.tools.task.TaskStatus; |
50 |
|
51 |
/**
|
52 |
* Driver para datos cargados en un objeto IBuffer
|
53 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
54 |
*
|
55 |
*/
|
56 |
public class MemoryRasterProvider extends AbstractRasterProvider { |
57 |
public static String NAME = "Gdal Store"; |
58 |
public static String DESCRIPTION = "Gdal Raster file"; |
59 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
60 |
|
61 |
private Extent v = null; |
62 |
protected Buffer buffer = null; |
63 |
private Extent extent = null; |
64 |
private boolean open = false; |
65 |
|
66 |
public static void register() { |
67 |
} |
68 |
|
69 |
public void registerTileProviderFormats(Class<RasterProvider> c) { |
70 |
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Mandatory constructor to instantiate an empty provider
|
75 |
*/
|
76 |
public MemoryRasterProvider() {}
|
77 |
|
78 |
/**
|
79 |
* Constructor. Asigna el buffer de datos y la extensi?n
|
80 |
* @param proj Proyecci?n
|
81 |
* @param buf Buffer
|
82 |
* @throws NotSupportedExtensionException
|
83 |
*/
|
84 |
public MemoryRasterProvider(AbstractRasterDataParameters params,
|
85 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
86 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
87 |
.createDynObject( |
88 |
MetadataLocator.getMetadataManager().getDefinition( |
89 |
METADATA_DEFINITION_NAME))); |
90 |
setParam(storeServices, params); |
91 |
if(!(params instanceof MemoryDataParameters)) |
92 |
throw new NotSupportedExtensionException("Buffer not supported"); |
93 |
|
94 |
extent = ((MemoryDataParameters)params).getExtent(); |
95 |
this.buffer = ((MemoryDataParameters)params).getBuffer();
|
96 |
|
97 |
if(extent != null) { |
98 |
double psX = (extent.maxX() - extent.minX()) / buffer.getWidth();
|
99 |
double psY = (extent.minY() - extent.maxY()) / buffer.getHeight();
|
100 |
ownTransformation = new AffineTransform(psX, 0, 0, psY, extent.minX(), extent.maxY()); |
101 |
} else
|
102 |
ownTransformation = new AffineTransform(1, 0, 0, -1, 0, buffer.getHeight()); |
103 |
|
104 |
if(buffer == null) |
105 |
throw new NotSupportedExtensionException("Buffer invalid"); |
106 |
|
107 |
load(); |
108 |
bandCount = buffer.getBandCount(); |
109 |
|
110 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
|
111 |
int[] dt = new int[buffer.getBandCount()]; |
112 |
for (int i = 0; i < dt.length; i++) |
113 |
dt[i] = buffer.getDataType(); |
114 |
setDataType(dt); |
115 |
open = true;
|
116 |
} |
117 |
|
118 |
public RasterProvider load() {
|
119 |
return this; |
120 |
} |
121 |
|
122 |
public boolean isOpen() { |
123 |
return open;
|
124 |
} |
125 |
|
126 |
public void close() { |
127 |
buffer = null;
|
128 |
open = false;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Asigna el extent de la vista actual.
|
133 |
*/
|
134 |
public void setView(Extent e) { |
135 |
v = e; |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Obtiene extent de la vista actual
|
140 |
*/
|
141 |
public Extent getView() {
|
142 |
return v;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Obtiene la anchura del fichero
|
147 |
*/
|
148 |
public double getWidth() { |
149 |
return buffer.getWidth();
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Obtiene la altura del fichero
|
154 |
*/
|
155 |
public double getHeight() { |
156 |
return buffer.getHeight();
|
157 |
} |
158 |
|
159 |
public void reProject(ICoordTrans rp) { |
160 |
} |
161 |
|
162 |
/**
|
163 |
* Obtiene la orientaci?n de la imagen a partir del signo del tama?o de pixel para poder
|
164 |
* asignarlo en el setView. Esto es util para poder conocer como debe leerse la image,
|
165 |
* de abajo a arriba, de arriba a abajo, de izquierda a derecha o de derecha a izquierda.
|
166 |
* La posici?n habitual es la que el pixel size en X es positivo y en Y negativo leyendose
|
167 |
* en este caso las X de menor a mayor y las Y de mayor a menor. Los casos posibles son:
|
168 |
* <UL>
|
169 |
* <LI><B>X > 0; Y < 0;</B> {true, false}</LI>
|
170 |
* <LI><B>X > 0; Y > 0;</B> {true, true}</LI>
|
171 |
* <LI><B>X < 0; Y > 0;</B> {false, true}</LI>
|
172 |
* <LI><B>X < 0; Y < 0;</B> {false, false}</LI>
|
173 |
* </UL>
|
174 |
*
|
175 |
* @return
|
176 |
*/
|
177 |
/*private boolean[] getOrientation(){
|
178 |
boolean[] orientation = {true, false};
|
179 |
return orientation;
|
180 |
}*/
|
181 |
|
182 |
public Object getData(int x, int y, int band) { |
183 |
if(buffer.getDataType() == Buffer.TYPE_BYTE){ |
184 |
return new Integer(buffer.getElemByte(y, x, band)); |
185 |
}else if(buffer.getDataType() == Buffer.TYPE_SHORT){ |
186 |
return new Integer(buffer.getElemShort(y, x, band)); |
187 |
}else if(buffer.getDataType() == Buffer.TYPE_INT){ |
188 |
return new Integer(buffer.getElemInt(y, x, band)); |
189 |
}else if(buffer.getDataType() == Buffer.TYPE_FLOAT){ |
190 |
return new Float(buffer.getElemFloat(y, x, band)); |
191 |
}else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
192 |
return new Double(buffer.getElemDouble(y, x, band)); |
193 |
} |
194 |
return null; |
195 |
} |
196 |
|
197 |
|
198 |
/**
|
199 |
* Devuelve el tama?o de bloque
|
200 |
* @return Tama?o de bloque
|
201 |
*/
|
202 |
public int getBlockSize(){ |
203 |
return 0; |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada
|
208 |
* @return true si est? georreferenciada y false si no lo est?.
|
209 |
*/
|
210 |
public boolean isGeoreferenced() { |
211 |
return (this.extent != null); |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
|
216 |
* el valor de esta variable cada vez que dibuja.
|
217 |
* @return true si se ha supersampleado y false si no se ha hecho.
|
218 |
*/
|
219 |
public boolean isSupersampling() { |
220 |
return false; |
221 |
} |
222 |
|
223 |
/**
|
224 |
* @return Returns the dataType.
|
225 |
*/
|
226 |
public int[] getDataType() { |
227 |
int[] dt = new int[buffer.getBandCount()]; |
228 |
for (int i = 0; i < dt.length; i++) |
229 |
dt[i] = buffer.getDataType(); |
230 |
return dt;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* Ajusta los puntos pasados por par?metro a los l?mites del buffer. Es decir si alguno excede
|
235 |
* los l?mites por arriba o por abajo los ajusta.
|
236 |
* @param begin Punto inicial
|
237 |
* @param end Punto final
|
238 |
*/
|
239 |
private void adjustPointsToBufferLimits(Point2D begin, Point2D end) { |
240 |
if(begin.getX() < 0) |
241 |
begin.setLocation(0, begin.getY());
|
242 |
if(begin.getY() > buffer.getHeight())
|
243 |
begin.setLocation(begin.getX(), buffer.getHeight()); |
244 |
if(end.getY() < 0) |
245 |
end.setLocation(begin.getX(), 0);
|
246 |
if(end.getX() > buffer.getWidth())
|
247 |
begin.setLocation(buffer.getWidth(), begin.getY()); |
248 |
} |
249 |
|
250 |
public void loadBuffer(SpiRasterQuery q) |
251 |
throws ProcessInterruptedException, RasterDriverException {
|
252 |
getWindow(q.getAdjustedRequestBoundingBox(), q.getBandList(), q.getBufferForProviders(), q.getTaskStatus()); |
253 |
} |
254 |
|
255 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) { |
256 |
Point2D begin = worldToRaster(new Point2D.Double(ex.getULX(), ex.getULY())); |
257 |
Point2D end = worldToRaster(new Point2D.Double(ex.getLRX(), ex.getLRY())); |
258 |
setView(ex); |
259 |
|
260 |
adjustPointsToBufferLimits(begin, end); |
261 |
|
262 |
switch(buffer.getDataType()){
|
263 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break; |
264 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break; |
265 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break; |
266 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break; |
267 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break; |
268 |
} |
269 |
return rasterBuf;
|
270 |
} |
271 |
|
272 |
public Buffer getWindow(double x, double y, double w, double h, |
273 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) { |
274 |
Point2D begin = worldToRaster(new Point2D.Double(x, y)); |
275 |
Point2D end = worldToRaster(new Point2D.Double(x + w, y - h)); |
276 |
setView(new ExtentImpl(x, y, x + w, y - h));
|
277 |
|
278 |
adjustPointsToBufferLimits(begin, end); |
279 |
|
280 |
switch(buffer.getDataType()){
|
281 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break; |
282 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break; |
283 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break; |
284 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break; |
285 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break; |
286 |
} |
287 |
return rasterBuf;
|
288 |
} |
289 |
|
290 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
291 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) { |
292 |
Point2D begin = worldToRaster(new Point2D.Double(extent.getMin().getX(), extent.getMax().getY())); |
293 |
Point2D end = worldToRaster(new Point2D.Double(extent.getMax().getX(), extent.getMin().getY())); |
294 |
setView(extent); |
295 |
|
296 |
adjustPointsToBufferLimits(begin, end); |
297 |
|
298 |
//Ancho y alto en pixels (double) del area seleccionada.
|
299 |
double w = Math.abs(end.getX() - begin.getX()); |
300 |
double h = Math.abs(end.getY() - begin.getY()); |
301 |
|
302 |
//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino
|
303 |
double stepX = w / ((double)bufWidth); |
304 |
double stepY = h / ((double)bufHeight); |
305 |
|
306 |
//Escritura separada en 5 llamadas para mejorar el rendimiento
|
307 |
switch(buffer.getDataType()){
|
308 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
309 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
310 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
311 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
312 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, begin, bandList); break; |
313 |
} |
314 |
|
315 |
/*int xPx = 0, yPx = 0;
|
316 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) {
|
317 |
yPx = 0;
|
318 |
for(double row = begin.getY(); yPx < bufHeight; row += stepY) {
|
319 |
xPx = 0;
|
320 |
for(double col = begin.getX(); xPx < bufWidth; col += stepX) {
|
321 |
switch(buffer.getDataType()){
|
322 |
case Buffer.TYPE_BYTE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); break;
|
323 |
case Buffer.TYPE_SHORT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); break;
|
324 |
case Buffer.TYPE_INT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); break;
|
325 |
case Buffer.TYPE_FLOAT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); break;
|
326 |
case Buffer.TYPE_DOUBLE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); break;
|
327 |
}
|
328 |
xPx ++;
|
329 |
}
|
330 |
yPx ++;
|
331 |
}
|
332 |
}*/
|
333 |
return rasterBuf;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
|
338 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
|
339 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento.
|
340 |
* @param rasterBuf Buffer donde se escriben los datos
|
341 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
|
342 |
* 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.
|
343 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
|
344 |
* 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.
|
345 |
* @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
|
346 |
* del pixel. Esto es util cuando se supersamplea.
|
347 |
*/
|
348 |
private void writeByteBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
349 |
int xPx = 0, yPx = 0; |
350 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
351 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
352 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
353 |
continue;
|
354 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
355 |
yPx = 0;
|
356 |
for(double row = begin.getY(); (yPx < rasterBuf.getHeight() && row < buffer.getHeight()); row += stepY) { |
357 |
xPx = 0;
|
358 |
for(double col = begin.getX(); (xPx < rasterBuf.getWidth() && col < buffer.getWidth()); col += stepX) { |
359 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); |
360 |
xPx ++; |
361 |
} |
362 |
yPx ++; |
363 |
} |
364 |
} |
365 |
} |
366 |
} |
367 |
|
368 |
/**
|
369 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
|
370 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
|
371 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento.
|
372 |
* @param rasterBuf Buffer donde se escriben los datos
|
373 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
|
374 |
* 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.
|
375 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
|
376 |
* 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.
|
377 |
* @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
|
378 |
* del pixel. Esto es util cuando se supersamplea.
|
379 |
*/
|
380 |
private void writeShortBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
381 |
int xPx = 0, yPx = 0; |
382 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
383 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
384 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
385 |
continue;
|
386 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
387 |
yPx = 0;
|
388 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
389 |
xPx = 0;
|
390 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
391 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); |
392 |
xPx ++; |
393 |
} |
394 |
yPx ++; |
395 |
} |
396 |
} |
397 |
} |
398 |
} |
399 |
|
400 |
/**
|
401 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
|
402 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
|
403 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento.
|
404 |
* @param rasterBuf Buffer donde se escriben los datos
|
405 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
|
406 |
* 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.
|
407 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
|
408 |
* 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.
|
409 |
* @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
|
410 |
* del pixel. Esto es util cuando se supersamplea.
|
411 |
*/
|
412 |
private void writeIntBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
413 |
int xPx = 0, yPx = 0; |
414 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
415 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
416 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
417 |
continue;
|
418 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
419 |
yPx = 0;
|
420 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
421 |
xPx = 0;
|
422 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
423 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); |
424 |
xPx ++; |
425 |
} |
426 |
yPx ++; |
427 |
} |
428 |
} |
429 |
} |
430 |
} |
431 |
|
432 |
/**
|
433 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
|
434 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
|
435 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento.
|
436 |
* @param rasterBuf Buffer donde se escriben los datos
|
437 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
|
438 |
* 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.
|
439 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
|
440 |
* 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.
|
441 |
* @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
|
442 |
* del pixel. Esto es util cuando se supersamplea.
|
443 |
*/
|
444 |
private void writeFloatBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
445 |
int xPx = 0, yPx = 0; |
446 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
447 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
448 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
449 |
continue;
|
450 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
451 |
yPx = 0;
|
452 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
453 |
xPx = 0;
|
454 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
455 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); |
456 |
xPx ++; |
457 |
} |
458 |
yPx ++; |
459 |
} |
460 |
} |
461 |
} |
462 |
} |
463 |
|
464 |
/**
|
465 |
* Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
|
466 |
* se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
|
467 |
* escribir, el punto inicial en coordenadas pixel (double) y el incremento.
|
468 |
* @param rasterBuf Buffer donde se escriben los datos
|
469 |
* @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
|
470 |
* 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.
|
471 |
* @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
|
472 |
* 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.
|
473 |
* @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
|
474 |
* del pixel. Esto es util cuando se supersamplea.
|
475 |
*/
|
476 |
private void writeDoubleBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) { |
477 |
int xPx = 0, yPx = 0; |
478 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
479 |
int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand); |
480 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
481 |
continue;
|
482 |
for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) { |
483 |
yPx = 0;
|
484 |
for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) { |
485 |
xPx = 0;
|
486 |
for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) { |
487 |
rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); |
488 |
xPx ++; |
489 |
} |
490 |
yPx ++; |
491 |
} |
492 |
} |
493 |
} |
494 |
} |
495 |
|
496 |
/*
|
497 |
* (non-Javadoc)
|
498 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(int, int, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer)
|
499 |
*/
|
500 |
// public Buffer getWindow(int x, int y, BandList bandList, Buffer rasterBuf) {
|
501 |
// int w = rasterBuf.getWidth();
|
502 |
// int h = rasterBuf.getHeight();
|
503 |
// setView(
|
504 |
// new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
|
505 |
// getWidth(),
|
506 |
// getHeight(),
|
507 |
// new Rectangle2D.Double(x, y, w, h)))
|
508 |
// );
|
509 |
//
|
510 |
// for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++){
|
511 |
// int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand);
|
512 |
// if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
|
513 |
// continue;
|
514 |
// if(buffer.getDataType() == Buffer.TYPE_BYTE) {
|
515 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
|
516 |
// for(int line = y; line < (y + h); line ++)
|
517 |
// for(int col = x; col < (x + w); col ++)
|
518 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemByte(line, col, drawableBands[drawBands]));
|
519 |
// }
|
520 |
// }else if(buffer.getDataType() == Buffer.TYPE_SHORT){
|
521 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
|
522 |
// for(int line = y; line < (y + h); line ++)
|
523 |
// for(int col = x; col < (x + w); col ++)
|
524 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemShort(line, col, drawableBands[drawBands]));
|
525 |
// }
|
526 |
// }else if(buffer.getDataType() == Buffer.TYPE_INT){
|
527 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
|
528 |
// for(int line = y; line < (y + h); line ++)
|
529 |
// for(int col = x; col < (x + w); col ++)
|
530 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemInt(line, col, drawableBands[drawBands]));
|
531 |
// }
|
532 |
// }else if(buffer.getDataType() == Buffer.TYPE_FLOAT){
|
533 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
|
534 |
// for(int line = y; line < (y + h); line ++)
|
535 |
// for(int col = x; col < (x + w); col ++)
|
536 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemFloat(line, col, drawableBands[drawBands]));
|
537 |
// }
|
538 |
// }else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){
|
539 |
// for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
|
540 |
// for(int line = y; line < (y + h); line ++)
|
541 |
// for(int col = x; col < (x + w); col ++)
|
542 |
// rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemDouble(line, col, drawableBands[drawBands]));
|
543 |
// }
|
544 |
// }
|
545 |
// }
|
546 |
// return rasterBuf;
|
547 |
// }
|
548 |
|
549 |
public Buffer getWindow(int x, int y, int w, int h, |
550 |
BandList bandList, Buffer rasterBuf, TaskStatus status) {
|
551 |
setView( |
552 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
|
553 |
getWidth(), |
554 |
getHeight(), |
555 |
new Rectangle2D.Double(x, y, w, h))) |
556 |
); |
557 |
|
558 |
//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino
|
559 |
double stepX = w / ((double)rasterBuf.getWidth()); |
560 |
double stepY = h / ((double)rasterBuf.getHeight()); |
561 |
switch(buffer.getDataType()){
|
562 |
case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
563 |
case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
564 |
case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
565 |
case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
566 |
case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break; |
567 |
} |
568 |
return rasterBuf;
|
569 |
} |
570 |
|
571 |
public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
572 |
switch(buffer.getDataType()){
|
573 |
case Buffer.TYPE_BYTE: return buffer.getLineFromBandByte(line, band); |
574 |
case Buffer.TYPE_SHORT: return buffer.getLineFromBandShort(line, band); |
575 |
case Buffer.TYPE_INT: return buffer.getLineFromBandInt(line, band); |
576 |
case Buffer.TYPE_FLOAT: return buffer.getLineFromBandFloat(line, band); |
577 |
case Buffer.TYPE_DOUBLE: return buffer.getLineFromBandDouble(line, band); |
578 |
} |
579 |
return null; |
580 |
} |
581 |
|
582 |
public Object readBlock(int pos, int blockHeight, double scale) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
583 |
if(pos < 0) |
584 |
throw new InvalidSetViewException("Request out of grid"); |
585 |
|
586 |
if((pos + blockHeight) > buffer.getHeight())
|
587 |
blockHeight = Math.abs(buffer.getHeight() - pos);
|
588 |
|
589 |
switch(buffer.getDataType()){
|
590 |
case Buffer.TYPE_BYTE: |
591 |
byte[][][] bufb = new byte[getBandCount()][][]; |
592 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
593 |
for (int row = 0; row < blockHeight; row++) { |
594 |
bufb[iBand][row] = buffer.getLineFromBandByte(row, iBand); |
595 |
} |
596 |
} |
597 |
return bufb;
|
598 |
case Buffer.TYPE_SHORT: |
599 |
short[][][] bufs = new short[getBandCount()][][]; |
600 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
601 |
for (int row = 0; row < blockHeight; row++) { |
602 |
bufs[iBand][row] = buffer.getLineFromBandShort(row, iBand); |
603 |
} |
604 |
} |
605 |
return bufs;
|
606 |
case Buffer.TYPE_INT: |
607 |
int[][][] bufi = new int[getBandCount()][][]; |
608 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
609 |
for (int row = 0; row < blockHeight; row++) { |
610 |
bufi[iBand][row] = buffer.getLineFromBandInt(row, iBand); |
611 |
} |
612 |
} |
613 |
return bufi;
|
614 |
case Buffer.TYPE_FLOAT: |
615 |
float[][][] buff = new float[getBandCount()][][]; |
616 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
617 |
for (int row = 0; row < blockHeight; row++) { |
618 |
buff[iBand][row] = buffer.getLineFromBandFloat(row, iBand); |
619 |
} |
620 |
} |
621 |
return buff;
|
622 |
case Buffer.TYPE_DOUBLE: |
623 |
double[][][] bufd = new double[getBandCount()][][]; |
624 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
625 |
for (int row = 0; row < blockHeight; row++) { |
626 |
bufd[iBand][row] = buffer.getLineFromBandDouble(row, iBand); |
627 |
} |
628 |
} |
629 |
return bufd;
|
630 |
} |
631 |
return null; |
632 |
} |
633 |
|
634 |
/**
|
635 |
* Obtiene el objeto que contiene el estado de la transparencia
|
636 |
*/
|
637 |
public Transparency getTransparency() { |
638 |
if(transparency == null) |
639 |
transparency = new DataStoreTransparency(getColorInterpretation());
|
640 |
return transparency;
|
641 |
} |
642 |
|
643 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
644 |
if(band >= getBandCount())
|
645 |
throw new BandAccessException("Wrong band"); |
646 |
return 0; |
647 |
} |
648 |
|
649 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
650 |
if (band >= getBandCount())
|
651 |
throw new BandAccessException("Wrong band"); |
652 |
return 0; |
653 |
} |
654 |
|
655 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
656 |
if (band >= getBandCount())
|
657 |
throw new BandAccessException("Wrong band"); |
658 |
return 0; |
659 |
} |
660 |
|
661 |
public boolean isOverviewsSupported() { |
662 |
return false; |
663 |
} |
664 |
|
665 |
public String getProviderName() { |
666 |
return NAME;
|
667 |
} |
668 |
|
669 |
public String getName() { |
670 |
return "buffer"+this.hashCode(); |
671 |
} |
672 |
|
673 |
public String getFullName() { |
674 |
return this.getName(); |
675 |
} |
676 |
|
677 |
public void setStatus(RasterProvider provider) { |
678 |
if(provider instanceof MemoryRasterProvider) { |
679 |
//Not implemented yet
|
680 |
} |
681 |
} |
682 |
|
683 |
public TileServer getTileServer() {
|
684 |
return null; |
685 |
} |
686 |
|
687 |
} |