[gdal-dev] Python gdal -- Class or function equivalent to
jon at gina.alaska.edu
Mon Aug 24 18:20:57 EDT 2009
Frank (and all):
Thanks for the information. Using this link:
I was able to figure out how to transform points from one EPSG coordinate
system to another using Python. Here's how:
def transform(i_srs, o_srs, lon, lat):
# i_srs looks like "EPSG:4326"
# o_srs looks like "EPSG:3338"
from osgeo import osr
i_num = int(i_srs.split(':')) #obtain the EPSG number
o_num = int(o_srs.split(':')) #obtain the EPSG number
srs_in = osr.SpatialReference() #create an input Spatial Reference
srs_in.ImportFromEPSG(i_num) #import from EPSG:4326
srs_out = osr.SpatialReference() #create an output Spatial Reference
srs_out.ImportFromEPSG(o_num) #import from EPSG:3338
ct = osr.CoordinateTransformation(srs_in, srs_out)
#CoordinateTransformation object from EPSG:4326 to EPSG:3338
(X, Y, height) = ct.TransformPoint(float(lon), float(lat)) #Calculate
our transformed points
return (X, Y, height)
#the returned values give exactly what is expected as per my previous email
#end of script
Thanks again everyone!
On Fri, Aug 21, 2009 at 6:03 PM, Frank Warmerdam <warmerdam at pobox.com>wrote:
> Jonathan Sawyer wrote:
>> Good evening developers,
>> I am very new to GDAL, so please bear with me.
>> What function/class/module do I need to look at to perform coordinate
>> transformation, in Python?
>> Or better yet, can anyone point me to good online docs to learn how the
>> Python bindings are used in gdal?
>> FYI: I am looking for the equivalent to this command line example:
>> $ gdaltransform -s_srs EPSG:4326 -t_srs EPSG:3338
>> -146.673599867, 64.7163624865
>> 348408.577415968 1658661.40355536 0
>> Have a good weekend, and thanks for your help.
> There are some pointers to sample python scripts at:
> The tolatlong.py script has some example script for transforming
> Good luck,
> I set the clouds in motion - turn up | Frank Warmerdam,
> warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam<http://pobox.com/%7Ewarmerdam>
> and watch the world go round - Rush | Geospatial Programmer for Rent
Geographic Information Network of Alaska (GINA)
University of Alaska Fairbanks
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the gdal-dev