Sunday, August 6, 2017

Convert Projected coordinates (Northings/Eastings) to Geographical (Latitude/Longitude) using Python

Generally, there are two types of coordinate systems used to represent Geospatial data namely:-
1) Geographical Coordinate Systems - Polar coordinates assumes the earth is spheroid/geoid/ellipsoid/curve (Latitude/Longitude). Example: World Geodetic System (WGS) 1984. Geographic coordinate systems are based on a spheroid and utilize angular units (degrees).

2) Projected Coordinate Systems - Rectangular coordinates assumes the earth is flat (Northings/Eastings).Example: Universal Transverse Mercator (UTM) Zone 33. Projected coordinate systems are based on a plane (the spheroid projected onto a 2D surface) and utilize linear units (feet and meters)

Get Long/Lat point from

Lets obtain a point coordinate for this demonstration. Am going to use this website to collect a single point coordinate in long/lat Coordinate system WGS 84 EPSG:4326

As yo can see from above, we have obtained the long/lat value: 7.27245, 8.91936. That is the value I will use for demonstrating how to convert from longitude,latitude to native map projection x,y coordinates and vice versa using python programming interface.

Using Python to Convert between Coordinate Systems

Often, there will be need to convert from one system to another. Here am going to introduce few python packages for coordinate systems conversation. These packages are:-
1) PyProj - Python interface to PROJ.4 library to performs cartographic transformations and geodetic computations.
2) GDAL/OGR - libraries that allows read and write of multiple GIS formats.

Because these packages were originally written for the C programming language, installing their python bindings for use with python takes some effort. Thank God for the wheel packages made available by third party developers out there such as: Unofficial Windows Binaries for Python Extension Packages by Christoph Gohlke and the QGIS Software project. Lets see how to use them one after the other.


Search for Pyproj wheel and install from here. Open you python IDE and enter the code below to convert from longitude,latitude to native map projection x,y coordinates and vice versa using pyproj.

Note that the projections where changed for each transformation.

Comparing the above result result to what the website tool gives us, we see that the results are very close.


Here I will use the gdal/ogr installation that comes with the QGIS python interface. Download and install QGIS and open the python console. Enter and run the script below;

That is it.
Thanks for following.

No comments:

Post a Comment