QGIS Plugins – Fixing ‘QgsCoordinateReferenceSystem’ is Not Defined in QGIS Plugin

qgis

I like to extract a buffer of a railway system to a .poly file and use this one to extract further object within this buffer from an OSM file of germany.

I have defined a CRS for the layer of interest (UTM 32N)

enter image description here

The message QgsCoordinateReferenceSystem' is not defined is displayed when I try to use the plugin osmpoly in QGIS.

enter image description here

how to fix this?

I tried both suggestions. Did not work. neither the combination of them. New messages are displayed for

suggestion 1)

enter image description here

suggestion 2)

enter image description here

sugestion 1) and 2) combined (do not know if this makes sense at all)

enter image description here

after suggestion 1) and change linie 166 as below:

enter image description here

When I export my layer out of the used geopackage to .shp in WGS 84 (4326), the failure messages do not show anymore but the .poly is not created either.

Best Answer

Apparently there is a bug in the code. Error message QgsCoordinateReferenceSystem is not defined is related to plug-in Python code rather than to lack of CRS defined in your layer. Now there are two options - you could obviously contact developer or you can try to fix the code yourself. If you choose the latter, go to the file C:/Users/User.../osmpoly_export/polygenerator.py (full path as in you screenshot), open it in text (or Python) editor and uncomment line 32 i.e. remove hash in the line:

#from qgis.core import *

or alternatively (and more pythonic) add in from section:

from qgis.core import QgsCoordinateReferenceSystem
from qgis.core import QgsCoordinateTransform
from qgis.core import QgsProject

Another required change is to the line in the code (look for it around line 170): Replace:

transform = QgsCoordinateTransform(crsSrc, crsDest)

With:

transform = QgsCoordinateTransform(crsSrc, crsDest, QgsProject.instance())

After that reload the plug-in (or restart QGIS)

Related Question