@@ -28,16 +28,51 @@ Parameters:
28
28
* IgnoreAxisOrientation (optional,hack) : If specified (set to 1), do not invert axis orientation according to WCS standard for geographic CRS.
29
29
30
30
31
- Python console example:
31
+ Python console example, adds new layer to map canvas :
32
32
33
- from PyQt4.QtCore import QString
33
+ from PyQt4.QtCore import QString
34
34
35
- uri = QgsDataSourceURI()
36
- uri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
37
- uri.setParam ( "identifier", "band1_int16_noct_epsg4326" )
35
+ uri = QgsDataSourceURI()
36
+ uri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
37
+ uri.setParam ( "identifier", "band1_int16_noct_epsg4326" )
38
38
39
- layer = QgsRasterLayer( QString(uri.encodedUri()), "WCS test", "wcs" )
40
- layer.isValid()
39
+ layer = QgsRasterLayer( QString(uri.encodedUri()), "WCS test", "wcs" )
40
+ layer.isValid()
41
41
42
- QgsMapLayerRegistry.instance().addMapLayer(layer)
42
+ QgsMapLayerRegistry.instance().addMapLayer(layer)
43
+
44
+
45
+ another standalone script, downloads WCS layer to local file:
46
+
47
+ import sys
48
+
49
+ from qgis.core import *
50
+
51
+ from PyQt4.QtCore import QString
52
+
53
+ QgsApplication.setPrefixPath("/path/to/qgis/installation/", True)
54
+
55
+ QgsApplication.initQgis()
56
+
57
+ app = QgsApplication(sys.argv,False) # important for QgsNetworkAccessManager
58
+
59
+ srcUri = QgsDataSourceURI()
60
+ srcUri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
61
+ srcUri.setParam ( "identifier", "band1_int16_noct_epsg4326" )
62
+
63
+ srcProvider = QgsProviderRegistry.instance().provider( "wcs", QString( srcUri.encodedUri()) )
64
+
65
+ if not srcProvider or not srcProvider.isValid():
66
+ print "Cannot create provider"
67
+ sys.exit ( 1 )
68
+
69
+ pipe = QgsRasterPipe()
70
+ if not pipe.set( srcProvider ):
71
+ print "Cannot set provider on pipe")
72
+
73
+ destUri = "/tmp/test.tif"
74
+
75
+ fileWriter = QgsRasterFileWriter ( destUri )
76
+
77
+ fileWriter.writeRaster( pipe, srcProvider.xSize(), srcProvider.ySize(), srcProvider.extent(), srcProvider.crs() )
43
78
0 commit comments