Skip to content
Permalink
Browse files

Example script in Python to download WCS layer

  • Loading branch information
blazek committed Sep 17, 2012
1 parent 8c8d028 commit a25b1ec50970939396deef3fba273ec1d4b23f20
Showing with 43 additions and 8 deletions.
  1. +43 −8 src/providers/wcs/URI
@@ -28,16 +28,51 @@ Parameters:
* IgnoreAxisOrientation (optional,hack) : If specified (set to 1), do not invert axis orientation according to WCS standard for geographic CRS.


Python console example:
Python console example, adds new layer to map canvas:

from PyQt4.QtCore import QString
from PyQt4.QtCore import QString

uri = QgsDataSourceURI()
uri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
uri.setParam ( "identifier", "band1_int16_noct_epsg4326" )
uri = QgsDataSourceURI()
uri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
uri.setParam ( "identifier", "band1_int16_noct_epsg4326" )

layer = QgsRasterLayer( QString(uri.encodedUri()), "WCS test", "wcs" )
layer.isValid()
layer = QgsRasterLayer( QString(uri.encodedUri()), "WCS test", "wcs" )
layer.isValid()

QgsMapLayerRegistry.instance().addMapLayer(layer)
QgsMapLayerRegistry.instance().addMapLayer(layer)


another standalone script, downloads WCS layer to local file:

import sys

from qgis.core import *

from PyQt4.QtCore import QString

QgsApplication.setPrefixPath("/path/to/qgis/installation/", True)

QgsApplication.initQgis()

app = QgsApplication(sys.argv,False) # important for QgsNetworkAccessManager

srcUri = QgsDataSourceURI()
srcUri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
srcUri.setParam ( "identifier", "band1_int16_noct_epsg4326" )

srcProvider = QgsProviderRegistry.instance().provider( "wcs", QString( srcUri.encodedUri()) )

if not srcProvider or not srcProvider.isValid():
print "Cannot create provider"
sys.exit ( 1 )

pipe = QgsRasterPipe()
if not pipe.set( srcProvider ):
print "Cannot set provider on pipe")

destUri = "/tmp/test.tif"

fileWriter = QgsRasterFileWriter ( destUri )

fileWriter.writeRaster( pipe, srcProvider.xSize(), srcProvider.ySize(), srcProvider.extent(), srcProvider.crs() )

0 comments on commit a25b1ec

Please sign in to comment.
You can’t perform that action at this time.