Revision 2236 org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataStore.java
AbstractRasterDataStore.java | ||
---|---|---|
40 | 40 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
41 | 41 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
42 | 42 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException; |
43 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
44 | 43 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
45 | 44 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
46 | 45 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
... | ... | |
181 | 180 |
|
182 | 181 |
Buffer buf = null; |
183 | 182 |
|
184 |
if(!q.requestHasShift()) { |
|
183 |
if(q.isSupersamplingOptionActive() && q.isSupersamplingTheRequest()) { |
|
184 |
Supersampling supersampling = new Supersampling(q, this); |
|
185 |
buf = supersampling.query(provider); |
|
186 |
} else if(q.requestHasShift()) { |
|
187 |
FramedBufferResampling framedBufferResampling = new FramedBufferResampling(q, this); |
|
188 |
buf = framedBufferResampling.query(provider); |
|
189 |
} else { |
|
185 | 190 |
q.calculateParameters(this); |
186 | 191 |
try { |
187 | 192 |
buf = ((AbstractRasterProvider)provider).getDataSet(q); |
... | ... | |
190 | 195 |
} |
191 | 196 |
} |
192 | 197 |
|
193 |
//***************************************** |
|
194 |
//Tiled |
|
195 |
//***************************************** |
|
196 |
/*if(q.getType() == DefaultRasterQuery.TYPE_TILED) { |
|
197 |
step = null; |
|
198 |
//dataExtent = new ExtentImpl(q.getRequestBoundingBox().getULX(), q.getRequestBoundingBox().getULY(), |
|
199 |
//q.getRequestBoundingBox().getLRX(), q.getRequestBoundingBox().getLRY()); |
|
200 |
((RasterDataParameters)getParameters()).setAlphaBand(currentQuery.getAlphaBandNumber()); |
|
201 |
getWindowTiled(q); |
|
202 |
}*/ |
|
203 |
|
|
204 | 198 |
result = new Object[]{buf}; |
205 | 199 |
|
206 |
//***************************************** |
|
207 |
//Request only one tile |
|
208 |
//***************************************** |
|
209 |
/*if(q.getType() == DefaultRasterQuery.TYPE_ONE_TILE) { |
|
210 |
if(isTiled()) { |
|
211 |
try { |
|
212 |
Tile t = getTile(q); |
|
213 |
result = t.getData(); |
|
214 |
} catch (TileGettingException e) { |
|
215 |
throw new QueryException("Problems getting the tile", e); |
|
216 |
} |
|
217 |
} else { |
|
218 |
buf = setAreaOfInterestInWC(q); |
|
219 |
buf.setDataExtent(new Rectangle2D.Double(q.getRequestBoundingBox().getULX(), q.getRequestBoundingBox().getULY(), |
|
220 |
q.getRequestBoundingBox().getLRX() - q.getRequestBoundingBox().getULX(), q.getRequestBoundingBox().getLRY() - q.getRequestBoundingBox().getULY())); |
|
221 |
result = new Object[]{buf}; |
|
222 |
} |
|
223 |
}*/ |
|
224 |
|
|
225 | 200 |
if(q.isStoredLastBuffer()) |
226 | 201 |
lastBuffer = buf; |
227 | 202 |
else |
... | ... | |
237 | 212 |
return null; |
238 | 213 |
} |
239 | 214 |
|
240 |
/** |
|
241 |
* Builds a read only buffer |
|
242 |
* @param x |
|
243 |
* @param y |
|
244 |
* @param w |
|
245 |
* @param h |
|
246 |
* @return |
|
247 |
* @throws QueryException |
|
248 |
*/ |
|
249 |
/*private Buffer buildReadOnlyBuffer(int x, int y, int w, int h) throws QueryException { |
|
250 |
Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer( |
|
251 |
getDataType()[0], |
|
252 |
w, |
|
253 |
h, |
|
254 |
getBandCount()); |
|
255 |
try { |
|
256 |
((RasterReadOnlyBuffer)rb).setBufferParams((QueryableRaster)this, |
|
257 |
x, |
|
258 |
y, |
|
259 |
x + w - 1, |
|
260 |
y + h - 1, |
|
261 |
storeBandList); |
|
262 |
} catch (FileNotExistsException e) { |
|
263 |
throw new QueryException("Error setting buffer params in a RO buffer", e); |
|
264 |
} catch (NotSupportedExtensionException e) { |
|
265 |
throw new QueryException("Error setting buffer params in a RO buffer", e); |
|
266 |
} catch (InvalidSetViewException e) { |
|
267 |
throw new QueryException("Error setting buffer params in a RO buffer", e); |
|
268 |
} |
|
269 |
return rb; |
|
270 |
}*/ |
|
271 |
|
|
272 |
|
|
273 |
/** |
|
274 |
* Asigna el ?rea de interes en coordenadas del mundo real. Si las coordenadas exceden del tama?o de la imagen |
|
275 |
* estas coordenadas son ajustadas el extent. |
|
276 |
* @param x Coordenada X, esquina superior izquierda |
|
277 |
* @param y Coordenada Y, esquina superior izquierda |
|
278 |
* @param w Ancho del ?rea |
|
279 |
* @param h Alto del ?rea |
|
280 |
* @throws ArrayIndexOutOfBoundsException |
|
281 |
* @throws InvalidSetViewException |
|
282 |
*/ |
|
283 |
/*protected Buffer setAreaOfInterestInWC(DefaultRasterQuery q) |
|
284 |
throws RasterDriverException, InvalidSetViewException, ProcessInterruptedException { |
|
285 |
if(q.getType() == DefaultRasterQuery.TYPE_WCOORDS) { |
|
286 |
step = null; |
|
287 |
dataExtent = new ExtentImpl(q.getX(), q.getY(), q.getX() + q.getW(), q.getY() - q.getH()); |
|
288 |
Extent adjustedDataExtent = util.calculateAdjustedView(dataExtent, getAffineTransform(), getWidth(), getHeight()); |
|
289 |
q.setAreaOfInterest(adjustedDataExtent.getMin().getX(), adjustedDataExtent.getMax().getY(), adjustedDataExtent.width(), adjustedDataExtent.height()); |
|
290 |
q.setAdjustToExtent(currentQuery.isAdjustToExtent()); |
|
291 |
return getWindowWithoutResampling(q); |
|
292 |
} |
|
293 |
|
|
294 |
if( q.getType() == DefaultRasterQuery.TYPE_WCOORDS_RESCALED || |
|
295 |
q.getType() == DefaultRasterQuery.TYPE_ONE_TILE) { |
|
296 |
step = null; |
|
297 |
dataExtent = q.getRequestBoundingBox();//new ExtentImpl(q.getBBox().getULX(), q.getBBox().getULY(), q.getBBox().getLRX(), q.getBBox().getLRY()); |
|
298 |
Extent adjustedDataExtent = util.calculateAdjustedView(dataExtent, getAffineTransform(), getWidth(), getHeight()); |
|
299 |
|
|
300 |
//Caso 3D: La petici?n no se ajusta al ?rea y se rellena el exterior con NoData |
|
301 |
if(!currentQuery.isAdjustToExtent() && !util.isInside(dataExtent, getExtent())) { |
|
302 |
return requestFillingWithNoData(dataExtent, adjustedDataExtent, q.getBufWidth(), q.getBufHeight()); |
|
303 |
} |
|
304 |
|
|
305 |
q.setRequestBoundingBox(adjustedDataExtent); |
|
306 |
|
|
307 |
//Esta secci?n es para que no supersamplee el driver y pueda hacerse en el cliente |
|
308 |
if(!currentQuery.isSupersamplingLoadingBuffer()) { |
|
309 |
Point2D p1 = worldToRaster(new Point2D.Double(adjustedDataExtent.getULX(), adjustedDataExtent.getULY())); |
|
310 |
Point2D p2 = worldToRaster(new Point2D.Double(adjustedDataExtent.getLRX(), adjustedDataExtent.getLRY())); |
|
311 |
nWidth = Math.abs(p1.getX() - p2.getX()); |
|
312 |
nHeight = Math.abs(p1.getY() - p2.getY()); |
|
313 |
|
|
314 |
if(q.getBufWidth() > Math.ceil(nWidth) && q.getBufHeight() > Math.ceil(nHeight)) { |
|
315 |
step = calcSteps(adjustedDataExtent.getULX(), adjustedDataExtent.getULY(), adjustedDataExtent.getLRX(), adjustedDataExtent.getLRY(), nWidth, nHeight, q.getBufWidth(), q.getBufHeight()); |
|
316 |
q.setBufWidth(-1); |
|
317 |
q.setBufHeight(-1); |
|
318 |
return getWindowWC(q); |
|
319 |
} |
|
320 |
} |
|
321 |
q.setAdjustToExtent(true); |
|
322 |
return getWindowWithResampling(q); |
|
323 |
} |
|
324 |
return null; |
|
325 |
}*/ |
|
326 |
|
|
327 | 215 |
public Extent adjustToExtent(Extent e) { |
328 | 216 |
Extent currentExtent = this.getExtent(); |
329 | 217 |
|
... | ... | |
397 | 285 |
return files; |
398 | 286 |
} |
399 | 287 |
|
400 |
/** |
|
401 |
* M?todo que crea un buffer con la extensi?n que se ha pedido completa y sin ajustar |
|
402 |
* a la extensi?n del raster. La zona que tenga informaci?n del raster se rellenara con |
|
403 |
* esta y la que quede vacia se rellenar? con valores NoData. El ancho y alto del buffer corresponden |
|
404 |
* a toda la zona solicitada, tanto la que cae dentro como la rellena con Nodata |
|
405 |
* |
|
406 |
* @param rasterBuf Buffer de salida. |
|
407 |
* @throws InvalidSetViewException |
|
408 |
*/ |
|
409 |
/*private Buffer requestFillingWithNoData(Extent requestExtent, Extent fitExtent, int bufWidth, int bufHeight) |
|
410 |
throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException { |
|
411 |
double error = 0.01; |
|
412 |
//Upper Left |
|
413 |
double distWcX = Math.abs(fitExtent.getMin().getX() - dataExtent.getMin().getX()); |
|
414 |
distWcX = (distWcX > error) ? distWcX : 0; |
|
415 |
double distWcY = Math.abs(fitExtent.getMax().getY() - dataExtent.getMax().getY()); |
|
416 |
distWcY = (distWcY > error) ? distWcY : 0; |
|
417 |
//Pixel inicial del buffer donde se empieza a dibujar. Redondeamos por arriba pq lo que sobra se pone NoData |
|
418 |
double initPxX = Math.ceil((distWcX * bufWidth) / requestExtent.width()); |
|
419 |
double initPxY = Math.ceil((distWcY * bufHeight) / requestExtent.height()); |
|
420 |
|
|
421 |
//Lower Right |
|
422 |
distWcX = Math.abs(fitExtent.getMax().getX() - dataExtent.getMin().getX()); |
|
423 |
distWcX = (distWcX > error) ? distWcX : 0; |
|
424 |
distWcY = Math.abs(fitExtent.getMin().getY() - dataExtent.getMax().getY()); |
|
425 |
distWcY = (distWcY > error) ? distWcY : 0; |
|
426 |
//Pixel final del buffer donde se dibuja. Redondeamos por abajo pq lo que sobra se pone NoData |
|
427 |
double endPxX = Math.floor((distWcX * bufWidth) / requestExtent.width()); |
|
428 |
double endPxY = Math.floor((distWcY * bufHeight) / requestExtent.height()); |
|
429 |
|
|
430 |
int copyX = (int)Math.abs(endPxX - initPxX); |
|
431 |
int copyY = (int)Math.abs(endPxY - initPxY); |
|
432 |
|
|
433 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
434 |
q.setRequestBoundingBox(fitExtent); |
|
435 |
q.setBufWidth(copyX); |
|
436 |
q.setBufHeight(copyY); |
|
437 |
q.setAdjustToExtent(true); |
|
438 |
Buffer rasterBuf = getWindowWithResampling(q); |
|
439 |
|
|
440 |
Buffer buf = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, rasterBuf.getBandCount(), true); |
|
441 |
buf.setNoDataValue(currentQuery.getNoDataValueToFill()); |
|
442 |
for(int i = 0; i < buf.getBandCount(); i++) { |
|
443 |
switch(buf.getDataType()) { |
|
444 |
case Buffer.TYPE_BYTE:buf.assign(i, |
|
445 |
buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().byteValue() : RasterLibrary.defaultByteNoDataValue); |
|
446 |
break; |
|
447 |
case Buffer.TYPE_SHORT:buf.assign(i, |
|
448 |
buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().shortValue() : RasterLibrary.defaultShortNoDataValue); |
|
449 |
break; |
|
450 |
case Buffer.TYPE_INT:buf.assign(i, |
|
451 |
buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().intValue() : RasterLibrary.defaultIntegerNoDataValue); |
|
452 |
break; |
|
453 |
case Buffer.TYPE_FLOAT:buf.assign(i, |
|
454 |
buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().floatValue() : RasterLibrary.defaultFloatNoDataValue); |
|
455 |
break; |
|
456 |
case Buffer.TYPE_DOUBLE:buf.assign(i, |
|
457 |
buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().doubleValue() : RasterLibrary.defaultDoubleNoDataValue); |
|
458 |
break; |
|
459 |
} |
|
460 |
} |
|
461 |
|
|
462 |
switch(rasterBuf.getDataType()) { |
|
463 |
case Buffer.TYPE_BYTE: |
|
464 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) |
|
465 |
for (int row = 0; row < copyY; row++) |
|
466 |
for (int col = 0; col < copyX; col++) |
|
467 |
buf.setElem((int)(row + initPxY), (int)(col + initPxX), |
|
468 |
iBand, |
|
469 |
rasterBuf.getElemByte(row, col, iBand)); |
|
470 |
break; |
|
471 |
case Buffer.TYPE_SHORT: |
|
472 |
case Buffer.TYPE_USHORT: |
|
473 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) |
|
474 |
for (int row = 0; row < copyY; row++) |
|
475 |
for (int col = 0; col < copyX; col++) |
|
476 |
buf.setElem((int)(row + initPxY), (int)(col + initPxX), |
|
477 |
iBand, |
|
478 |
rasterBuf.getElemShort(row, col, iBand)); |
|
479 |
break; |
|
480 |
case Buffer.TYPE_INT: |
|
481 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) |
|
482 |
for (int row = 0; row < copyY; row++) |
|
483 |
for (int col = 0; col < copyX; col++) |
|
484 |
buf.setElem((int)(row + initPxY), (int)(col + initPxX), |
|
485 |
iBand, |
|
486 |
rasterBuf.getElemInt(row, col, iBand)); |
|
487 |
break; |
|
488 |
case Buffer.TYPE_FLOAT: |
|
489 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) |
|
490 |
for (int row = 0; row < copyY; row++) |
|
491 |
for (int col = 0; col < copyX; col++) |
|
492 |
buf.setElem((int)(row + initPxY), (int)(col + initPxX), |
|
493 |
iBand, |
|
494 |
rasterBuf.getElemFloat(row, col, iBand)); |
|
495 |
break; |
|
496 |
case Buffer.TYPE_DOUBLE: |
|
497 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) |
|
498 |
for (int row = 0; row < copyY; row++) |
|
499 |
for (int col = 0; col < copyX; col++) |
|
500 |
buf.setElem((int)(row + initPxY), (int)(col + initPxX), |
|
501 |
iBand, |
|
502 |
rasterBuf.getElemDouble(row, col, iBand)); |
|
503 |
break; |
|
504 |
} |
|
505 |
return buf; |
|
506 |
}*/ |
|
507 |
|
|
508 | 288 |
public TimeSeries getTimeSerials() throws RmfSerializerException { |
509 | 289 |
if(getProvider() instanceof RasterProvider) |
510 | 290 |
return ((RasterProvider)getProvider()).getTimeSerials(); |
Also available in: Unified diff