On QGIS 2.18.1, Python 2.7.12, Ubuntu 64 bit, I am struggling with setting a CRS for a memory output layer within an iteration over several years of observations for a protected area (PA) polygon layer (UNEP-WCMC World PA database). The solution I have found so far (see, e.g. this) builds upon generating a multipart vector layer for a sub-selection of PA per year as a memory layer in order to intersect with GADM country polygons. This, however, requires a manual input of selecting the CRS for the memory layer. Is there a way of doing this automatically?
The code that requires solution:
from qgis.core import * from PyQt4.QtCore import * # singlepart to multipart algorithm processing.runandload('qgis:singlepartstomultipart', my_PA_vl, "my_field_of_country_ISO3", "memory:my_output_layer_name") # for this step I would like to set CRS for mem layer automatically my_output_layer_name = QgsMapLayerRegistry.instance().mapLayersByName("Multipart")
Setting the output layer to
None - which should set the memory layer CRS to input layer CRS (?) - somehow does not generate any output.
Potentially, there might even be a better solution / approach for what I am intending...