I have a vector layer which I need to load and edit (add several attribute columns). I am doing this without opening QGIS, so within a Python script. I have the following piece of code for the layer loading:
from osgeo import gdal from osgeo import ogr from gdalconst import * from PyQt4.QtGui import * from PyQt4.QtCore import * from qgis.core import * layer = QgsVectorLayer("/home/usr/Desktop/EligibleAreas_polygons.shp", "EligibleAreas_polygons", "ogr") if not layer.isValid(): print "Eligible areas layer failed to load!"
When I execute the Python script I get the message that the shapefile could not be loaded. When I try executing the same script from the Python console in QGIS, I get no warning. What could be the problem?
When I execute the next step (creating an attribute column "Land_Area" of doubles) within the Python console:
# add new fields layer.addAttribute(QgsField("LandArea", QVariant.Double))
I get False. Can someone give me a suggestion on how to solve this?