Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
qgib opened this issue Dec 1, 2017 · 10 comments
Closed

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

qgib opened this issue Dec 1, 2017 · 10 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority PyQGIS Related to the PyQGIS API Regression Something which used to work, but doesn't anymore

Comments

@qgib
Copy link
Contributor

qgib commented Dec 1, 2017

Author Name: Cyprien Antignac (Cyprien Antignac)
Original Redmine Issue: 17600
Affected QGIS version: master
Redmine category:python_bindings_/_sipify
Assignee: Alessandro Pasotti


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).

@qgib
Copy link
Contributor Author

qgib commented Dec 2, 2017

Author Name: Giovanni Manghi (@gioman)


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

@qgib
Copy link
Contributor Author

qgib commented Dec 2, 2017

Author Name: Nyall Dawson (@nyalldawson)


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


  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Dec 4, 2017

Author Name: Cyprien Antignac (Cyprien Antignac)


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

@qgib
Copy link
Contributor Author

qgib commented Dec 4, 2017

Author Name: Richard Duivenvoorde (@rduivenvoorde)


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'

@qgib
Copy link
Contributor Author

qgib commented Dec 4, 2017

Author Name: Giovanni Manghi (@gioman)


  • operating_system was changed from Windows 10 to
  • status_id was changed from Feedback to Open

@qgib
Copy link
Contributor Author

qgib commented Dec 4, 2017

Author Name: Cyprien Antignac (Cyprien Antignac)


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 

@qgib
Copy link
Contributor Author

qgib commented Dec 11, 2017

Author Name: Alessandro Pasotti (@elpaso)


  • assigned_to_id was configured as Alessandro Pasotti

@qgib
Copy link
Contributor Author

qgib commented Dec 11, 2017

Author Name: Alessandro Pasotti (@elpaso)


PR: #5843


  • status_id was changed from Open to In Progress
  • pull_request_patch_supplied was changed from 0 to 1

@qgib
Copy link
Contributor Author

qgib commented Dec 11, 2017

Author Name: Anónimo (Anónimo)


Applied in changeset bfa857b.


  • done_ratio was changed from 0 to 100
  • status_id was changed from In Progress to Closed

@qgib qgib closed this as completed Dec 11, 2017
@qgib
Copy link
Contributor Author

qgib commented Feb 22, 2018

Author Name: Giovanni Manghi (@gioman)


  • resolution was changed from to fixed/implemented

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority PyQGIS Related to the PyQGIS API Regression Something which used to work, but doesn't anymore labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority PyQGIS Related to the PyQGIS API Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

No branches or pull requests

1 participant