# How to get appropriate CRS for a position specified in lat/lon coordinates?

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.

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
``````
• 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 '16 at 17:56

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

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.