killqgis.py
1 |
from PyQt4.QtCore import QVariant |
---|---|
2 |
#create test data in SHP
|
3 |
vl = QgsVectorLayer("Point?crs=epsg:4326&field=name:string(20)", "temporary_points", "memory") |
4 |
pr = vl.dataProvider() |
5 |
vl.startEditing() |
6 |
fet = QgsFeature() |
7 |
fet.setGeometry(QgsGeometry.fromPoint(QgsPoint(10,10))) |
8 |
fet.setAttributes(["Johny"])
|
9 |
pr.addFeatures([fet]) |
10 |
vl.commitChanges() |
11 |
filepath = '/tmp/test.shp'
|
12 |
QgsVectorFileWriter.writeAsVectorFormat(vl, filepath, "CP1250", None, "ESRI Shapefile") |
13 |
|
14 |
|
15 |
#load SHP, works with any shp
|
16 |
vl = QgsVectorLayer(filepath, "temporary_points", "ogr") |
17 |
QgsMapLayerRegistry.instance().addMapLayer(vl) |
18 |
|
19 |
#open the attribute table, important!
|
20 |
iface.actionOpenTable().trigger() |
21 |
|
22 |
pr = vl.dataProvider() |
23 |
vl.startEditing() |
24 |
pr.addAttributes([QgsField("name2", QVariant.String)])
|
25 |
vl.commitChanges() |
26 |
vl.startEditing() |
27 |
print "now in the attribute table delete a field" |
28 |
|