Revision 5461
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/layers/DefaultFLyrRaster.java | ||
---|---|---|
39 | 39 |
import java.util.Set; |
40 | 40 |
|
41 | 41 |
import org.cresques.cts.IProjection; |
42 |
|
|
43 | 42 |
import org.gvsig.compat.print.PrintAttributes; |
44 | 43 |
import org.gvsig.fmap.crs.CRSFactory; |
45 | 44 |
import org.gvsig.fmap.dal.DataStore; |
... | ... | |
133 | 132 |
import org.gvsig.tools.task.SimpleTaskStatus; |
134 | 133 |
import org.gvsig.tools.task.TaskStatusManager; |
135 | 134 |
import org.gvsig.tools.task.impl.BaseTaskStatus; |
136 |
|
|
137 | 135 |
import org.slf4j.Logger; |
138 | 136 |
import org.slf4j.LoggerFactory; |
139 | 137 |
|
... | ... | |
145 | 143 |
@SuppressWarnings("deprecation") |
146 | 144 |
public class DefaultFLyrRaster extends FLyrDefault implements FLyrRaster, Multiresolution, InfoByPoint, Classifiable, |
147 | 145 |
IRasterLayerActions, ILayerState, VisualPropertyListener, SingleLayer { |
148 |
|
|
146 |
|
|
147 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultFLyrRaster.class); |
|
148 |
|
|
149 | 149 |
public static final String PERSISTENT_NAME = "FLyrRasterSE_Persistent"; |
150 | 150 |
public static final String PERSISTENT_DESCRIPTION = "FLyrRasterSE Persistent"; |
151 | 151 |
private RasterManager rManager = RasterLocator.getManager(); |
... | ... | |
525 | 525 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel, double scale) throws ReadException { |
526 | 526 |
TaskEventManager task = rManager.getRasterTask(); |
527 | 527 |
task.setEvent(null); |
528 |
|
|
528 |
|
|
529 | 529 |
if(!layerInitialize) { |
530 | 530 |
if (getDataStore() != null) |
531 | 531 |
try { |
... | ... | |
574 | 574 |
try { |
575 | 575 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
576 | 576 |
draw(image, g, vport, cancel); |
577 |
} catch (InterruptedException e) { |
|
578 |
System.out.println("Se ha cancelado el pintado"); |
|
579 |
} catch (QueryException e) { |
|
580 |
throw new ReadException("Error reading file.", e); |
|
581 |
} catch (NoninvertibleTransformException e) { |
|
582 |
throw new ReadException("Error in the transformation.", e); |
|
583 |
} |
|
577 |
} catch (QueryException | ProcessInterruptedException | NoninvertibleTransformException e) { |
|
578 |
throw new ReadException(getDataStore().getFullName(), e); |
|
579 |
} |
|
584 | 580 |
} else |
585 | 581 |
try { |
586 | 582 |
draw(image, g, vp, cancel); |
587 |
} catch (InterruptedException e) { |
|
588 |
System.out.println("Se ha cancelado el pintado"); |
|
589 |
} catch (QueryException e) { |
|
590 |
throw new ReadException("Error reading file.", e); |
|
583 |
} catch (QueryException | ProcessInterruptedException e) { |
|
584 |
throw new ReadException(getDataStore().getFullName(), e); |
|
591 | 585 |
} |
592 |
|
|
593 | 586 |
} |
594 | 587 |
|
595 | 588 |
//callLegendChanged(null); |
... | ... | |
599 | 592 |
} |
600 | 593 |
} |
601 | 594 |
|
602 |
protected void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) throws QueryException, InterruptedException { |
|
595 |
protected void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) |
|
596 |
throws QueryException, ProcessInterruptedException { |
|
603 | 597 |
Envelope adjustedExtent = vp.getAdjustedExtent(); |
604 | 598 |
if (adjustedExtent == null) |
605 | 599 |
return; |
... | ... | |
619 | 613 |
manager.add(taskStatus); |
620 | 614 |
taskStatus.setAutoremove(true); |
621 | 615 |
|
622 |
//Crea la reproyecci?n al vuelo la primera vez |
|
623 |
RasterDataParameters params = (RasterDataParameters)getDataStore().getParameters(); |
|
624 |
if(!getRender().isReprojectingOnTheFly() && |
|
625 |
getDataStore().getProjection() != null && |
|
626 |
params.getReprojectionOption() == RasterDataParameters.ON_THE_FLY) { |
|
627 |
getRender().createReprojectionOnTheFly(getDataStore(), getCoordTrans(), taskStatus); |
|
628 |
} |
|
629 |
|
|
630 | 616 |
try { |
631 | 617 |
if(getDataStore().isTiled()) { |
632 |
getRender().drawTiledService(g, vp2, vp.getImageSize(), taskStatus); |
|
618 |
getRender().drawTiledService(g, vp2, vp.getImageSize(), this.getCoordTrans(), taskStatus);
|
|
633 | 619 |
} else { |
634 |
getRender().draw(g, vp2, taskStatus); |
|
620 |
getRender().draw(g, vp2, this.getCoordTrans(), taskStatus);
|
|
635 | 621 |
} |
636 |
} catch (ProcessInterruptedException e1) { |
|
637 | 622 |
} finally { |
638 | 623 |
taskStatus.terminate(); |
624 |
taskStatus.remove(); |
|
639 | 625 |
} |
640 | 626 |
} |
641 | 627 |
|
... | ... | |
670 | 656 |
|
671 | 657 |
Rectangle2D e = getDataStore().getExtent().toRectangle2D(); |
672 | 658 |
try { |
673 |
return geomManager.createEnvelope(e.getX(), e.getY(), e.getMaxX(), e
|
|
659 |
Envelope env = geomManager.createEnvelope(e.getX(), e.getY(), e.getMaxX(), e
|
|
674 | 660 |
.getMaxY(), SUBTYPES.GEOM2D); |
675 |
|
|
676 |
/* |
|
677 |
No es necesario |
|
678 |
ICoordTrans ct = getCoordTrans(); |
|
679 |
RasterDataParameters params = (RasterDataParameters)getDataStore().getParameters(); |
|
680 |
if (ct != null && params.getReprojectionOption() == RasterDataParameters.ON_THE_FLY) { |
|
681 |
env = env.convert(ct); |
|
661 |
|
|
662 |
if(this.getCoordTrans() != null){ |
|
663 |
return env.convert(getCoordTrans()); |
|
682 | 664 |
} |
683 |
return env;*/ |
|
684 |
|
|
665 |
return env; |
|
685 | 666 |
} catch (CreateEnvelopeException e1) { |
686 | 667 |
logger.error("Error creating the envelope", e); |
687 | 668 |
return null; |
... | ... | |
1350 | 1331 |
} |
1351 | 1332 |
|
1352 | 1333 |
public AffineTransform getAffineTransform() { |
1353 |
return getDataStore().getAffineTransform(); |
|
1334 |
|
|
1335 |
AffineTransform storeTransformation = this.getDataStore().getAffineTransform(); |
|
1336 |
|
|
1337 |
// If layer is projected on the fly transform affine transform |
|
1338 |
if(this.getCoordTrans() != null){ |
|
1339 |
Envelope fullEnvelope = this.getFullEnvelope(); |
|
1340 |
|
|
1341 |
double newCellSizeX = |
|
1342 |
(fullEnvelope.getMaximum(0) - fullEnvelope.getMinimum(0)) |
|
1343 |
/ getDataStore().getWidth(); |
|
1344 |
double newCellSizeY = |
|
1345 |
(fullEnvelope.getMaximum(1) - fullEnvelope.getMinimum(1)) |
|
1346 |
/ getDataStore().getHeight(); |
|
1347 |
|
|
1348 |
AffineTransform layerTransformation = |
|
1349 |
new AffineTransform(newCellSizeX, storeTransformation.getShearY(), |
|
1350 |
storeTransformation.getShearX(), -newCellSizeY, fullEnvelope.getMinimum(0), |
|
1351 |
fullEnvelope.getMaximum(1)); |
|
1352 |
return layerTransformation; |
|
1353 |
} |
|
1354 |
|
|
1355 |
return storeTransformation; |
|
1354 | 1356 |
} |
1355 | 1357 |
|
1356 | 1358 |
public void setAffineTransform(AffineTransform transf) { |
... | ... | |
1679 | 1681 |
} |
1680 | 1682 |
|
1681 | 1683 |
public RasterDataStore getDataStore() { |
1682 |
if(dataStore != null) { |
|
1683 |
RasterDataParameters params = (RasterDataParameters)dataStore.getParameters(); |
|
1684 |
if (getCoordTrans() != null && params.getReprojectionOption() == RasterDataParameters.ON_THE_FLY) { |
|
1685 |
this.dataStore.setCoordTrans(getCoordTrans()); |
|
1686 |
} |
|
1687 |
} |
|
1688 | 1684 |
return this.dataStore; |
1689 | 1685 |
} |
1690 | 1686 |
|
1691 | 1687 |
public IProjection getProjection() { |
1692 |
if(getDataStore() == null) |
|
1693 |
return null; |
|
1694 |
|
|
1695 |
RasterDataParameters p = (RasterDataParameters)getDataStore().getParameters(); |
|
1696 |
if(p.getReprojectionOption() == RasterDataParameters.DONT_CHANGE_PROJECTION) |
|
1697 |
return null; |
|
1698 | 1688 |
return getDataStore().getProjection(); |
1699 | 1689 |
} |
1700 | 1690 |
|
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/ProcessUtils.java | ||
---|---|---|
183 | 183 |
* @throws ProviderNotRegisteredException |
184 | 184 |
* @throws InitializeException |
185 | 185 |
*/ |
186 |
public boolean exportRaster(final String sFilename, |
|
187 |
Buffer buf, |
|
188 |
double cellsize, |
|
189 |
double minX, |
|
190 |
double minY, |
|
191 |
NoData nodata) { |
|
192 |
boolean result = exportRaster(sFilename, buf, cellsize, minX, minY); |
|
193 |
nodata.setFileName(sFilename); |
|
194 |
nodata.save(); |
|
195 |
return result; |
|
196 |
} |
|
186 |
public boolean exportRaster(final String sFilename, Buffer buf, double cellsize, double minX, |
|
187 |
double minY, NoData nodata) { |
|
188 |
return exportRaster(sFilename, buf, cellsize, minX, minY); |
|
189 |
} |
|
197 | 190 |
|
198 |
/** |
|
199 |
* Exports a raster buffer to disk |
|
200 |
* @param sFilename |
|
201 |
* @param buf |
|
202 |
* @param cellsize |
|
203 |
* @param minX |
|
204 |
* @param minY |
|
205 |
* @return |
|
206 |
*/ |
|
207 |
@SuppressWarnings("deprecation") |
|
208 |
public boolean exportRaster(final String sFilename, |
|
209 |
Buffer buf, |
|
210 |
Buffer alphaBuffer, |
|
211 |
double cellsize, |
|
212 |
double ulx, |
|
213 |
double uly) { |
|
191 |
/** |
|
192 |
* Exports buffer to disk |
|
193 |
* |
|
194 |
* @param sFilename |
|
195 |
* Name of file to write data buffer |
|
196 |
* @param buf |
|
197 |
* data buffer |
|
198 |
* @param cellsize |
|
199 |
* Cell size of new raster |
|
200 |
* @param minX |
|
201 |
* @param minY |
|
202 |
* @param nodata |
|
203 |
* No data value of new raster |
|
204 |
* @param proj |
|
205 |
* Projection of new raster |
|
206 |
* @return |
|
207 |
*/ |
|
208 |
public boolean exportRaster(final String sFilename, Buffer buf, double cellsize, double minX, |
|
209 |
double minY, NoData nodata, IProjection proj) { |
|
210 |
boolean result = exportRaster(sFilename, buf, cellsize, minX, minY, proj); |
|
211 |
nodata.setFileName(sFilename); |
|
212 |
nodata.save(); |
|
213 |
return result; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Export buffer to disk |
|
218 |
* |
|
219 |
* @param sFilename |
|
220 |
* Name of raster file |
|
221 |
* @param buf |
|
222 |
* Buffer data with new data |
|
223 |
* @param alphaBuffer |
|
224 |
* Buffer with alpha data |
|
225 |
* @param cellsize |
|
226 |
* Cell size of new raster |
|
227 |
* @param ulx |
|
228 |
* X coordinate of upper left corner |
|
229 |
* @param uly |
|
230 |
* Y coordinate of upper left corner |
|
231 |
* @param proj |
|
232 |
* Projection of new raster |
|
233 |
* @return |
|
234 |
*/ |
|
235 |
@SuppressWarnings("deprecation") |
|
236 |
public boolean exportRaster(final String sFilename, Buffer buf, Buffer alphaBuffer, |
|
237 |
double cellsize, double ulx, double uly, IProjection proj) { |
|
214 | 238 |
try { |
215 | 239 |
RasterManager manager = RasterLocator.getManager(); |
216 | 240 |
final DataServerWriter writerBufferServer = manager.createDataServerWriter(); |
... | ... | |
243 | 267 |
buf.getHeight(), |
244 | 268 |
buf.getDataType(), |
245 | 269 |
params, |
246 |
null);
|
|
270 |
proj);
|
|
247 | 271 |
if(colorInterpretation != null) |
248 | 272 |
writer.setColorBandsInterpretation(colorInterpretation.getValues()); |
249 | 273 |
writer.dataWrite(); |
... | ... | |
255 | 279 |
return true; |
256 | 280 |
} |
257 | 281 |
|
258 |
/** |
|
259 |
* Exports a raster buffer to disk |
|
260 |
* @param sFilename |
|
261 |
* @param buf |
|
262 |
* @param cellsize |
|
263 |
* @param minX |
|
264 |
* @param minY |
|
265 |
* @return |
|
266 |
*/ |
|
267 |
public boolean exportRaster(final String sFilename, |
|
268 |
Buffer buf, |
|
269 |
double cellsize, |
|
270 |
double ulx, |
|
271 |
double uly) { |
|
282 |
/** |
|
283 |
* Export buffer to disk |
|
284 |
* |
|
285 |
* @param sFilename |
|
286 |
* Name of raster file |
|
287 |
* @param buf |
|
288 |
* Buffer data with new data |
|
289 |
* @param alphaBuffer |
|
290 |
* Buffer with alpha data |
|
291 |
* @param cellsize |
|
292 |
* Cell size of new raster |
|
293 |
* @param ulx |
|
294 |
* X coordinate of upper left corner |
|
295 |
* @param uly |
|
296 |
* Y coordinate of upper left corner |
|
297 |
* @return |
|
298 |
*/ |
|
299 |
public boolean exportRaster(final String sFilename, Buffer buf, Buffer alphaBuffer, |
|
300 |
double cellsize, double ulx, double uly) { |
|
301 |
return exportRaster(sFilename, buf, alphaBuffer, cellsize, ulx, uly, null); |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
* Exports raster buffer to disk |
|
306 |
* |
|
307 |
* @param sFilename |
|
308 |
* Name of raster file |
|
309 |
* @param buf |
|
310 |
* Buffer data with new data |
|
311 |
* @param cellsize |
|
312 |
* Cell size of new raster |
|
313 |
* @param ulx |
|
314 |
* X coordinate of upper left corner |
|
315 |
* @param uly |
|
316 |
* Y coordinate of upper left corner |
|
317 |
* @return |
|
318 |
*/ |
|
319 |
public boolean exportRaster(final String sFilename, Buffer buf, double cellsize, double ulx, |
|
320 |
double uly) { |
|
272 | 321 |
return exportRaster(sFilename, buf, null, cellsize, ulx, uly); |
273 | 322 |
} |
274 | 323 |
|
324 |
/** |
|
325 |
* Exports raster buffer to disk |
|
326 |
* |
|
327 |
* @param sFilename |
|
328 |
* Name of raster file |
|
329 |
* @param buf |
|
330 |
* Buffer data with new data |
|
331 |
* @param cellsize |
|
332 |
* Cell size of new raster |
|
333 |
* @param ulx |
|
334 |
* X coordinate of upper left corner |
|
335 |
* @param uly |
|
336 |
* Y coordinate of upper left corner |
|
337 |
* @param proj |
|
338 |
* Projection of new raster |
|
339 |
* @return |
|
340 |
*/ |
|
341 |
public boolean exportRaster(final String sFilename, Buffer buf, double cellsize, double ulx, |
|
342 |
double uly, IProjection proj) { |
|
343 |
return exportRaster(sFilename, buf, null, cellsize, ulx, uly, proj); |
|
344 |
} |
|
345 |
|
|
275 | 346 |
/** |
276 | 347 |
* Gets a list of rectangles which represents the pixel coordinates of each DataStore. |
277 | 348 |
* This rectangle is the area that intersects with the other DataStores in the list. |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/store/RasterDataStore.java | ||
---|---|---|
532 | 532 |
* @return The default value is false but each driver can change this value. |
533 | 533 |
*/ |
534 | 534 |
public boolean needEnhanced(); |
535 |
|
|
535 |
|
|
536 | 536 |
/** |
537 |
* Sets the transformation |
|
538 |
* @param t |
|
539 |
*/ |
|
540 |
public void setCoordTrans(ICoordTrans t); |
|
541 |
|
|
542 |
/** |
|
543 | 537 |
* Gets the information in a real point |
544 | 538 |
* @param x |
545 | 539 |
* X Pixel position |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/dataset/Buffer.java | ||
---|---|---|
24 | 24 |
import java.awt.geom.Rectangle2D; |
25 | 25 |
import java.awt.image.DataBuffer; |
26 | 26 |
|
27 |
import org.cresques.cts.ICoordTrans; |
|
27 | 28 |
import org.gvsig.fmap.dal.DataSet; |
28 | 29 |
import org.gvsig.fmap.dal.coverage.datastruct.Band; |
30 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
29 | 31 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
30 | 32 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
33 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
31 | 34 |
import org.gvsig.fmap.dal.coverage.process.IncrementableTask; |
32 | 35 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
33 | 36 |
import org.gvsig.fmap.dal.coverage.store.props.Histogramable; |
... | ... | |
492 | 495 |
public IncrementableTask getIncrementableTask(int type); |
493 | 496 |
|
494 | 497 |
public double[][] getAllBandsLimits() throws ProcessInterruptedException; |
498 |
|
|
499 |
/** |
|
500 |
* Project buffer using the coordinate transformation. Coordinate |
|
501 |
* transformation has to define the tranformation between target buffer to |
|
502 |
* source buffer. Result buffer will have extent, width and height received |
|
503 |
* as parameters. If coordinate transform is null, transformation will not |
|
504 |
* be applied and result buffer will have the same data but the extent and |
|
505 |
* size of buffer will be modified. |
|
506 |
* |
|
507 |
* @param coordTrans |
|
508 |
* Coordinate transformation to warp buffer |
|
509 |
* @param extent |
|
510 |
* Extent of projected buffer |
|
511 |
* @param width |
|
512 |
* Width of projected buffer |
|
513 |
* @param height |
|
514 |
* Height of projected buffer |
|
515 |
* @return buffer Buffer projected with extent, width and height received as |
|
516 |
* parameter. |
|
517 |
* @throws WarpException |
|
518 |
* If there are any problem wrapping buffer. |
|
519 |
*/ |
|
520 |
public Buffer project(ICoordTrans coordTrans, Extent extent, int width, int height) throws WarpException; |
|
495 | 521 |
} |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/dataset/AbstractBuffer.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.coverage.dataset; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.awt.geom.NoninvertibleTransformException; |
|
5 |
import java.awt.geom.Point2D; |
|
6 |
import java.awt.geom.Rectangle2D; |
|
7 |
|
|
8 |
import org.cresques.cts.ICoordTrans; |
|
9 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
10 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
11 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
12 |
import org.gvsig.fmap.dal.coverage.exception.BufferCreationException; |
|
13 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
14 |
|
|
15 |
/** |
|
16 |
* Abstract class that implements common functionality to any buffer implementation. |
|
17 |
* |
|
18 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
19 |
* |
|
20 |
*/ |
|
21 |
public abstract class AbstractBuffer implements Buffer { |
|
22 |
|
|
23 |
@Override |
|
24 |
public Buffer project(ICoordTrans coordTrans, Extent extent, int width, int height) |
|
25 |
throws WarpException { |
|
26 |
|
|
27 |
if (this.getDataExtent() == null) { |
|
28 |
throw new IllegalArgumentException( |
|
29 |
"Soruce buffer has to have data extent to be projected"); |
|
30 |
} |
|
31 |
|
|
32 |
if (width <= 0 || height <= 0) { |
|
33 |
throw new IllegalArgumentException( |
|
34 |
"Width or heigth of result buffer can not be 0 or negative"); |
|
35 |
} |
|
36 |
|
|
37 |
Rectangle2D dataExtentRect = this.getDataExtent(); |
|
38 |
Extent sourceExtent = |
|
39 |
RasterLocator.getManager().getDataStructFactory().createExtent(dataExtentRect); |
|
40 |
AffineTransform atSourceBuffer = |
|
41 |
new AffineTransform(sourceExtent.width() / this.getWidth(), 0, 0, |
|
42 |
-sourceExtent.height() / this.getHeight(), sourceExtent.getMin().getX(), |
|
43 |
sourceExtent.getMax().getY()); |
|
44 |
|
|
45 |
BufferParam bufParam = |
|
46 |
RasterLocator.getManager().getBufferFactory() |
|
47 |
.createBufferParams(width, height, this.getBandCount(), this.getDataType(), true); |
|
48 |
Buffer bufReprojected = null; |
|
49 |
try { |
|
50 |
bufReprojected = RasterLocator.getManager().getBufferFactory().createBuffer(bufParam); |
|
51 |
} catch (BufferCreationException e) { |
|
52 |
String msg = |
|
53 |
String.format( |
|
54 |
"Can not create buffer. [parameters width %1s height: %2s bands number %3s" |
|
55 |
+ " data type %4s malloc %5s]", this.getWidth(), this.getHeight(), |
|
56 |
this.getBandCount(), this.getDataType(), true); |
|
57 |
throw new WarpException(msg, e); |
|
58 |
} |
|
59 |
|
|
60 |
AffineTransform atReprojectedBuffer = |
|
61 |
new AffineTransform(extent.width() / width, 0, 0, -extent.height() / height, extent |
|
62 |
.getMin().getX(), extent.getMax().getY()); |
|
63 |
|
|
64 |
try { |
|
65 |
|
|
66 |
NoData noData = this.getNoDataValue(); |
|
67 |
if (noData == null) { |
|
68 |
noData = |
|
69 |
RasterLocator.getManager().getDataStructFactory() |
|
70 |
.createDefaultNoData(this.getBandCount(), this.getDataType()); |
|
71 |
} |
|
72 |
|
|
73 |
for (int row = 0; row < bufReprojected.getHeight(); row++) { |
|
74 |
for (int col = 0; col < bufReprojected.getWidth(); col++) { |
|
75 |
Point2D worldPoint = new Point2D.Double(); |
|
76 |
atReprojectedBuffer.transform(new Point2D.Double(col, row), worldPoint); |
|
77 |
Point2D reprojectedWorldPoint = worldPoint; |
|
78 |
|
|
79 |
// If there is a coordinate transform defined, transforms |
|
80 |
// world point |
|
81 |
if (coordTrans != null) { |
|
82 |
reprojectedWorldPoint = coordTrans.convert(worldPoint, null); |
|
83 |
} |
|
84 |
|
|
85 |
Point2D sourceBufferPoint = new Point2D.Double(); |
|
86 |
atSourceBuffer.inverseTransform(reprojectedWorldPoint, sourceBufferPoint); |
|
87 |
writePixel(bufReprojected.getDataType(), this, bufReprojected, |
|
88 |
bufReprojected.getBandCount(), sourceBufferPoint, col, row, noData); |
|
89 |
} |
|
90 |
} |
|
91 |
} catch (NoninvertibleTransformException e) { |
|
92 |
throw new WarpException(String.format("Can not invert transformation %1s", |
|
93 |
atSourceBuffer), e); |
|
94 |
} |
|
95 |
return bufReprojected; |
|
96 |
} |
|
97 |
|
|
98 |
private void writePixel(int type, Buffer sourceBuffer, Buffer buf, int bandCount, Point2D p, |
|
99 |
int col, int row, NoData nd) { |
|
100 |
if (p.getX() >= 0 && p.getX() < sourceBuffer.getWidth() && p.getY() >= 0 |
|
101 |
&& p.getY() < sourceBuffer.getHeight()) { |
|
102 |
for (int iBand = 0; iBand < bandCount; iBand++) { |
|
103 |
switch (type) { |
|
104 |
case Buffer.TYPE_BYTE: |
|
105 |
buf.setElem(row, col, iBand, |
|
106 |
sourceBuffer.getElemByte((int) p.getY(), (int) p.getX(), iBand)); |
|
107 |
break; |
|
108 |
case Buffer.TYPE_SHORT: |
|
109 |
buf.setElem(row, col, iBand, |
|
110 |
sourceBuffer.getElemShort((int) p.getY(), (int) p.getX(), iBand)); |
|
111 |
break; |
|
112 |
case Buffer.TYPE_INT: |
|
113 |
buf.setElem(row, col, iBand, |
|
114 |
sourceBuffer.getElemInt((int) p.getY(), (int) p.getX(), iBand)); |
|
115 |
break; |
|
116 |
case Buffer.TYPE_FLOAT: |
|
117 |
buf.setElem(row, col, iBand, |
|
118 |
sourceBuffer.getElemFloat((int) p.getY(), (int) p.getX(), iBand)); |
|
119 |
break; |
|
120 |
case Buffer.TYPE_DOUBLE: |
|
121 |
buf.setElem(row, col, iBand, |
|
122 |
sourceBuffer.getElemDouble((int) p.getY(), (int) p.getX(), iBand)); |
|
123 |
break; |
|
124 |
} |
|
125 |
} |
|
126 |
} else { |
|
127 |
for (int iBand = 0; iBand < bandCount; iBand++) { |
|
128 |
switch (type) { |
|
129 |
case Buffer.TYPE_BYTE: |
|
130 |
buf.setElem(row, col, iBand, nd.getValue().byteValue()); |
|
131 |
break; |
|
132 |
case Buffer.TYPE_SHORT: |
|
133 |
buf.setElem(row, col, iBand, nd.getValue().shortValue()); |
|
134 |
break; |
|
135 |
case Buffer.TYPE_INT: |
|
136 |
buf.setElem(row, col, iBand, nd.getValue().intValue()); |
|
137 |
break; |
|
138 |
case Buffer.TYPE_FLOAT: |
|
139 |
buf.setElem(row, col, iBand, nd.getValue().floatValue()); |
|
140 |
break; |
|
141 |
case Buffer.TYPE_DOUBLE: |
|
142 |
buf.setElem(row, col, iBand, nd.getValue().doubleValue()); |
|
143 |
break; |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
} |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/grid/render/Render.java | ||
---|---|---|
36 | 36 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
37 | 37 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
38 | 38 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
39 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
39 | 40 |
import org.gvsig.tools.dispose.Disposable; |
40 | 41 |
import org.gvsig.tools.task.TaskStatus; |
41 | 42 |
|
... | ... | |
199 | 200 |
* @param g Graphics sobre el que se pinta |
200 | 201 |
* @param vp ViewPort de la extensi?n a dibujar |
201 | 202 |
* @param taskStatus |
202 |
* @throws InvalidSetViewException
|
|
203 |
* @throws ArrayIndexOutOfBoundsException
|
|
203 |
* @throws ProcessInterruptedException
|
|
204 |
* @throws QueryException
|
|
204 | 205 |
*/ |
205 | 206 |
public Buffer draw(Graphics2D g, ViewPortData vp, TaskStatus taskStatus) |
206 | 207 |
throws QueryException, ProcessInterruptedException; |
207 | 208 |
|
209 |
/** |
|
210 |
* Dibuja la extensi?n del viewport sobre el graphics aplicando la |
|
211 |
* transformaci?n que recibe como par?metro. |
|
212 |
* |
|
213 |
* @param g |
|
214 |
* Graphics sobre el que se pinta |
|
215 |
* @param vp |
|
216 |
* ViewPort de la extensi?n a dibujar |
|
217 |
* @param coordTrans |
|
218 |
* Transformaci?n a aplicar sobre el buffer antes de ser |
|
219 |
* dibujado. La transformaci?n ser? valida si tiene como |
|
220 |
* proyecci?n fuente la proyecci?n de la extensi?n del ViewPort y |
|
221 |
* como proyecci?n destino la proyecci?n de la fuente de datos. |
|
222 |
* @param taskStatus |
|
223 |
* Objeto compartido para indicar el estado de la tarea |
|
224 |
* @return Si el graphics es null, el buffer proyectado justo antes de ser |
|
225 |
* dibujado, en cualquier otro caso un buffer in?til sin datos. |
|
226 |
* @throws QueryException |
|
227 |
* @throws ProcessInterruptedException |
|
228 |
*/ |
|
229 |
public Buffer draw(Graphics2D g, ViewPortData vp, ICoordTrans coordTrans, TaskStatus taskStatus) |
|
230 |
throws QueryException, ProcessInterruptedException; |
|
231 |
|
|
208 | 232 |
/** |
209 | 233 |
* Este m?todo dibuja sobre el Graphics a partir de un Viewport sin ajustar. Los tiles que van llegando |
210 | 234 |
* no est?n en el tama?o ajustado sino que llegan en su tama?o origina, tipicamente 256x256 p?xeles. Estos |
211 | 235 |
* son reescalados al ir a dibujarlos sobre el Graphics. |
236 |
* |
|
212 | 237 |
* @param g |
213 | 238 |
* @param vp |
214 | 239 |
* @throws RasterDriverException |
... | ... | |
218 | 243 |
public void drawTiledService(Graphics2D g, ViewPortData vp, Dimension2D viewDimension, TaskStatus status) |
219 | 244 |
throws QueryException, ProcessInterruptedException; |
220 | 245 |
|
246 |
/** |
|
247 |
* Dibuja la extensi?n del viewport de forma teselada sobre el graphics |
|
248 |
* aplicando la |
|
249 |
* transformaci?n que recibe como par?metro. |
|
250 |
* |
|
251 |
* @param g |
|
252 |
* Graphics sobre el que se pinta |
|
253 |
* @param vp |
|
254 |
* ViewPort de la extensi?n a dibujar |
|
255 |
* @param viewDimension |
|
256 |
* Dimensi?n de la vista |
|
257 |
* @param coordTrans |
|
258 |
* Transformaci?n a aplicar sobre el buffer antes de ser |
|
259 |
* dibujado. La transformaci?n ser? valida si tiene como |
|
260 |
* proyecci?n fuente la proyecci?n de la extensi?n del ViewPort y |
|
261 |
* como proyecci?n destino la proyecci?n de la fuente de datos. |
|
262 |
* @param status |
|
263 |
* Objeto compartido para indicar el estado de la tarea |
|
264 |
* @throws QueryException |
|
265 |
* @throws ProcessInterruptedException |
|
266 |
*/ |
|
267 |
public void drawTiledService(Graphics2D g, ViewPortData vp, Dimension2D viewDimension, |
|
268 |
ICoordTrans coordTrans, TaskStatus status) throws QueryException, |
|
269 |
ProcessInterruptedException; |
|
270 |
|
|
221 | 271 |
/** |
222 | 272 |
* <p> |
223 | 273 |
* This method throws the draw call in a Thread. This is useful to draw tiles. |
... | ... | |
254 | 304 |
public void setGraphicInfo(Graphics2D g, ViewPortData vp); |
255 | 305 |
|
256 | 306 |
public void setReading(boolean reading); |
257 |
|
|
258 |
public void createReprojectionOnTheFly( |
|
259 |
RasterDataStore store, |
|
260 |
ICoordTrans coordTrans, |
|
261 |
TaskStatus status); |
|
262 |
|
|
263 |
public boolean isReprojectingOnTheFly(); |
|
264 | 307 |
} |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/buffer/RasterBuffer.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.impl.buffer; |
23 | 23 |
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.NoninvertibleTransformException; |
|
26 |
import java.awt.geom.Point2D; |
|
24 | 27 |
import java.awt.geom.Rectangle2D; |
25 | 28 |
|
29 |
import org.cresques.cts.ICoordTrans; |
|
26 | 30 |
import org.gvsig.fmap.dal.DataStore; |
27 | 31 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
32 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
33 |
import org.gvsig.fmap.dal.coverage.dataset.AbstractBuffer; |
|
28 | 34 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
35 |
import org.gvsig.fmap.dal.coverage.dataset.BufferParam; |
|
36 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
29 | 37 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
38 |
import org.gvsig.fmap.dal.coverage.exception.BufferCreationException; |
|
30 | 39 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
40 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
31 | 41 |
import org.gvsig.fmap.dal.coverage.process.IncrementableTask; |
32 | 42 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
33 | 43 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
... | ... | |
44 | 54 |
* m[0] = matriz cuadrada; -> Sustituye la banda entera. |
45 | 55 |
* |
46 | 56 |
*/ |
47 |
public abstract class RasterBuffer implements Buffer { |
|
57 |
public abstract class RasterBuffer extends AbstractBuffer implements Buffer {
|
|
48 | 58 |
public static final int INTERPOLATION_PROCESS = 0; |
49 | 59 |
|
50 | 60 |
protected boolean[] cancel = new boolean[1]; |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/buffer/cache/PageBuffer.java | ||
---|---|---|
24 | 24 |
import java.awt.geom.Rectangle2D; |
25 | 25 |
import java.io.IOException; |
26 | 26 |
|
27 |
import org.cresques.cts.ICoordTrans; |
|
27 | 28 |
import org.gvsig.fmap.dal.DataStore; |
29 |
import org.gvsig.fmap.dal.coverage.dataset.AbstractBuffer; |
|
28 | 30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
29 | 31 |
import org.gvsig.fmap.dal.coverage.datastruct.Band; |
32 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
30 | 33 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
31 | 34 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
35 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
32 | 36 |
import org.gvsig.fmap.dal.coverage.process.IncrementableTask; |
33 | 37 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
34 | 38 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
... | ... | |
47 | 51 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
48 | 52 |
* |
49 | 53 |
*/ |
50 |
public class PageBuffer implements Buffer { |
|
54 |
public class PageBuffer extends AbstractBuffer implements Buffer {
|
|
51 | 55 |
private PageBandBuffer[] pageBandBuffer = null; |
52 | 56 |
private double[] limits = null; |
53 | 57 |
private HistogramComputer histogramComputer = null; |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/AbstractRasterProvider.java | ||
---|---|---|
116 | 116 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
117 | 117 |
*/ |
118 | 118 |
public abstract class AbstractRasterProvider extends AbstractCoverageStoreProvider implements RasterProvider { |
119 |
|
|
120 |
private static final Logger LOG = LoggerFactory.getLogger(AbstractRasterProvider.class); |
|
121 |
|
|
119 | 122 |
/** |
120 | 123 |
* Flags que representan a las bandas visualizables |
121 | 124 |
*/ |
... | ... | |
175 | 178 |
} |
176 | 179 |
uri = translateURI(uri); |
177 | 180 |
} |
181 |
|
|
182 |
// If there is a defined SRS, set it to provider. This must be override |
|
183 |
// if provider is georeferenced. |
|
184 |
if(params != null && params.getSRS() != null){ |
|
185 |
try { |
|
186 |
this.setProjection(params.getSRS(), false); |
|
187 |
} catch (RmfSerializerException e) { |
|
188 |
LOG.warn("Can not persist {} parameter projection to {} provider", |
|
189 |
new Object[] { params.getSRSID(), this.getName() }); |
|
190 |
} |
|
191 |
} |
|
178 | 192 |
|
179 | 193 |
ownTransformation = new AffineTransform(); |
180 | 194 |
externalTransformation = new AffineTransform(); |
... | ... | |
183 | 197 |
public AbstractRasterProvider(DataStoreParameters params, |
184 | 198 |
DataStoreProviderServices storeServices, DynObject metadata) { |
185 | 199 |
super(params, storeServices, metadata); |
186 |
URI uriParam = ((RasterDataParameters)params).getURI(); |
|
200 |
RasterDataParameters rasterParameters = (RasterDataParameters) params; |
|
201 |
URI uriParam = rasterParameters.getURI(); |
|
187 | 202 |
if(uriParam != null) { |
188 | 203 |
if ("FILE".equalsIgnoreCase(uriParam.getScheme())) { |
189 | 204 |
File f = new File(uriParam); |
... | ... | |
193 | 208 |
if(params instanceof RemoteStoreParameters) |
194 | 209 |
uri = translateURI(uriParam); |
195 | 210 |
} |
211 |
|
|
212 |
if(rasterParameters != null && rasterParameters.getSRS() != null){ |
|
213 |
try { |
|
214 |
this.setProjection(rasterParameters.getSRS(), false); |
|
215 |
} catch (RmfSerializerException e) { |
|
216 |
LOG.warn("Can not persist {} parameter projection to {} provider", |
|
217 |
new Object[] { rasterParameters.getSRSID(), this.getName() }); |
|
218 |
} |
|
219 |
} |
|
196 | 220 |
|
197 | 221 |
ownTransformation = new AffineTransform(); |
198 | 222 |
externalTransformation = new AffineTransform(); |
... | ... | |
622 | 646 |
} |
623 | 647 |
return new File(rmfFolder.getAbsolutePath() + File.separator + fileName + tail); |
624 | 648 |
} |
625 |
return new File(getRMFFileForRemoteServices(getName())); |
|
626 |
// return null; |
|
649 |
return null; |
|
627 | 650 |
} |
628 | 651 |
|
629 | 652 |
protected String getRMFFileForRemoteServices(String layerName) { |
630 | 653 |
String md5 = ""; |
631 | 654 |
try { |
632 |
md5 = RasterLocator.getManager().getFileUtils().convertPathToMD5(uri.toString());
|
|
655 |
md5 = RasterLocator.getManager().getFileUtils().convertPathToMD5(new File(uri).getAbsolutePath());
|
|
633 | 656 |
} catch (LocatorException e) { |
634 | 657 |
logger.debug("Error getting the Locator", e); |
635 | 658 |
} catch (NoSuchAlgorithmException e) { |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataStore.java | ||
---|---|---|
127 | 127 |
private DelegateWeakReferencingObservable |
128 | 128 |
delegateObservable = new DelegateWeakReferencingObservable(this); |
129 | 129 |
private Render render = null; |
130 |
protected ICoordTrans coordTrans = null; |
|
131 | 130 |
protected RasterDataServerExplorer explorer = null; |
132 | 131 |
|
133 | 132 |
public BandList getDefaultBandList() { |
... | ... | |
605 | 604 |
public DataStore getStore() { |
606 | 605 |
return this; |
607 | 606 |
} |
608 |
|
|
609 |
public void setCoordTrans(ICoordTrans t) { |
|
610 |
this.coordTrans = t; |
|
611 |
} |
|
612 |
|
|
607 |
|
|
613 | 608 |
public void close() { |
614 | 609 |
if(lastBuffer != null) { |
615 | 610 |
lastBuffer.dispose(); |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataParameters.java | ||
---|---|---|
50 | 50 |
private static final String FIELD_VISIBLE = "visible"; |
51 | 51 |
private static final String FIELD_REPROJ_OPTION = "selected_option"; |
52 | 52 |
|
53 |
protected IProjection crs = null; |
|
54 |
|
|
55 | 53 |
/** |
56 | 54 |
* @param definition |
57 | 55 |
*/ |
... | ... | |
91 | 89 |
.setMandatory(false) |
92 | 90 |
.setHidden(true); |
93 | 91 |
|
94 |
/*definition.addDynFieldObject(FIELD_CRS)
|
|
95 |
.setDescription("CRS") |
|
96 |
.setMandatory(false)
|
|
97 |
.setHidden(true);*/
|
|
92 |
definition.addDynFieldObject(FIELD_CRS) |
|
93 |
.setDescription("CRS").
|
|
94 |
setType(org.cresques.DataTypes.CRS).
|
|
95 |
setMandatory(false);
|
|
98 | 96 |
} |
99 | 97 |
|
100 | 98 |
public void assignFields(RasterDataParameters par, RasterDataServerExplorer explorer) { |
... | ... | |
104 | 102 |
setAlphaBand(par.getAlphaBand()); |
105 | 103 |
setFrame(par.getFrame()); |
106 | 104 |
setURI(par.getURI()); |
105 |
setSRS(par.getSRS()); |
|
107 | 106 |
} |
108 | 107 |
|
109 | 108 |
/** |
... | ... | |
145 | 144 |
} |
146 | 145 |
|
147 | 146 |
public String getSRSID() { |
148 |
if (crs == null) { |
|
149 |
return null; |
|
150 |
} |
|
151 |
return crs.getAbrev(); |
|
147 |
return getSRS() != null ? getSRS().getAbrev() : null; |
|
152 | 148 |
} |
153 | 149 |
|
154 | 150 |
public void setSRSID(String srsid) { |
155 | 151 |
if (srsid == null) { |
156 |
crs = null;
|
|
152 |
setSRS(null);
|
|
157 | 153 |
} else { |
158 |
crs = CRSFactory.getCRS(srsid);
|
|
154 |
setSRS(CRSFactory.getCRS(srsid));
|
|
159 | 155 |
} |
160 | 156 |
} |
161 | 157 |
|
162 | 158 |
public void setSRS(IProjection srs) { |
163 |
this.crs = srs;
|
|
159 |
this.setDynValue(FIELD_CRS, srs);
|
|
164 | 160 |
} |
165 | 161 |
|
166 | 162 |
public IProjection getSRS() { |
167 |
if (this.getSRSID() == null) { |
|
168 |
return null; |
|
169 |
} |
|
170 |
return crs; |
|
163 |
return (IProjection) this.getDynValue(FIELD_CRS); |
|
171 | 164 |
} |
172 | 165 |
|
173 | 166 |
/** |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/DefaultRasterStore.java | ||
---|---|---|
256 | 256 |
} |
257 | 257 |
|
258 | 258 |
public Extent getExtent() { |
259 |
Extent e = provider.getExtent(); |
|
260 |
if (coordTrans != null) { |
|
261 |
e = e.convert(coordTrans); |
|
262 |
} |
|
263 |
return e; |
|
259 |
return provider.getExtent(); |
|
264 | 260 |
} |
265 | 261 |
|
266 | 262 |
/** |
... | ... | |
490 | 486 |
|
491 | 487 |
public AffineTransform getAffineTransform() { |
492 | 488 |
if(provider != null) { |
493 |
AffineTransform at = provider.getAffineTransform(); |
|
494 |
/*if (coordTrans != null) { |
|
495 |
Point2D scale = new Point2D.Double(at.getTranslateX() + at.getScaleX(), at.getTranslateY() + at.getScaleY()); |
|
496 |
Point2D translate = new Point2D.Double(at.getTranslateX(), at.getTranslateY()); |
|
497 |
scale = coordTrans.convert(scale, scale); |
|
498 |
translate = coordTrans.convert(translate, translate); |
|
499 |
double sX = scale.getX() - translate.getX(); |
|
500 |
double sY = scale.getY() - translate.getY(); |
|
501 |
at = new AffineTransform( |
|
502 |
sX, |
|
503 |
at.getShearY(), |
|
504 |
at.getShearX(), |
|
505 |
sY, |
|
506 |
translate.getX(), |
|
507 |
translate.getY()); |
|
508 |
}*/ |
|
509 |
return at; |
|
489 |
return provider.getAffineTransform(); |
|
510 | 490 |
} |
511 | 491 |
return null; |
512 | 492 |
} |
... | ... | |
1051 | 1031 |
//Esto solo es por si al cargar un proyecto se ha cambiado el fichero de sitio y el usuario |
1052 | 1032 |
//lo introduce manualmente. En ese caso el bandList debe contener la misma ruta al fichero que el |
1053 | 1033 |
//provider y no la que se grab? inicialmente |
1054 |
try{ |
|
1055 |
for (int i = 0; i < storeBandList.getBandCount(); i++) { |
|
1056 |
storeBandList.getBand(i).setFileName(new File(provider.getURI()).getAbsolutePath()); |
|
1057 |
} |
|
1058 |
}catch (Exception e){ |
|
1059 |
logger.warn("Couldn't get file for "+provider.getURI()+" when creating Band List Store"); |
|
1060 |
} |
|
1034 |
for (int i = 0; i < storeBandList.getBandCount(); i++) { |
|
1035 |
storeBandList.getBand(i).setFileName(new File(provider.getURI()).getAbsolutePath()); |
|
1036 |
} |
|
1061 | 1037 |
} |
1062 | 1038 |
this.metadata = (Metadata)state.get("metadata"); |
1063 | 1039 |
|
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/datastruct/ExtentImpl.java | ||
---|---|---|
28 | 28 |
import java.text.DecimalFormat; |
29 | 29 |
|
30 | 30 |
import org.cresques.cts.ICoordTrans; |
31 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
31 | 32 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
32 | 33 |
import org.gvsig.fmap.dal.coverage.datastruct.GridExtent; |
34 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
35 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
36 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
37 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
33 | 38 |
import org.gvsig.raster.impl.grid.GridExtentImpl; |
34 | 39 |
import org.gvsig.tools.ToolsLocator; |
35 | 40 |
import org.gvsig.tools.dynobject.DynStruct; |
41 |
import org.gvsig.tools.locator.LocatorException; |
|
36 | 42 |
import org.gvsig.tools.persistence.PersistenceManager; |
37 | 43 |
import org.gvsig.tools.persistence.PersistentState; |
38 | 44 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
39 | 47 |
|
40 | 48 |
/** |
41 | 49 |
* Clase que getiona el extent de una imagen |
... | ... | |
43 | 51 |
* @author Luis W.Sevilla (sevilla_lui@gva.es) |
44 | 52 |
*/ |
45 | 53 |
public class ExtentImpl implements Extent { |
54 |
|
|
55 |
private static final Logger LOG = LoggerFactory.getLogger(ExtentImpl.class); |
|
56 |
|
|
46 | 57 |
public static final String PERSISTENT_NAME = "Extent_Persistent"; |
47 | 58 |
public static final String PERSISTENT_DESCRIPTION = "Extent Persistent"; |
48 | 59 |
|
... | ... | |
482 | 493 |
} |
483 | 494 |
|
484 | 495 |
public Extent convert(ICoordTrans trans) { |
485 |
Rectangle2D rect = new Rectangle2D.Double(getURX(), getLRY(), width(), height()); |
|
486 |
Rectangle2D rectDest = trans.convert(rect); |
|
487 |
if (rectDest == null){ |
|
488 |
return null; |
|
489 |
} |
|
490 |
|
|
491 |
return new ExtentImpl( |
|
492 |
rectDest.getMinX(), |
|
493 |
rectDest.getMaxY(), |
|
494 |
rectDest.getMaxX(), |
|
495 |
rectDest.getMinY()); |
|
496 |
try { |
|
497 |
Envelope envelope = GeometryLocator.getGeometryManager().createEnvelope(getMin().getX(), |
|
498 |
getMin().getY(), getMax().getX(), getMax().getY(), SUBTYPES.GEOM2D); |
|
499 |
envelope = envelope.convert(trans); |
|
500 |
|
|
501 |
Point2D ul = new Point2D.Double(envelope.getMinimum(0), envelope.getMaximum(1)); |
|
502 |
Point2D lr = new Point2D.Double(envelope.getMaximum(0), envelope.getMinimum(1)); |
|
503 |
|
|
504 |
return RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr); |
|
505 |
} catch (LocatorException | CreateEnvelopeException e) { |
|
506 |
LOG.error("Can not convert data extent. []"); |
|
507 |
return null; |
|
508 |
} |
|
496 | 509 |
} |
497 | 510 |
|
498 | 511 |
public boolean equals(Object obj) { |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/render/DefaultRender.java | ||
---|---|---|
42 | 42 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
43 | 43 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
44 | 44 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
45 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
45 | 46 |
import org.gvsig.fmap.dal.coverage.filter.FilterLoader; |
46 | 47 |
import org.gvsig.fmap.dal.coverage.grid.FilterListChangeEvent; |
47 | 48 |
import org.gvsig.fmap.dal.coverage.grid.FilterListChangeListener; |
... | ... | |
76 | 77 |
import org.gvsig.tools.persistence.PersistentState; |
77 | 78 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
78 | 79 |
import org.gvsig.tools.task.TaskStatus; |
80 |
import org.slf4j.Logger; |
|
79 | 81 |
import org.slf4j.LoggerFactory; |
80 | 82 |
/** |
81 | 83 |
* Esta clase se encarga de la gesti?n del dibujado de datos le?dos desde la capa |
... | ... | |
99 | 101 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
100 | 102 |
*/ |
101 | 103 |
public class DefaultRender implements Render, PropertyListener, FilterListChangeListener, Persistent, TileListener { |
104 |
|
|
105 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultRender.class); |
|
106 |
|
|
102 | 107 |
/** |
103 | 108 |
* Fuente de datos para el renderizado |
104 | 109 |
*/ |
... | ... | |
141 | 146 |
|
142 | 147 |
private Graphics2D lastGraphics = null; |
143 | 148 |
private ViewPortData lastViewPortData = null; |
149 |
private ICoordTrans lastCoordTrans = null; |
|
144 | 150 |
private Dimension2D viewDimension = null; |
145 |
private RasterRenderReprojection
|
|
146 |
reprojectionOnTheFly = null;
|
|
151 |
private boolean
|
|
152 |
reprojectionOnTheFly = false;
|
|
147 | 153 |
private RasterManager rManager = null; |
148 | 154 |
|
149 | 155 |
/** |
... | ... | |
155 | 161 |
|
156 | 162 |
/** |
157 | 163 |
* Constructor |
158 |
* @param grid
|
|
164 |
* @param ds
|
|
159 | 165 |
*/ |
160 | 166 |
public DefaultRender(RasterDataStore ds) { |
161 | 167 |
this.dataStore = ds; |
... | ... | |
168 | 174 |
return rManager; |
169 | 175 |
} |
170 | 176 |
|
171 |
public void createReprojectionOnTheFly( |
|
172 |
RasterDataStore store, |
|
173 |
ICoordTrans coordTrans, |
|
174 |
TaskStatus status) { |
|
175 |
reprojectionOnTheFly = new RasterRenderReprojection( |
|
176 |
store, coordTrans, status); |
|
177 |
} |
|
178 |
|
|
179 |
public boolean isReprojectingOnTheFly() { |
|
180 |
return reprojectionOnTheFly != null; |
|
181 |
} |
|
182 |
|
|
183 | 177 |
public RasterDataStore getDataStore() { |
184 | 178 |
return this.dataStore; |
185 | 179 |
} |
... | ... | |
223 | 217 |
*/ |
224 | 218 |
public void run() { |
225 | 219 |
try { |
226 |
draw(lastGraphics, lastViewPortData, null); |
|
220 |
draw(lastGraphics, lastViewPortData, lastCoordTrans, null);
|
|
227 | 221 |
} catch (QueryException e) { |
228 | 222 |
LoggerFactory.getLogger(getClass()).debug("Error in a query", e); |
229 | 223 |
} catch (ProcessInterruptedException e) { |
... | ... | |
255 | 249 |
|
256 | 250 |
public synchronized Buffer getLastRenderBuffer() |
257 | 251 |
throws QueryException, ProcessInterruptedException { |
258 |
return draw(null, lastViewPortData, null); |
|
252 |
return draw(null, lastViewPortData, lastCoordTrans, null);
|
|
259 | 253 |
} |
260 | 254 |
|
261 |
public synchronized void drawTiledService(Graphics2D g, |
|
262 |
ViewPortData vp, |
|
263 |
Dimension2D viewDimension, |
|
264 |
TaskStatus taskStatus) |
|
265 |
throws QueryException, ProcessInterruptedException { |
|
255 |
public synchronized void drawTiledService(Graphics2D g, ViewPortData vp, |
|
256 |
Dimension2D viewDimension, ICoordTrans coordTrans, TaskStatus taskStatus) |
|
257 |
throws QueryException, ProcessInterruptedException { |
|
266 | 258 |
lastGraphics = g; |
267 | 259 |
lastViewPortData = vp; |
260 |
lastCoordTrans = coordTrans; |
|
268 | 261 |
this.viewDimension = viewDimension; |
269 | 262 |
int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
270 | 263 |
|
271 |
if(util.isOutside(vp.getExtent(), dataStore.getExtent())) { |
|
264 |
Extent extent = dataStore.getExtent(); |
|
265 |
if(coordTrans != null){ |
|
266 |
extent = extent.convert(coordTrans); |
|
267 |
} |
|
268 |
|
|
269 |
if(util.isOutside(vp.getExtent(), extent)) { |
|
272 | 270 |
endReading(); |
273 | 271 |
return; |
274 | 272 |
} |
... | ... | |
293 | 291 |
query.forceARGBRequest(); |
294 | 292 |
} else |
295 | 293 |
query.forceRGBRequest(); |
296 |
query.setAreaOfInterest(vp.getExtent(), |
|
294 |
|
|
295 |
Extent areaOfInterest = vp.getExtent(); |
|
296 |
if(coordTrans != null){ |
|
297 |
|
|
298 |
areaOfInterest = vp.getExtent().convert(coordTrans.getInverted()); |
|
299 |
} |
|
300 |
|
|
301 |
query.setAreaOfInterest(areaOfInterest, |
|
297 | 302 |
(int)Math.round(vp.getWidth()), |
298 | 303 |
(int)Math.round(vp.getHeight()), this); |
299 | 304 |
dataStore.query(query); |
... | ... | |
308 | 313 |
double[] step = (double[])loadedTile.getDownloaderParams("Step"); |
309 | 314 |
AffineTransform transf = (AffineTransform)loadedTile.getDownloaderParams("AffineTransform"); |
310 | 315 |
|
311 |
Extent e = getRasterManager().getDataStructFactory().
|
|
316 |
Extent tileExtent = getRasterManager().getDataStructFactory().
|
|
312 | 317 |
createExtent(loadedTile.getUl().getX(), |
313 | 318 |
loadedTile.getUl().getY(), |
314 | 319 |
loadedTile.getLr().getX(), |
... | ... | |
330 | 335 |
addTileColorTable(tileColorTable); |
331 | 336 |
} |
332 | 337 |
} |
333 |
buf.setDataExtent(e.toRectangle2D());
|
|
338 |
buf.setDataExtent(tileExtent.toRectangle2D());
|
|
334 | 339 |
|
340 |
if(lastCoordTrans != null){ |
|
341 |
|
|
342 |
Extent projectedExtent = tileExtent.convert(lastCoordTrans); |
|
343 |
try { |
|
344 |
buf = |
|
345 |
buf.project(lastCoordTrans.getInverted(), projectedExtent, loadedTile.getWidthPx(), |
|
346 |
loadedTile.getHeightPx()); |
|
347 |
tileExtent = projectedExtent; |
|
348 |
} catch (WarpException e) { |
|
349 |
LOG.error(String.format( |
|
350 |
"Can not project [level: %1s row: %2s column: %3s] tile buffer to %4s", |
|
351 |
loadedTile.getLevel(), loadedTile.getRow(), loadedTile.getCol(), lastCoordTrans |
|
352 |
.getPDest().getAbrev())); |
|
353 |
return; |
|
354 |
} |
|
355 |
} |
|
356 |
|
|
335 | 357 |
Transparency transparencyProcessed = null; |
336 | 358 |
if(tiling == null || tiling.booleanValue()) { |
337 | 359 |
try { |
... | ... | |
352 | 374 |
h = viewDimension.getHeight(); |
353 | 375 |
} |
354 | 376 |
double viewScaleW = lastViewPortData.getExtent().width() / w; |
355 |
double tileScaleW = e.width() / (double)buf.getWidth();
|
|
377 |
double tileScaleW = tileExtent.width() / (double)buf.getWidth();
|
|
356 | 378 |
double scaleW = viewScaleW / tileScaleW; |
357 | 379 |
double viewScaleH = lastViewPortData.getExtent().height() / h; |
358 |
double tileScaleH = e.height() / (double)buf.getHeight();
|
|
380 |
double tileScaleH = tileExtent.height() / (double)buf.getHeight();
|
|
359 | 381 |
double scaleH = viewScaleH / tileScaleH; |
360 | 382 |
|
361 | 383 |
ImageDrawerImpl d = new ImageDrawerImpl(); |
... | ... | |
375 | 397 |
at.scale(1 / scaleW, 1 / scaleH); |
376 | 398 |
|
377 | 399 |
try { |
378 |
Point2D pt = new Point2D.Double(e.getULX(), e.getULY());
|
|
400 |
Point2D pt = new Point2D.Double(tileExtent.getULX(), tileExtent.getULY());
|
|
379 | 401 |
((DefaultViewPortData)lastViewPortData).mat.transform(pt, pt); |
380 | 402 |
at.inverseTransform(pt, pt); |
381 | 403 |
|
... | ... | |
388 | 410 |
} |
389 | 411 |
} else { |
390 | 412 |
try { |
391 |
drawBufferOnImage(lastGraphics, lastViewPortData, buf, step, transf, e);
|
|
413 |
drawBufferOnImage(lastGraphics, lastViewPortData, buf, step, transf, tileExtent);
|
|
392 | 414 |
} catch (QueryException e1) { |
393 | 415 |
LoggerFactory.getLogger(getClass()).debug("Error loading data", e1); |
394 | 416 |
} catch (ProcessInterruptedException e1) { |
... | ... | |
401 | 423 |
} |
402 | 424 |
} |
403 | 425 |
|
404 |
public synchronized Buffer draw(Graphics2D g, ViewPortData vp, TaskStatus taskStatus) |
|
426 |
public synchronized Buffer draw(Graphics2D g, ViewPortData vp, ICoordTrans coordTrans, TaskStatus taskStatus)
|
|
405 | 427 |
throws QueryException, ProcessInterruptedException { |
406 | 428 |
lastGraphics = g; |
407 | 429 |
lastViewPortData = vp; |
430 |
lastCoordTrans = coordTrans; |
|
408 | 431 |
|
409 |
if(util.isOutside(vp.getExtent(), dataStore.getExtent())) { |
|
432 |
Extent extent = dataStore.getExtent(); |
|
433 |
if(coordTrans != null){ |
|
434 |
extent = extent.convert(coordTrans); |
|
435 |
} |
|
436 |
|
|
437 |
if(util.isOutside(vp.getExtent(), extent)) { |
|
410 | 438 |
endReading(); |
411 | 439 |
return null; |
412 | 440 |
} |
413 | 441 |
|
414 |
Extent adjustedRotedRequest = request(vp, dataStore); |
|
442 |
Extent adjustedRotedRequest = null; |
|
443 |
try { |
|
444 |
adjustedRotedRequest = request(vp, coordTrans, dataStore); |
|
445 |
} catch (NoninvertibleTransformException e) { |
|
446 |
throw new ProcessInterruptedException("Problems adjusting extent to render"); |
|
447 |
} |
|
415 | 448 |
|
416 | 449 |
if ((widthImage <= 0) || (heightImage <= 0)) { |
417 | 450 |
endReading(); |
... | ... | |
425 | 458 |
double[] step = null; |
426 | 459 |
int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
427 | 460 |
|
428 |
if(reprojectionOnTheFly != null) { |
|
429 |
buf = reprojectionOnTheFly.warp(adjustedRotedRequest, |
|
430 |
(int)Math.round(widthImage), |
|
431 |
(int)Math.round(heightImage), |
|
432 |
vp.getTime(), |
|
433 |
renderBands, |
|
434 |
getRenderingTransparency()); |
|
461 |
if (coordTrans != null) { |
|
462 |
RasterRenderReprojection renderReprojection = new RasterRenderReprojection(); |
|
463 |
try { |
|
464 |
buf = |
|
465 |
renderReprojection.warp(dataStore, coordTrans, adjustedRotedRequest, |
|
466 |
(int) Math.round(widthImage), (int) Math.round(heightImage), vp.getTime(), |
|
467 |
renderBands, taskStatus); |
|
468 |
} catch (WarpException e) { |
|
469 |
throw new ProcessInterruptedException(e); |
|
470 |
} |
|
435 | 471 |
} else { |
436 | 472 |
lastAlphaBand = getRenderingTransparency().getAlphaBandNumber(); |
437 | 473 |
|
... | ... | |
609 | 645 |
* @param vp |
610 | 646 |
* @param ldatastore |
611 | 647 |
* @return |
648 |
* @throws NoninvertibleTransformException |
|
612 | 649 |
*/ |
613 |
private Extent request(ViewPortData vp, RasterDataStore ldatastore) {
|
|
614 |
if (ldatastore.isRotated()) {
|
|
650 |
private Extent request(ViewPortData vp, ICoordTrans coordTrans, RasterDataStore ldatastore) throws NoninvertibleTransformException {
|
|
651 |
if (ldatastore.isRotated()) {
|
|
615 | 652 |
//Obtenemos las cuatro esquinas de la selecci?n que hemos hecho en la vista |
616 | 653 |
Point2D ul = new Point2D.Double(vp.getExtent().minX(), vp.getExtent().maxY()); |
617 | 654 |
Point2D ur = new Point2D.Double(vp.getExtent().maxX(), vp.getExtent().maxY()); |
... | ... | |
653 | 690 |
//Ajustamos la petici?n a los limites del raster, teniendo en cuenta la rotaci?n de este. |
654 | 691 |
return new ExtentImpl(ulWC, lrWC); |
655 | 692 |
} |
656 |
Extent adjustedRotedExtent = util.calculateAdjustedView(vp.getExtent(), ldatastore.getAffineTransform(), ldatastore.getWidth(), ldatastore.getHeight()); |
|
693 |
|
|
694 |
AffineTransform at = ldatastore.getAffineTransform(); |
|
695 |
Extent adjustedRotedExtent = null; |
|
696 |
if (coordTrans != null) { |
|
697 |
Extent reprojectedExtent = ldatastore.getExtent().convert(coordTrans); |
|
698 |
double cellSizeX = |
|
699 |
(reprojectedExtent.getMax().getX() - reprojectedExtent.getMin().getX()) |
|
700 |
/ ldatastore.getWidth(); |
|
701 |
double cellSizeY = |
|
702 |
(reprojectedExtent.getMax().getY() - reprojectedExtent.getMin().getY()) |
|
703 |
/ ldatastore.getHeight(); |
|
704 |
|
|
705 |
Extent intersection = vp.getExtent().intersection(reprojectedExtent); |
|
706 |
at = |
|
707 |
new AffineTransform(cellSizeX, at.getShearY(), at.getShearX(), -cellSizeY, |
|
708 |
intersection.getMin().getX(), intersection.getMax().getY()); |
|
709 |
double width = intersection.width() / cellSizeX; |
|
710 |
double height = intersection.height() / cellSizeY; |
|
711 |
adjustedRotedExtent = util.calculateAdjustedView(intersection, at, width, height); |
|
712 |
} else { |
|
713 |
adjustedRotedExtent = util.calculateAdjustedView(vp.getExtent(), at, ldatastore.getWidth(), |
|
714 |
ldatastore.getHeight()); |
|
715 |
} |
|
716 |
|
|
657 | 717 |
widthImage = (int)Math.round(Math.abs(adjustedRotedExtent.width() * vp.getMat().getScaleX())); |
658 | 718 |
heightImage = (int)Math.round(Math.abs(adjustedRotedExtent.height() * vp.getMat().getScaleY())); |
659 |
Point2D ul = new Point2D.Double(adjustedRotedExtent.getULX(), adjustedRotedExtent.getULY()); |
|
660 |
Point2D lr = new Point2D.Double(adjustedRotedExtent.getLRX(), adjustedRotedExtent.getLRY()); |
|
661 |
ul = ldatastore.worldToRaster(ul); |
|
662 |
lr = ldatastore.worldToRaster(lr); |
|
663 |
ulPxRequest = new Point2D.Double(ul.getX(), ul.getY()); |
|
664 |
lrPxRequest = new Point2D.Double(lr.getX(), lr.getY()); |
|
719 |
Point2D ul = new Point2D.Double(adjustedRotedExtent.getMin().getX(), adjustedRotedExtent.getMax().getY()); |
|
720 |
Point2D lr = new Point2D.Double(adjustedRotedExtent.getMax().getX(), adjustedRotedExtent.getMin().getY()); |
|
721 |
|
|
722 |
Point2D worldUL = new Point2D.Double(); |
|
723 |
Point2D worldLR = new Point2D.Double(); |
|
724 |
|
|
725 |
if (coordTrans != null) { |
|
726 |
ul = at.inverseTransform(ul, worldUL); |
|
727 |
lr = at.inverseTransform(lr, worldLR); |
|
728 |
} else { |
|
729 |
worldUL = ldatastore.worldToRaster(ul); |
|
730 |
worldLR = ldatastore.worldToRaster(lr); |
|
731 |
} |
|
732 |
|
|
733 |
ulPxRequest = new Point2D.Double(worldUL.getX(), worldUL.getY()); |
|
734 |
lrPxRequest = new Point2D.Double(worldLR.getX(), worldLR.getY()); |
|
665 | 735 |
return adjustedRotedExtent; |
666 | 736 |
} |
667 | 737 |
|
... | ... | |
810 | 880 |
|
811 | 881 |
/** |
812 | 882 |
* Asigna la factoria de buffer del renderizador |
813 |
* @param bf
|
|
883 |
* @param ds
|
|
814 | 884 |
*/ |
815 | 885 |
public void setDataSource(RasterDataStore ds) { |
816 | 886 |
this.dataStore = ds; |
... | ... | |
935 | 1005 |
|
936 | 1006 |
/** |
937 | 1007 |
* Builds the filters from the list of classes <code>PersistencyFilterParam</code> recovered from a project |
938 |
* @param fList |
|
939 |
* @param listFilterUsed |
|
1008 |
* @param stats |
|
940 | 1009 |
* @throws PersistenceException |
941 | 1010 |
*/ |
942 | 1011 |
public void buildFiltersFromPersistencyFilterParam(Statistics stats) throws PersistenceException { |
... | ... | |
964 | 1033 |
throw new PersistenceException("error_adding_filters", exc.get(0)); |
965 | 1034 |
} |
966 | 1035 |
} |
967 |
|
|
1036 |
|
|
1037 |
@Override |
|
1038 |
public Buffer draw(Graphics2D g, ViewPortData vp, TaskStatus taskStatus) throws QueryException, |
|
1039 |
ProcessInterruptedException { |
|
1040 |
return draw(g, vp, null, taskStatus); |
|
1041 |
} |
|
1042 |
|
|
1043 |
@Override |
|
1044 |
public void drawTiledService(Graphics2D g, ViewPortData vp, Dimension2D viewDimension, |
|
1045 |
TaskStatus status) throws QueryException, ProcessInterruptedException { |
|
1046 |
drawTiledService(g, vp, viewDimension, null, status); |
|
1047 |
} |
|
968 | 1048 |
} |
org.gvsig.raster/branches/org.gvisg.raster_proyeccion_al_vuelo/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/render/RasterRenderReprojection.java | ||
---|---|---|
26 | 26 |
import org.cresques.cts.ICoordTrans; |
27 | 27 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
28 | 28 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
29 |
import org.gvsig.fmap.dal.coverage.dataset.BufferParam; |
|
30 | 29 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
31 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
32 |
import org.gvsig.fmap.dal.coverage.exception.BufferCreationException; |
|
33 | 30 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
34 | 31 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
32 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
35 | 33 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
36 | 34 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
37 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
38 | 35 |
import org.gvsig.raster.impl.DefaultRasterManager; |
39 | 36 |
import org.gvsig.timesupport.Time; |
40 |
import org.gvsig.tools.locator.LocatorException; |
|
41 | 37 |
import org.gvsig.tools.task.TaskStatus; |
42 | 38 |
|
43 | 39 |
/** |
44 |
* Reprojects a RasterDataStore.
|
|
40 |
* Reprojects a RasterDataStore. |
|
45 | 41 |
* |
46 | 42 |
* @author Nacho Brodin nachobrodin@gmail.com |
47 | 43 |
*/ |
48 | 44 |
public class RasterRenderReprojection { |
49 |
private RasterDataStore store = null; |
|
50 |
private ICoordTrans coordTrans = null; |
|
51 |
private ICoordTrans invertedCoordTrans = null; |
|
52 |
private NoData noData = null; |
|
53 |
private int dataType = Buffer.TYPE_BYTE; |
|
54 |
private TaskStatus status = null; |
|
55 |
private int lastAlphaBandNumber = 0; |
|
56 |
|
|
57 |
public RasterRenderReprojection(RasterDataStore store, |
|
58 |
ICoordTrans coordTrans, |
|
59 |
TaskStatus status) { |
|
60 |
this.store = store; |
|
61 |
this.status = status; |
|
62 |
this.coordTrans = coordTrans; |
|
63 |
this.invertedCoordTrans = coordTrans.getInverted(); |
|
64 |
dataType = store.getDataType()[0]; |
|
65 |
noData = RasterLocator.getManager().getDataStructFactory().createDefaultNoData( |
|
66 |
store.getBandCount(), dataType); |
|
67 |
} |
|
68 |
|
|
69 |
public Buffer warp(Extent bbox, |
|
70 |
int w, |
|
71 |
int h, |
|
72 |
Time time, |
|
73 |
int[] renderBands, |
|
74 |
Transparency lastTransparency) throws QueryException, ProcessInterruptedException { |
|
75 |
Point2D ul = new Point2D.Double(bbox.getULX(), bbox.getULY()); |
|
76 |
Point2D lr = new Point2D.Double(bbox.getLRX(), bbox.getLRY()); |
|
77 |
ul = invertedCoordTrans.convert(ul, ul); |
|
78 |
lr = invertedCoordTrans.convert(lr, lr); |
|
79 |
|
|
80 |
if(ul.getX() < store.getExtent().getULX()) |
|
81 |
ul.setLocation(store.getExtent().getULX(), ul.getY()); |
|
82 |
if(ul.getY() > store.getExtent().getULY()) |
|
83 |
ul.setLocation(ul.getX(), store.getExtent().getULY()); |
|
84 |
if(lr.getX() > store.getExtent().getLRX()) |
|
85 |
lr.setLocation(store.getExtent().getLRX(), lr.getY()); |
|
86 |
if(lr.getY() < store.getExtent().getLRY()) |
|
87 |
lr.setLocation(lr.getX(), store.getExtent().getLRY()); |
|
88 |
|
|
89 |
Extent newBbox = RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr); |
|
90 |
|
|
91 |
double[] size = getSize(bbox, newBbox, w, h); |
|
92 |
int newW = (int)size[0]; |
|
93 |
int newH = (int)size[1]; |
|
94 |
double cellSize = size[2]; |
|
95 |
|
|
96 |
BufferParam bufParam = RasterLocator.getManager().getBufferFactory().createBufferParams( |
|
97 |
store.getDataType()[0], newW, newH, 3, true); |
|
98 |
Buffer bufReprojected = null; |
|
99 |
try { |
|
100 |
bufReprojected = RasterLocator.getManager().getBufferFactory().createBuffer(bufParam); |
|
101 |
} catch (LocatorException e) { |
|
102 |
throw new QueryException("Error creating the buffer", e); |
|
103 |
} catch (BufferCreationException e) { |
|
104 |
throw new QueryException("Error creating the buffer", e); |
|
105 |
} |
|
106 |
|
|
107 |
RasterQuery query = DefaultRasterManager.getInstance().createQuery(); |
|
108 |
query.setTaskStatus(status); |
|
109 |
query.setTime(time); |
|
110 |
query.setSupersamplingOption(false); // Desactivamos el supersampleo en la carga del buffer. |
|
111 |
query.forceARGBRequest(); |
|
112 |
query.setAreaOfInterest(newBbox, newW, newH); |
|
113 |
query.setDrawableBands(renderBands); |
Also available in: Unified diff