Bug report #17600

QgsCoordinateTransform.transform() doesn't work anymore in QGIS master

Added by Cyprien Antignac over 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:High
Assignee:Alessandro Pasotti
Category:Python bindings / sipify
Affected QGIS version:master Regression?:Yes
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:25497

Description

The bug concern "QgsCoordinateTransform.transform()" in QGIS 2.99.

crsSrc = self.mapcanvas.mapSettings().destinationCrs().authid()
crsDest = layer.crs().authid()
if crsDest != crsSrc:
    crsSrc = QgsCoordinateReferenceSystem(crsSrc)
    crsDest = QgsCoordinateReferenceSystem(crsDest)
    box = feat.geometry().boundingBox()
    xform = QgsCoordinateTransform(crsSrc, crsDest)
    box = xform.transform(box)
self.mapcanvas.setExtent(box.buffered(50))

If I use a "QgsRectangle()" (box is a QgsRectangle()) in parameter, it returns "argument 1 has unexpected type 'QgsRectangle()'", it's the same thing with "QgsCoordinateTransform.transformBoundingBox()". Owever if i try with "QgsPointXY()" or X/Y coordinate it returns "Exception : unknown".

When I try to use "tranform()" in Python Console, the help section returns only 2 of the 3 possibilities ("QgsRectangle()" not appear) but the "QgsPointXY()" and X/Y coordinates possibilities don't even work.

It's a big problem for me, my plugin can't anymore reproject the rectangle to use it has zoom factor (for example : if QGIS is in EPSG:4326, I need to reproject the rectangle to EPSG:2154, if I don't, QGIS zoom in Germany but my area is in the center of France).

Associated revisions

Revision bfa857bb
Added by Alessandro Pasotti over 6 years ago

[bugfix] Restore binding for QgsCoordinateTransform

Fixes #17600

Binding was lost in commit 10d34ece02bb765f5d9d88bb0524c909235fb0d7

History

#1 Updated by Giovanni Manghi over 6 years ago

  • Subject changed from QgsCoordinateTransform.transform() doesn't work - QGIS 2.99 to QgsCoordinateTransform.transform() doesn't work anymore in QGIS master
  • Category changed from Python plugins to Python bindings / sipify

#2 Updated by Nyall Dawson over 6 years ago

  • Status changed from Open to Feedback

Something seems odd with your build or environment. Is this a custom build?

#3 Updated by Cyprien Antignac over 6 years ago

It's not a custom build, I have install QGIS from "QGIS-OSGeo4W-2.99.0-48-Setup-x86_64.exe" to prepare my plugin to QGIS 3.0

#4 Updated by Richard Duivenvoorde over 6 years ago

confirmed here on Debian too

running a small project with:
- crs of project different from layer
- layer active i layer manager
- one features of layer selected

then:

crsSrc = iface.mapCanvas().mapSettings().destinationCrs().authid()
crsSrc
crsDest = iface.mapCanvas().currentLayer().crs().authid()
crsDest
if crsDest != crsSrc:
    crsSrc = QgsCoordinateReferenceSystem(crsSrc)
    crsDest = QgsCoordinateReferenceSystem(crsDest)
    # make sure you have ONE feature selected
    box = iface.mapCanvas().currentLayer().selectedFeatures()[0].geometry().boundingBox()
    xform = QgsCoordinateTransform(crsSrc, crsDest)
    box = xform.transform(box)
    box
self.iface.mapCanvas().setExtent(box.buffered(50))

throws

Traceback (most recent call last):
  File "/usr/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 11, in <module>
TypeError: QgsCoordinateTransform.transform(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'QgsRectangle'
  overload 2: argument 1 has unexpected type 'QgsRectangle'

#5 Updated by Giovanni Manghi over 6 years ago

  • Operating System deleted (Windows 10)
  • Status changed from Feedback to Open

#6 Updated by Cyprien Antignac over 6 years ago

I've retry "transform()" with "QgsPointXY" and finally it work, I think it's a personal mistake in this case. But I still have not succeeded with "QgsRectangle()".

I've also retry with transformBoundingBox() :

it = layer.getFeatures(request)
extent = None
for x in it:
    extent = x.geometry().boundingBox()
if extent:
    crsSrc = self.mapcanvas.mapSettings().destinationCrs().authid()
    crsDest = layer.crs().authid()
if crsDest != crsSrc:
    crsSrc = QgsCoordinateReferenceSystem(crsSrc)
    crsDest = QgsCoordinateReferenceSystem(crsDest)
    xform = QgsCoordinateTransform(crsSrc, crsDest)
    extent = xform.transformBoundingBox(extent)
self.mapcanvas.setExtent(extent.buffered(50))
self.mapcanvas.refresh()

And it returns :

Traceback (most recent call last):
  File "C:/Users/Cyprien/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gedopi\stationDialogs.py", line 801, in zoomStation
    extent = xform.transformBoundingBox(extent)
Exception: unknown

Version de Python : 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] 
Version de QGIS : 2.99.0-Master Master, 0717835f79 

#7 Updated by Alessandro Pasotti over 6 years ago

  • Assignee set to Alessandro Pasotti

#8 Updated by Alessandro Pasotti over 6 years ago

  • Status changed from Open to In Progress
  • Pull Request or Patch supplied changed from No to Yes

#9 Updated by Anonymous over 6 years ago

  • % Done changed from 0 to 100
  • Status changed from In Progress to Closed

#10 Updated by Giovanni Manghi about 6 years ago

  • Resolution set to fixed/implemented

Also available in: Atom PDF