Friday, 15 November 2019

Exporting layer to shapefile using PyQGIS?


I´m using python in QGIS 2.2 and struggling with an error trying this:


# create layer from text
_vlayer = QgsVectorLayer(_ur1, "raw", "delimitedtext")

works fine but:


# export layer to shape
_writer = QgsVectorFileWriter.writeAsVectorFormat\

(_vlayer,"hoppla.shp","utf-8",None,"ESRI Shapefile")

... ends up wiht error code "3" - according to documentation:"ErrCreateLayer".



Answer



It's all about user rights.


Just changed to a directory I'm allowed to write, everything works fine.


_writer = QgsVectorFileWriter.writeAsVectorFormat(_vlayer,r"C:/Users/myName/xx/hoppla.shp","utf-8",None,"ESRI Shapefile")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...