13

I have the UTM code 36S and want to convert it to EPSG.

Somebody told me that if the UTM code contains 'S', then the first three digits of the EPSG code are 327, and if the UTM code is 'N' then use 326 instead. And then you just append the UTM number (in this case 36) to get '327' + '36' => '32736'.

Does this always work? And should I be using some python library to do this for me?

1
  • 5
    The above recipe is valid for WGS 84. There are several other UTM 36 zones, see epsg.io/?q=utm+36s
    – TomazicM
    Commented Jun 22, 2020 at 10:17

5 Answers 5

12

Use pyproj (version 2.2+):

from pyproj import CRS

# use PROJ string, assuming a default WGS84
crs = CRS.from_string('+proj=utm +zone=36 +south')
# or dictionary
crs = CRS.from_dict({'proj': 'utm', 'zone': 36, 'south': True})

print(crs.to_authority())  # ('EPSG', '32736')
1
  • Brilliant, thanks a ton. Commented Jun 22, 2020 at 14:16
4

In Python, You can use osr, which comes with gdal:

import osr

zone = '36'
south = True

epsg_code = 32600
epsg_code += int(zone)
if south is True:
    epsg_code += 100

print (epsg_code) # will be 32736

spatref = osr.SpatialReference()
spatref.ImportFromEPSG(epsg_code)
wkt_crs = spatref.ExportToWkt()
print (wkt_crs) 
2

Thanks @Johan, your code is very usefully.

I need to find the EPSG id for utm zone, given latitude and longitude :

import math
# Special zones for Svalbard and Norway
def getZones(longitude, latitude) :
    
    if (latitude >= 72.0 and latitude < 84.0 ) :
         if (longitude >= 0.0  and longitude <  9.0) :
              return 31              
    if (longitude >= 9.0  and longitude < 21.0):
          return 33
    if (longitude >= 21.0 and longitude < 33.0):
          return 35
    if (longitude >= 33.0 and longitude < 42.0) :
          return 37
    return (math.floor((longitude + 180) / 6) ) + 1 
    

def findEPSG(longitude, latitude) :
    
    zone = getZones(longitude, latitude)
    #zone = (math.floor((longitude + 180) / 6) ) + 1  # without special zones for Svalbard and Norway         
    epsg_code = 32600
    epsg_code += int(zone)
    if (latitude < 0): # South
        epsg_code += 100    
    return epsg_code
    
    
print(findEPSG(-64,-32)    )
2

I think the code above by @user2232395 has been crippled by copy/pasting. Looking at the UTM zone map, it looks like the indentation is wrong. Also, there is a "fix" missing for Norway. I think it should be:

def getZones(lon, lat):
    "get UTM zone number from latitude and longitude"

    if lat >= 72.0 and lat < 84.0:
        if lon >= 0.0 and lon < 9.0:
            return 31
        if lon >= 9.0 and lon < 21.0:
            return 33
        if lon >= 21.0 and lon < 33.0:
            return 35
        if lon >= 33.0 and lon < 42.0:
            return 37
    if lat >= 56 and lat < 64.0 and lon >= 3 and lon <= 12:
        return 32
    return math.floor((lon + 180) / 6) + 1


2

The S in UTM zone 36S does not stand for South. UTM zones divide latitude into bands of 8 degrees. Letters C to M are in the southern hemisphere, with the northerly boundary of M being the Equator. Letters N to X (including S) are in the northern hemisphere, with the southerly boundary of N being the equator.

EPSG codes for the UTM zones do group by North and South, which is sufficient as UTM Northing coordinates are measured all the way from the equator regardless of which UTM 8 degree band is in play.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.