Bug report #18915

pyQGIS - new_point.transform(tr) Exception: unknown

Added by Russell Fulton over 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:Normal
Assignee:Denis Rouzaud
Category:Python bindings / sipify
Affected QGIS version:3.0.2 Regression?:No
Operating System:Mac OS 10.13.2 Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:26747

Description

I believe that this worked in 3.0.0 and 3.0.1 (once I converted the API calls to 3.0)

Call to transform dies with "Exception: unknown":

if wp.name in wp_features: # have a existing waypoint with that name
feature = wp_features[wp.name]
new_point = QgsPoint( wp.longitude, wp.latitude)
new_point.transform(tr)

History

#1 Updated by Denis Rouzaud over 6 years ago

can you share more of the code, especially the definition of transform, and provide a minimal code example?

#2 Updated by Russell Fulton over 6 years ago

I have done more investigation and the situations is not quite what I thought. It turns out that that transform gets called successfully lots of times before failing. Once I figured that out i looked at the point that was being transformed since the problem did not appear to be with the transform itself ( my bad for not checking this before).

wp is a waypoint from gpxpy

                        new_point = QgsPoint( wp.longitude, wp.latitude)
                        print( 'debug 1 wp:', wp, 'point:', new_point, ", tr:", tr)
                        new_point.transform(tr)

last line printed before crash:

debug 1 wp: [wpt{T E B05}:0.0,0.0@None] point: <qgis._core.QgsPoint object at 0x113b17ee8> , tr: <qgis._core.QgsCoordinateTransform object at 0x113b9a0d8>

It looks like the waypoint from the GPX file is 0,0 -- the transform is from 4326 to 2193

#3 Updated by Denis Rouzaud about 6 years ago

  • Status changed from Open to Feedback

Just tried this code

cfrom=QgsCoordinateReferenceSystem.fromEpsgId(4326)
cto=QgsCoordinateReferenceSystem.fromEpsgId(2193)
p=QgsPoint(0,0)
t=QgsCoordinateTransform(cfrom,cto,QgsProject.instance())
p.transform(t)

I don't get a crash but an exception

_core.QgsCsException: forward transform of
(0.000000, 0.000000)
PROJ: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 +to +proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
Error: latitude or longitude exceeded limits

But I think that it might be indeed a crash in 3.0, I am on master (upcoming 3.4).

You might want to do a try...except in Python to handle this.

#4 Updated by Denis Rouzaud about 6 years ago

  • Resolution set to fixed/implemented
  • Status changed from Feedback to Closed

I mark it as fixed as the exception is the foreseen effect.

Also available in: Atom PDF