8

I have a set of city networks whose coordinates are specified in lat/lons. I wish to run an algorithm on each network that treats them as a planar graph. I'm using python and can use pyproj to project the network appropriately, the problem is that I don't know the appropriate CRS for each city, e.g., for my test case, Harare, I define the variable: zimbabwe_reference='epsg:20935'.

What I'd like to do is call a function like crs=getCRS(lat, lon) and get the relevant string to pass on to pyproj.

5 Answers 5

15

You can calculate the UTM zone of each town center from the longitude, starting at zone 1 from -180°E to -174°E. zone=ROUND((183+longitude)/6;0) should calculate that in one step.

The EPSG code is 32600+zone for positive latitudes and 32700+zone for negatives.

Together in one formula:

EPSG=32700-ROUND((45+latitude)/90;0)*100+ROUND((183+longitude)/6;0)

Alternatively, create a custom CRS on the town center:

+proj=tmerc +lat_0=(latitude) +lon_0=(longitude) +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
4
  • there used to be a "what's my UTM zone" website that let you click on the map and it gave you the UTM zone and EPSG code. Sadly, it's been deactivated, but at least the formula isn't too hard.
    – Steven Kay
    Apr 20, 2016 at 17:56
  • 1
    @AndreJ ROUND((45+latitude)/90;0) gives the wrong value for the thousands digit. use the sign() function like (sign(lat)+1)/2 * 100 instead Apr 25, 2020 at 18:49
  • 1
    and for longitude part, floor((180+lon)/6) + 1 Apr 25, 2020 at 19:01
  • @StevenKay this website is here mangomap.com/robertyoung/maps/69585/what-utm-zone-am-i-in-# May 7, 2020 at 12:17
3

Now pyproj allows you to do it https://pyproj4.github.io/pyproj/stable/examples.html#find-utm-crs-by-latitude-and-longitude

They posted this example:

from pyproj import CRS
from pyproj.aoi import AreaOfInterest
from pyproj.database import query_utm_crs_info

utm_crs_list = query_utm_crs_info(
    datum_name="WGS 84",
    area_of_interest=AreaOfInterest(
        west_lon_degree=-93.581543,
        south_lat_degree=42.032974,
        east_lon_degree=-93.581543,
        north_lat_degree=42.032974,
    ),
)
utm_crs = CRS.from_epsg(utm_crs_list[0].code)
1

Boundless has an API for their projection to EPS that allows you to make calls using search strings.

0

epsg.io allows you to search by country.

Once you have a suitable EPSG code, you can extract using the links on the site.

They also have an API, and the QGIS plugin called Search and Format EPSG code can use this to fetch the proj4 string (amongst many other formats), given the CRS. Or you can use a url like this for getting the proj4 string for epsg:20935

Another possibility - if you can use postgres/postgis - is to build out the epsg database yourself (can get for free, but need to register) and do spatial queries to find out which CRSes overlap your target point.

0

There is a website which allows you to know which UTM zone you clicked on https://mangomap.com/robertyoung/maps/69585/what-utm-zone-am-i-in-#

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.