no_crash.py
1 |
iface = qgis.utils.iface |
---|---|
2 |
|
3 |
rasterLayer = iface.addRasterLayer("crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/png&layers=natura2000&styles=&url=http://geodata.nationaalgeoregister.nl/natura2000/ows", "wms master example", "wms" ) |
4 |
vectorLayer = iface.addVectorLayer("http://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=bestuurlijkegrenzen:provincies&SRSNAME=EPSG:28992","wfs example","WFS") |
5 |
|
6 |
QgsMapLayerRegistry.instance().addMapLayer(vectorLayer) |
7 |
|
8 |
iter = vectorLayer.getFeatures() |
9 |
|
10 |
for feature in iter: |
11 |
geom=feature.geometry() |
12 |
print "Feature ID %d: " % feature.id() |
13 |
|
14 |
if geom.type() == QGis.Point:
|
15 |
x = geom.asPoint() |
16 |
print "Point: " + str(x) |
17 |
elif geom.type() == QGis.Line:
|
18 |
x = geom.asPolyline() |
19 |
print "Line: %d points" % len(x) |
20 |
elif geom.type() == QGis.Polygon:
|
21 |
x = geom.asPolygon() |
22 |
numPts = 0
|
23 |
for ring in x: |
24 |
numPts += len(ring)
|
25 |
print "Polygon: %d rings with %d points" % (len(x), numPts) |
26 |
else:
|
27 |
print "Unknown" |
28 |
|
29 |
#fetch attributes
|
30 |
#attrs = feature.attributes()
|
31 |
#print attrs
|
32 |
|
33 |
QgsMapLayerRegistry.instance().removeMapLayer(vectorLayer.id()) |