[QGIS-Developer] PyQgis QgsCoordinateTransform constructor?

Etienne Trimaille etienne.trimaille at gmail.com
Thu Dec 21 23:55:26 PST 2017


Hi,

I had the same problem.

I looked in the source, this constructor is not available anymore in Python
Bindings:
https://github.com/qgis/QGIS/blob/master/src/core/qgscoordinatetransform.h#L75

You need to give a QgsCoordinateTransformContext in the constructor:

transform = QgsCoordinateTransform(crs, crs_4326,
QgsCoordinateTransformContext())

I hope it's the right way to do it.
But I guess, like you and me, a lot of users will wonder the same question
about this new parameter and how to configure it so it would be nice to
provide some snippet or to update the QGIS Cookbook.

Regards
Etienne



2017-12-22 8:44 GMT+01:00 Richard Duivenvoorde <rdmailings at duif.net>:

> Hi Devs,
>
> since ages, I use like the following to create/get 2
> QgsCoordinateReferenceSystem's , then create a QgsCoordinateTransform
> from those and transform geoms or points:
>
> crs = iface.mapCanvas().mapSettings().destinationCrs()
> print(type(crs))
> print(crs.srsid())
> print(crs.toWkt())
>
> crs2 = QgsCoordinateReferenceSystem()
> crs2.createFromId(4326)
> print(type(crs2))
> print(crs2.srsid())
> print(crs2.toWkt())
>
> crsTransform = QgsCoordinateTransform(crs2, crs)
>
> But since some time (test in python console):
>
> 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 10, in <module>
> TypeError: QgsCoordinateTransform(): arguments did not match any
> overloaded call:
>   overload 1: too many arguments
>   overload 2: not enough arguments
>   overload 3: not enough arguments
>   overload 4: not enough arguments
>   overload 5: argument 1 has unexpected type 'QgsCoordinateReferenceSystem'
>
> While the api
>
> https://qgis.org/api/classQgsCoordinateTransform.html#
> a8c036726885d51e9fdfe1478a063dfcd
>
> still notes this constructor?
>
> Do I miss info? Or is something wrong with my sip stuff?
>
> Regards,
>
> Richard Duivenvoorde
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171222/56329bd1/attachment.html>


More information about the QGIS-Developer mailing list