[Gdal-dev] Layer Coordinate Transformation

Mateusz Loskot mateusz at loskot.net
Fri Mar 16 04:21:25 EDT 2007

ibrahim Z. HIDIR wrote:
> it's working fine, but takes long time when i got a huge data, i couldn't
> find a way to transform all layer on one time without a python loop. is
> there a way to do it?

Yes, you need to iterate through features and transform SRS one by one.
You can also see how it's implemented in the ogr2ogr.cpp, near line 755.

However, I see a few places to optimize in you code:

> while feature is not None:
>   geom = feature.GetGeometryRef()
>   ref = osr.SpatialReference()
>   out_ref = osr.SpatialReference()
>   ref.ImportFromWkt( source_coor )
>   out_ref.ImportFromWkt( base_coor )

It's a better idea to not need to instantiate SpatialReference objects
and import SRS from WKT in each and every iteration.
It does decrease performance pretty much.
The 4 lines above should be put just before the loop, so ref and out_ref
is created once.

Mateusz Loskot

More information about the Gdal-dev mailing list