Thursday 31 August 2017

pyqgis - How to use Qgis Gridsplitter Plugin in Console


I would like to use Gridsplitter plugin in console. I have the following code for doing it:


from qgis.core import *
import qgis.utils
import imp

gridSplitterPath = "C:/Users/Mossy/.qgis2/python/plugins/gridSplitter/gridSplitter.py"

outputpath = "C:/Users/Mossy/Desktop/NewFolder/Output"
cutlayerpath = "C:/Users/Mossy/Desktop/NewFolder/InputData/cutlayer.shp"
layertocutpath = "C:/Users/Mossy/Desktop/NewFolder/InputData/layertocut.tif"

iface = qgis.utils.iface
module = imp.load_source("gridSplitter",gridSplitterPath)

mySplitter = module.gridSplitter(iface)
mySplitter.outputfolder = outputpath
mySplitter.layertocut = QgsRasterLayer(layertocutpath,"laytocut")

mySplitter.cutlayeris = True
mySplitter.cutlayer = QgsVectorLayer(cutlayerpath,"cutlay", "ogr")
mySplitter.pref = "cut_"
mySplitter.subfolderis = False
mySplitter.tileindexis = True

mySplitter.operate()

However, I get the following error:


Traceback (most recent call last):

File "", line 1, in
File "c:/users/Mossy/appdata/local/temp/tmpqc7_fe.py", line 23, in
mySplitter.operate()
File "C:/Users/Mossy/.qgis2/python/plugins/gridSplitter/gridSplitter.py", line 206, in operate
self.layertocutcrs= layertocut.crs()
AttributeError: 'NoneType' object has no attribute 'crs'

Does anybody know how to solve this problem?




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...