[gdal-dev] Re: Do we have to know UTM zone a priori to convert
to UTM from lat/lon
Matt Funk
matze999 at gmail.com
Tue Sep 13 16:14:45 EDT 2011
Hi,
just to finish this out. The snippet below is basically the core of what
i was looking for (in the end it turned out to be relatively simple, but
all things are once done).
All it does it convert a point (specified in WSG84 (lat/lon)) to UTM and
back to WGS84 lat/lon. If someone spots an issue please let me know.
-----------------------------
import osr
def utm_getZone(longitude):
return (int(1+(longitude+180.0)/6.0))
def utm_isNorthern(latitude):
if (latitude < 0.0):
return 0;
else:
return 1;
## Fcn: __main__
# Purpose:
# Inputs:
# Returns:
#
if __name__ == '__main__':
lat = 38.0; lon = -50.0
utm_zone = utm_getZone(lon); #print "utm_zone: "; print utm_zone
is_northern = utm_isNorthern(lat); #print "is_northern: "; print
is_northern
## set utm coordinate system
utm_cs = osr.SpatialReference()
utm_cs.SetWellKnownGeogCS('WGS84')
utm_cs.SetUTM(utm_zone,is_northern);
## set wgs84 coordinate system
wgs84_cs = utm_cs.CloneGeogCS(); #print "\nwgs84_cs:"; print
wgs84_cs.ExportToPrettyWkt()
## set the transform wgs84_to_utm and do the transform
transform_WGS84_To_UTM = osr.CoordinateTransformation(wgs84_cs,utm_cs)
utm_points = list(transform_WGS84_To_UTM.TransformPoint(lon,lat));
print "utm_points: "; print utm_points
## set the transform utm_to_wgs84 and do the transform
transform_UTM_To_WGS84 = osr.CoordinateTransformation(utm_cs,wgs84_cs)
latlon_points =
list(transform_UTM_To_WGS84.TransformPoint(utm_points[0],utm_points[1]))
print "latlon_points: "; print latlon_points
-----------------------------
matt
On 9/13/2011 7:54 AM, Etienne Tourigny wrote:
> Well GDAL has the necessary infrastructure for (almost) anyone to do
> it themselves.
> This type of application is typically handled by python scripts, feel
> free to submit your own when it is ready. It would make a nice
> addition to the python samples in my opinion.
>
> EPSG zones are defined for longitude zones, both north and south (not
> in 8-degree zones), so in GDAL you only need to find the longitudinal
> zone and define if it is north or south.
>
> e.g. from spatialreference.org
> EPSG:32718 -> WGS 84 / UTM zone 18S
> EPSG:32618 -> WGS 84 / UTM zone 18N
>
> Etienne
>
> On Mon, Sep 12, 2011 at 7:55 PM, Matt Funk <matze999 at gmail.com> wrote:
>> On 9/12/2011 4:07 PM, Tim Osborn wrote:
>>> I should have said that the above equation is valid for longitudes greater
>>> than or equal to -180.0 and less than +180.0.
>> I assume it is the same to determine the latitude zone (using 8
>> degrees). The one thing though are the exceptions (even though I don't
>> intend to do any computations in those zones) ... . Is it correct then
>> to assume that gdal has no capabilities to return the zone based on a
>> given lat/lon pair? As easy as the code you provided is, it seems that
>> this capability (and the zone exception handling) would be included in
>> gdal ... .
>>
>> either way, thanks
>> matt
>>
>>> --
>>> View this message in context: http://osgeo-org.1803224.n2.nabble.com/gdal-dev-Do-we-have-to-know-UTM-zone-a-priori-to-convert-to-UTM-from-lat-lon-tp6785362p6785446.html
>>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
--
Matt Funk
Research Associate
Plant and Environmental Scienc. Dept.
New Mexico State University
More information about the gdal-dev
mailing list