Skip to content

African Surveyors Connect | GeoConnect

The geospatial platform for visionaries and those who dare to dream

Menu
  • Posts
    • News
    • General
    • Educational
    • Spotlight
  • Jobs
  • Events
  • More
    • Learn-GIS
    • Magazine
    • Academy
Menu

Coordinate Transformation with Python

Posted on August 29, 2021 by KUMBIRAI MATINGO

A lot of surveyors out there face some challenges when it comes to transforming coordinates from one system to the next. Normally we would go out in the field and collect our data using GPS Coordinate systems but the client requires the products in a local coordinate (in this case we could say Arc1950 which is used in Zimbabwe, Zambia and Malawi).

What if I told you that all these challenges could be solved in just 4 line of Python code?

In this article, we are going to be looking at how our fellow workmates and colleagues can use Python to transform coordinates from system A to system B.

Python has become a widely adopted programming languages with so many packages that have been developed by Open-Source contributors all over the globe. We are going to be using a python package named: PyProj.

What is Pyproj?

According to PyPi, PyProj is a python interface to PROJ (cartographic projections and coordinate transformations library).

The developers of this package have also managed to come up with documentation to help the geospatial community or anyone else who wishes to conduct coordinate transformations between systems.

Let’s start coding

So let’s get straight to the purposes of this post and get a little deep into some python programming.

First of all what you would want to do is to install Pyproj. To do this we can use Pip.

Open the Command-Line Interface on your machine and enter:

pip install pyproj

Once we have this package installed, it comes with all the libraries and functions that will help us limit our code and keep it to a minimum.

You will require a code editor for the next steps. I would recommend using Visual Studio Code or PyCharm to handle such projects and code.

Enter the following line of code:

from pyproj import Transformer

Here we have told our Python interpreter that we would like to use the Pyproj package that we just imported. From that library, we would like to import the Transformer module which handles or the transformation requests.

transformer = Transformer.from_crs(4326, 20936)

Next, we assign a variable called transformer to the function which is going to let the Transformer know which system we are coming from and which system we are going to.

The from_crs() function is responsible for stating out the coordinate systems by taking two parameters, from and to respectively.

In this example we have selected 4326 and 20936, which is from WGS84 (EPSG:4326) to Arc1950 (EPSG:20936 Arc 1950) respectively. If you are not sure the codes to the CRS you want to use you can always refer to the list of coordinate reference systems or enquire with the Geology Department within your region.

transformed = transformer.transform(-19.0115438, 29.154858)

Now we create our last variable which is going to hold the result of the transformation and I have decided to name it transformed. It is always recommended to name your variables very differently, but for the sake of this tutorial, I would like to give illustration to the audience.

The piece of code above, calls the transform() function which takes two parameters, the Latitude and Longitude or Y and X coordinates to be transformed.

I took coordinates from around my area hoping you folks will not come hunting me around.

Finally:

print(transformed)

Let’s print the result of this transformation to the screen. The print function is basically used for display.

Run this Python code from your command line or from your code editor (depending on which one) and get a result for the transformation you have selected.

Your final piece of code should look like so:

[snippet slug=coordinate-transformation lang=python]

Hopefully you will get to adopt this easy to use way of transforming coordinates from one system to another.

I will also get back and work on a method to do this transformation for a batch of coordinates stored in CSV format and will definitely edit this section of the post.

KUMBIRAI MATINGO
KUMBIRAI MATINGO

Kumbirai is a GIS & MEAL specialist using geospatial analytics to advance global health and social impact. A certified Data Protection Officer (DPO), an open-data advocate and self-taught software developer, he builds web GIS tools that turn field data into decisions. He lectures in GIS/Remote Sensing and mentors emerging practitioners. Founder of a geospatial startup and nonprofit, he believes, “Real geospatial innovation happens when we empower communities with the right tools and knowledge.” Open to consulting and collaborations.

Share this:

  • Tweet
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print

Related Articles You Might Like

Search for Articles

Latest Posts

  • Deploying a GeoDjango App on Heroku
  • The Truth About Self-Taught Skills No One Tells You
  • Transformative Mapping Event Launches in Chinhoyi: A Testament to Youth Engagement and Community Collaboration 
  • GeoConnect Awarded Grant for Transformative OpenStreetMap Project in Chinhoyi, Zimbabwe
  • Unlocking Data Treasure Troves: A Guide to Accessing Zimbabwe’s Geospatial Datasets

In today’s digital age, a website is the face of your brand, and having a well-designed and functional website is essential for businesses to succeed online. Our web development services combine creativity and technical expertise to build custom websites that not only look great but also deliver a seamless user experience across all devices.

From responsive design to e-commerce integration, our team of web developers has the skills and experience to bring your vision to life and help your business thrive in the online world. Let us help you create a website that showcases your brand and drives growth for your business. Get in touch via WhatsApp on +263-77-6-887-606 or send me an Email on matingonk@gmail.com

While we have renamed and re-branded to GeoConnect, we have dedicated this platform to continue our work in sharing and exchanging knowledge with the community that has helped us become what we are today.

The journey and legacy continues. Learn more about Geo-Connect.

Quick Links / Resources

  • Legal
  • About Us
© 2025 African Surveyors Connect | GeoConnect | Developed for the profession with support from KM-Spatial