Revision 234 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.io/org.gvsig.raster.io.base/src/main/java/org/gvsig/fmap/dal/coverage/dataset/io/wmts/WMTSProvider.java
WMTSProvider.java | ||
---|---|---|
36 | 36 |
import org.gvsig.fmap.dal.DataStoreParameters; |
37 | 37 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
38 | 38 |
import org.gvsig.fmap.dal.coverage.dataset.io.GdalProvider; |
39 |
import org.gvsig.fmap.dal.coverage.dataset.io.param.WMTSStoreParametersImpl;
|
|
39 |
import org.gvsig.fmap.dal.coverage.dataset.io.param.WMTSDataParametersImpl;
|
|
40 | 40 |
import org.gvsig.fmap.dal.coverage.dataset.io.server.DefaultWMTSServerExplorerParameters; |
41 | 41 |
import org.gvsig.fmap.dal.coverage.dataset.io.server.WMTSServerExplorerImpl; |
42 | 42 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
... | ... | |
50 | 50 |
import org.gvsig.fmap.dal.coverage.exception.WMSException; |
51 | 51 |
import org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer; |
52 | 52 |
import org.gvsig.fmap.dal.coverage.grid.render.TileListener; |
53 |
import org.gvsig.fmap.dal.coverage.store.parameter.WMTSStoreParameters;
|
|
53 |
import org.gvsig.fmap.dal.coverage.store.parameter.WMTSDataParameters;
|
|
54 | 54 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
55 | 55 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
56 | 56 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
... | ... | |
94 | 94 |
private boolean open = false; |
95 | 95 |
//Only for fixed size. Complete extent and FIXED_SIZE in long side |
96 | 96 |
private File lastRequest = null; |
97 |
private DataStoreTransparency fileTransparency = null;
|
|
97 |
private DataStoreTransparency lastFileTransparency = null;
|
|
98 | 98 |
private int lastWidthRequest = 0; |
99 | 99 |
private int lastHeightRequest = 0; |
100 | 100 |
private boolean gridSubsets = true; |
... | ... | |
108 | 108 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
109 | 109 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
110 | 110 |
dataman.registerStoreProvider(NAME, |
111 |
WMTSProvider.class, WMTSStoreParametersImpl.class);
|
|
111 |
WMTSProvider.class, WMTSDataParametersImpl.class);
|
|
112 | 112 |
} |
113 | 113 |
|
114 | 114 |
if (!dataman.getExplorerProviders().contains(WMTSServerExplorerImpl.NAME)) { |
... | ... | |
130 | 130 |
public WMTSProvider(String params) throws NotSupportedExtensionException { |
131 | 131 |
super(params); |
132 | 132 |
if(params instanceof String) { |
133 |
WMTSStoreParametersImpl p = new WMTSStoreParametersImpl();
|
|
133 |
WMTSDataParametersImpl p = new WMTSDataParametersImpl();
|
|
134 | 134 |
p.setHost((String)params); |
135 | 135 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
136 | 136 |
.createDynObject( |
... | ... | |
140 | 140 |
} |
141 | 141 |
} |
142 | 142 |
|
143 |
public WMTSProvider(WMTSStoreParametersImpl params,
|
|
143 |
public WMTSProvider(WMTSDataParametersImpl params,
|
|
144 | 144 |
AbstractRasterDataStore storeServices) throws NotSupportedExtensionException { |
145 | 145 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
146 | 146 |
.createDynObject( |
... | ... | |
155 | 155 |
* @throws WMSException |
156 | 156 |
*/ |
157 | 157 |
private WMTSConnector getConnector() throws WMSException { |
158 |
WMTSStoreParametersImpl p = (WMTSStoreParametersImpl)parameters;
|
|
158 |
WMTSDataParametersImpl p = (WMTSDataParametersImpl)parameters;
|
|
159 | 159 |
URL url = null; |
160 | 160 |
try { |
161 | 161 |
url = new URL(p.getHost()); |
... | ... | |
179 | 179 |
public void init (DataStoreParameters params, |
180 | 180 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
181 | 181 |
setParam(params); |
182 |
setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE}); |
|
183 |
bandCount = 3;
|
|
182 |
setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE});
|
|
183 |
bandCount = 4;
|
|
184 | 184 |
|
185 |
if(!(param instanceof WMTSStoreParameters))
|
|
185 |
if(!(param instanceof WMTSDataParameters))
|
|
186 | 186 |
return; |
187 | 187 |
|
188 |
gridSubsets = hasGridSubsets((WMTSStoreParameters)param);
|
|
188 |
gridSubsets = hasGridSubsets((WMTSDataParameters)param);
|
|
189 | 189 |
} |
190 | 190 |
|
191 | 191 |
/** |
... | ... | |
194 | 194 |
* @return |
195 | 195 |
*/ |
196 | 196 |
@SuppressWarnings("unchecked") |
197 |
private boolean hasGridSubsets(WMTSStoreParameters p) {
|
|
197 |
private boolean hasGridSubsets(WMTSDataParameters p) {
|
|
198 | 198 |
ArrayList tileMatrixSetLimits = null; |
199 | 199 |
ArrayList<?> tileMatrixSetLinkList = p.getLayer().getTileMatrixSetLink(); |
200 | 200 |
String srs = p.getSRSCode(); |
... | ... | |
249 | 249 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform() |
250 | 250 |
*/ |
251 | 251 |
public AffineTransform getAffineTransform() { |
252 |
WMTSStoreParametersImpl p = (WMTSStoreParametersImpl)parameters;
|
|
252 |
WMTSDataParametersImpl p = (WMTSDataParametersImpl)parameters;
|
|
253 | 253 |
Extent e = getExtent(); |
254 | 254 |
double psX = e.width() / (lastWidthRequest <= 0 ? p.getWidth() : lastWidthRequest); |
255 | 255 |
double psY = -(e.height() / (lastHeightRequest <= 0 ? p.getHeight() : lastHeightRequest)); |
... | ... | |
271 | 271 |
* @return Extent |
272 | 272 |
*/ |
273 | 273 |
public Extent getExtent() { |
274 |
WMTSStoreParametersImpl p = (WMTSStoreParametersImpl)parameters;
|
|
274 |
WMTSDataParametersImpl p = (WMTSDataParametersImpl)parameters;
|
|
275 | 275 |
if(gridSubsets) { |
276 | 276 |
WMTSLayer layer = p.getLayer(); |
277 | 277 |
WMTSBoundingBox bbox = layer.getWGS84BBox(); |
... | ... | |
307 | 307 |
*/ |
308 | 308 |
private Extent[] getExtentByResolutionLevel() { |
309 | 309 |
if(extentByLevel == null) { |
310 |
WMTSStoreParametersImpl p = (WMTSStoreParametersImpl)parameters;
|
|
310 |
WMTSDataParametersImpl p = (WMTSDataParametersImpl)parameters;
|
|
311 | 311 |
WMTSTileMatrixSetLink tileMatrixSetLink = getTileMatrixSetLink(); |
312 | 312 |
WMTSTileMatrixSet tileMatrixSet = tileMatrixSetLink.getTileMatrixSet(); |
313 | 313 |
|
... | ... | |
375 | 375 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency() |
376 | 376 |
*/ |
377 | 377 |
public Transparency getTransparency() { |
378 |
if(fileTransparency == null)
|
|
379 |
fileTransparency = new DataStoreTransparency();
|
|
380 |
return fileTransparency;
|
|
378 |
if(lastFileTransparency == null)
|
|
379 |
lastFileTransparency = new DataStoreTransparency();
|
|
380 |
return lastFileTransparency;
|
|
381 | 381 |
} |
382 | 382 |
|
383 | 383 |
/* |
... | ... | |
409 | 409 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth() |
410 | 410 |
*/ |
411 | 411 |
public double getWidth() { |
412 |
WMTSStoreParametersImpl p = (WMTSStoreParametersImpl)parameters;
|
|
412 |
WMTSDataParametersImpl p = (WMTSDataParametersImpl)parameters;
|
|
413 | 413 |
if (lastWidthRequest <= 0) |
414 | 414 |
return p.getWidth(); |
415 | 415 |
return lastWidthRequest; |
... | ... | |
420 | 420 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight() |
421 | 421 |
*/ |
422 | 422 |
public double getHeight() { |
423 |
WMTSStoreParametersImpl p = (WMTSStoreParametersImpl)parameters;
|
|
423 |
WMTSDataParametersImpl p = (WMTSDataParametersImpl)parameters;
|
|
424 | 424 |
if (lastHeightRequest <= 0) |
425 | 425 |
return p.getHeight(); |
426 | 426 |
return lastHeightRequest; |
... | ... | |
495 | 495 |
* (non-Javadoc) |
496 | 496 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, org.gvsig.fmap.dal.coverage.grid.render.TileListener, int) |
497 | 497 |
*/ |
498 |
@SuppressWarnings("unchecked") |
|
499 | 498 |
public void getWindowRaster(double minX, double minY, double maxX, double maxY, |
500 |
int bufWidth, int bufHeight, BandList bandList, TileListener listener, int frameInPx)throws ProcessInterruptedException, RasterDriverException { |
|
501 |
WMTSStoreParameters p = (WMTSStoreParameters)param; |
|
499 |
int bufWidth, int bufHeight, BandList bandList, TileListener listener)throws ProcessInterruptedException, RasterDriverException { |
|
502 | 500 |
Rectangle2D r = new Rectangle2D.Double(Math.min(minX, maxX), Math.min(minY, maxY), Math.abs(maxX - minX), Math.abs(maxY - minY)); |
501 |
WMTSStatus status = buildWMTSStatus(r, bufWidth, bufHeight); |
|
502 |
request(status, bandList, listener); |
|
503 |
} |
|
504 |
|
|
505 |
/** |
|
506 |
* Builds the WMTSStatus object using the parameters and the request bounding box. |
|
507 |
* @param r |
|
508 |
* @param bufWidth |
|
509 |
* @return |
|
510 |
* @throws RasterDriverException |
|
511 |
*/ |
|
512 |
@SuppressWarnings("unchecked") |
|
513 |
private WMTSStatus buildWMTSStatus(Rectangle2D r, int bufWidth, int bufHeight) throws RasterDriverException { |
|
514 |
WMTSDataParameters p = (WMTSDataParameters)param; |
|
503 | 515 |
|
504 | 516 |
//Mantiene actualizados los par?metros del WMTSStoreParameters con la ?ltima petici?n hecha |
505 | 517 |
p.setExtent(r); |
... | ... | |
535 | 547 |
|
536 | 548 |
//6-Petici?n |
537 | 549 |
WMTSStatus status = new WMTSStatus(); |
550 |
status.setTileList(tiles); |
|
538 | 551 |
status.setLayer(p.getLayer().getIdentifier()); |
539 | 552 |
status.setFormat(p.getImageFormat()); |
540 | 553 |
status.setStyle(p.getStyle() != null ? p.getStyle().getIdentifier() : ""); |
541 | 554 |
status.setTileMatrixSet(tileMatrixSet.getIdentifier()); |
542 | 555 |
status.setTileMatrix(tileMatrix.getIdentifier()); |
543 |
|
|
544 |
request(status, tiles, bandList, listener); |
|
556 |
return status; |
|
545 | 557 |
} |
546 | 558 |
|
547 | 559 |
/** |
... | ... | |
574 | 586 |
* @return |
575 | 587 |
*/ |
576 | 588 |
private WMTSTileMatrixSetLink getTileMatrixSetLink() { |
577 |
WMTSStoreParameters p = (WMTSStoreParameters)param;
|
|
589 |
WMTSDataParameters p = (WMTSDataParameters)param;
|
|
578 | 590 |
ArrayList<?> tileMatrixSetLinkList = p.getLayer().getTileMatrixSetLink(); |
579 | 591 |
for (int i = 0; i < tileMatrixSetLinkList.size(); i++) { |
580 | 592 |
WMTSTileMatrixSetLink tileMatrixSetLink = (WMTSTileMatrixSetLink)tileMatrixSetLinkList.get(i); |
... | ... | |
595 | 607 |
* @return |
596 | 608 |
*/ |
597 | 609 |
private double getScale(Rectangle2D r, int width) { |
598 |
WMTSStoreParameters p = (WMTSStoreParameters)param;
|
|
610 |
WMTSDataParameters p = (WMTSDataParameters)param;
|
|
599 | 611 |
if(!p.getSRS().isProjected()) { |
600 | 612 |
return (1000 * r.getWidth() * MTS_X_GRADO) / (width * 0.28); |
601 | 613 |
} else |
... | ... | |
605 | 617 |
/** |
606 | 618 |
* Throw a request |
607 | 619 |
* @param status |
608 |
* @param tiles |
|
609 | 620 |
* @param bandList |
610 | 621 |
* @param listener |
622 |
* @param alphaBandNumber |
|
623 |
* @return returns a buffer if the listener is null. In any other case it return null. |
|
611 | 624 |
* @throws RasterDriverException |
612 | 625 |
* @throws ProcessInterruptedException |
613 | 626 |
*/ |
614 |
private void request(WMTSStatus status, ArrayList<Tile> tiles, BandList bandList, TileListener listener) throws RasterDriverException, ProcessInterruptedException { |
|
627 |
@SuppressWarnings("unchecked") |
|
628 |
private Buffer request(WMTSStatus status, BandList bandList, TileListener listener) throws RasterDriverException, ProcessInterruptedException { |
|
629 |
WMTSDataParameters p = (WMTSDataParameters)param; |
|
615 | 630 |
WMTSConnector connector = null; |
616 | 631 |
try { |
617 | 632 |
connector = getConnector(); |
... | ... | |
622 | 637 |
if(connector == null) |
623 | 638 |
throw new RasterDriverException("Error getting the connector object"); |
624 | 639 |
|
640 |
ArrayList<Tile> tiles = status.getTileList(); |
|
641 |
|
|
625 | 642 |
for (int i = 0; i < tiles.size(); i++) { |
626 | 643 |
Tile tile = tiles.get(i); |
627 | 644 |
status.setTileRow(tile.row); |
... | ... | |
636 | 653 |
} |
637 | 654 |
|
638 | 655 |
GdalProvider driver = new GdalProvider(file.getPath()); |
656 |
bandCount = driver.getBandCount(); |
|
657 |
lastFileTransparency = driver.getTransparency(); |
|
639 | 658 |
Buffer rasterBuf = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], tile.wPx, tile.hPx, 3, true); |
640 | 659 |
Buffer buf = driver.getWindowRaster(0, 0, tile.wPx, tile.hPx, bandList, rasterBuf); |
641 | 660 |
|
661 |
buf.setDataExtent(new Rectangle2D.Double(Math.min(tile.ulx, tile.lrx), Math.min(tile.uly, tile.lry), Math.abs(tile.ulx - tile.lrx), Math.abs(tile.uly - tile.lry))); |
|
662 |
|
|
663 |
Buffer alphaBand = null; |
|
664 |
if(p.getAlphaBand() != -1 && listener != null) { |
|
665 |
alphaBand = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], tile.wPx, tile.hPx, 1, true); |
|
666 |
int[] oldDB = bandList.getDrawableBands(); |
|
667 |
bandList.setDrawableBands(new int[]{p.getAlphaBand()}); |
|
668 |
alphaBand = driver.getWindowRaster(0, 0, tile.wPx, tile.hPx, bandList, alphaBand); |
|
669 |
bandList.setDrawableBands(oldDB); |
|
670 |
} |
|
671 |
|
|
642 | 672 |
for (int j = 0; j < bandList.getBandCount(); j++) { |
643 | 673 |
bandList.getBand(j).setFileName(serverName); |
644 | 674 |
} |
645 | 675 |
|
646 |
buf.setDataExtent(new Rectangle2D.Double(Math.min(tile.ulx, tile.lrx), Math.min(tile.uly, tile.lry), Math.abs(tile.ulx - tile.lrx), Math.abs(tile.uly - tile.lry))); |
|
647 |
listener.nextBuffer(buf, new ExtentImpl(tile.ulx, tile.uly, tile.lrx, tile.lry), getAffineTransform(), null, true); |
|
648 | 676 |
driver.close(); |
677 |
|
|
678 |
if(listener != null) |
|
679 |
listener.nextBuffer(buf, alphaBand, new ExtentImpl(tile.ulx, tile.uly, tile.lrx, tile.lry), getAffineTransform(), null, true); |
|
680 |
else |
|
681 |
return buf; |
|
682 |
|
|
649 | 683 |
} catch (WMTSException e) { |
650 | 684 |
throw new RasterDriverException("Error getting tiles", e); |
651 | 685 |
} catch (ServerErrorException e) { |
... | ... | |
654 | 688 |
throw new RasterDriverException("Error getting tiles", e); |
655 | 689 |
} |
656 | 690 |
} |
657 |
listener.endReading(); |
|
691 |
if(listener != null) |
|
692 |
listener.endReading(); |
|
693 |
return null; |
|
658 | 694 |
} |
659 | 695 |
|
660 | 696 |
/* |
... | ... | |
685 | 721 |
*/ |
686 | 722 |
public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry, |
687 | 723 |
int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
688 |
lastWidthRequest = rasterBuf.getWidth();
|
|
689 |
lastHeightRequest = rasterBuf.getHeight();
|
|
690 |
return null;
|
|
724 |
Rectangle2D r = new Rectangle2D.Double(Math.min(ulx, lrx), Math.min(lry, uly), Math.abs(lrx - ulx), Math.abs(uly - lry));
|
|
725 |
WMTSStatus status = buildWMTSStatus(r, bufWidth, bufHeight);
|
|
726 |
return request(status, bandList, null);
|
|
691 | 727 |
} |
692 | 728 |
|
693 | 729 |
/* |
... | ... | |
816 | 852 |
public File getLastRequest() { |
817 | 853 |
return lastRequest; |
818 | 854 |
} |
855 |
|
|
856 |
/** |
|
857 |
* ASigna el par?metro de inicializaci?n del driver. |
|
858 |
*/ |
|
859 |
@Override |
|
860 |
public void setParam(DataStoreParameters param) { |
|
861 |
if(param instanceof WMTSDataParameters) |
|
862 |
this.name = ((WMTSDataParameters)param).getHost(); |
|
863 |
this.param = param; |
|
864 |
} |
|
865 |
|
|
819 | 866 |
} |
Also available in: Unified diff