2

I'm trying to create a script that will use the decimal degree coordinates of point features. To do this, I want to perform a coordinate transformation on features whose coordinates are in meters. In the code below, I get the active layer and store its coordinate system (UTM zone 18N), then choose an NAD83 geographic coordinate system (EPSG:5498), and construct a QgsCoordinateTransform. I then attempt various methods of executing the transformation, with bost QgsCoordinateTransform.transform(QgsPointXY) and QgsGeometry.transform(QgsCoordinateTransform), but all of them result in Exception: unknown.

Python Console 

li = iface.activeLayer()

liearth = ifacel.activeLayer().crs()

flatearth = QgsCoordinateReferenceSystem(5498)

lipts = [f for f in li.getFeatures()]

toflat = QgsCoordinateTransform(liearth, flatearth, QgsProject.instance())

for f in lipts:
  gPoint = toflat.transform(f.geometry().asPoint())
  print(gPoint)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 2, in <module>
Exception: unknown


fPts = [f.geometry().asPoint() for f in lipts]

type(fPts[0])
<class 'qgis._core.QgsPointXY'>

QgsCoordinateTransform(li.crs(), flatearth, QgsProject.instance()).transform(fPts[0])
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
Exception: unknown
type(fPts[0])
<class 'qgis._core.QgsPointXY'>

fGeo = [f.geometry() for f in lipts]
type(fGeo)
<class 'list'>
type(fGeo[0])
<class 'qgis._core.QgsGeometry'>

newpoint = fGeo[0]

newpoint
<qgis._core.QgsGeometry object at 0x114d5edc8>

newpoint.asPoint()
(592932,4.52942e+6)

newpoint.transform(QgsCoordinateTransform(li.crs(), flatearth, QgsProject.instance()))
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
Exception: unknown

The only helpful detail that I've been able to find online on this is someone who also received an unknown exception a few months ago a little before QGIS 3 was released. However, hey were able to fix the issue using a QgsRectangle, which I cannot do.

  • Do you really need 5498 which is a compound CRS of NAD83 + NAVD88? What about using 4269, the 2D geographic version of NAD83? – mkennedy Jun 18 '18 at 21:51
  • @mkennedy this rectified the problem. I will add this as an answer. – fairground Jun 20 '18 at 15:39
1

Since EPSG:5498 is a CRS with a vertical datum, the transformation fails. Using EPSG:4269, which is the same as 5498 but without the vertical datum, the transformation should be successful.

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.