qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.05k stars 2.92k forks source link

pyQGIS - new_point.transform(tr) Exception: unknown #26747

Closed qgib closed 5 years ago

qgib commented 6 years ago

Author Name: Russell Fulton (Russell Fulton) Original Redmine Issue: 18915 Affected QGIS version: 3.0.2 Redmine category:pythonbindings/_sipify Assignee: Denis Rouzaud


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)
qgib commented 6 years ago

Author Name: Denis Rouzaud (@3nids)


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

qgib commented 6 years ago

Author Name: Russell Fulton (Russell Fulton)


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

qgib commented 5 years ago

Author Name: Denis Rouzaud (@3nids)


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.


qgib commented 5 years ago

Author Name: Denis Rouzaud (@3nids)


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