5

I am trying to create a vector memory in a plugin. Basing on some examples,I was able to create a memory vector layer and to add it in QGis with : QgsMapLayer.instance().addMapLayer(myLayer,True)

But when the layer is added , QGis always displays the crs dialog to specify the crs of the layers

:crs dialog

I tried to specify myself the crs with : layer.setCrs(QgsCoordinateReference(4326)) but it still shows me the crs dialog.

Do you have any ideas to how avoid this dialog ?

6

In addition to changing the preferences in QGIS, another way to avoid the dialog is to specify the CRS when creating the memory layer (as opposed to changing it at a later step). This can be done using the URI string:

layer = QgsVectorLayer("Polygon?crs=EPSG:4326", "result", "memory")
QgsMapLayerRegistry.instance().addMapLayer(layer)

will create a memory layer using EPSG:4326 and add it to the registry without asking for the CRS to be specified, regardless of the QGIS preferences.

3

I found a way in QGIS, in Setting>Options>CRS you can specify a default CRS, so the dialog will not appear. Hope it can help other peoples with same problems.

0

This will prevent the popup from showing. The popup appears when you call QgsVectorLayer(). With Qt blockSingals, you can disable all signals to stop the signal calling the CRS dialog that is called when CRS is missing.

You can use the code below:

iface.mainWindow().blockSignals(True)

v_layer = QgsVectorLayer('Polygon?crs=EPSG:4326', 'layer_name', 'memory')

iface.mainWindow().blockSignals(False)
target_crs = QgsCoordinateReferenceSystem(
    4326, QgsCoordinateReferenceSystem.InternalCrsId
)
v_layer.setCrs(target_crs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.