[Qgis-developer] Python QGis Geometry.transform
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Thu Dec 3 08:21:59 EST 2009
On Thu, Dec 3, 2009 at 1:06 PM, motta.luiz at gmail.com
<motta.luiz at gmail.com> wrote:
> Hi All,
>
> I need transform geometry of one feature to other reference system.
>
> The API of geometry show the method transform
> int QgsGeometry::transform(const QgsCoordinateTransform)
>
> But in the Python, this methdos not exist.
> Console Python QGis
>> from qgis import
>> core geom = core.QgsGeometry()
>> print dir(geom.transform)
> exceptions.AttributeError: 'QgsGeometry' object has no attribute 'transform'
>
> I tested with:
> Ubuntu 9.10, QGis 1.3.0-Mimas code revision "exported"
> Windows XP, QGis 1.3-Mimas code revision 11638
>
> Do someone use this method in Python ?
>
I think you need to use QgsCoordinateTransform - here's a snippet
from the GeoCoding plugin that transforms a point 'point' from
whatever proj4string is to EPSG:4326 to 'pt'.
t=QgsCoordinateReferenceSystem()
t.createFromEpsg(4326)
f=QgsCoordinateReferenceSystem()
f.createFromProj4(proj4string)
transformer = QgsCoordinateTransform(f,t)
pt = transformer.transform(point)
Barry
--
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman
More information about the Qgis-developer
mailing list