Jonathan Hsu
Aug 22 · 2 min read
How to Convert Latitude & Longitude to Distance, UTM, and GeoJSON
How to Convert Latitude & Longitude to Distance, UTM, and GeoJSON

The world has come a long way in mapping. As a consumer, we take all the location data that is readily available for granted, but as a professional, you may be sitting on a treasure trove of GIS data that just needs to be refined. Here are three simple ways to take that first step with your latitude and longitude data.


The Distance Between Two Coordinates

If you’ve been calculating the distance between two coordinates for a long time, you may be familiar with the Haversine formula. While popular, this equation suffers from minor accuracy deficiencies as it makes the assumption the Earth is a sphere.

Using the geopy library, you have access to a more accurate method of calculating distance that is easier to implement.

Notice that each coordinate pair is a tuple and the unit of measure is added as a property at the end of the execution.


Convert to UTM

Universal Transverse Mercator (UTM) is a system of geospatial mapping that separates the globe into 60 zones, each with their own coordinate plane. The origin of each coordinate plane is at the center of the zone and will tell you the number of meters east and north of the origin.

Using the utm library, you can produce a tuple with the easting, northing, zone number, and zone letter. Keep note of the order within the tuple. Since each value is not labeled, the easting and northing can be easily confused.

In case you found your way here as a primary UTM user who wants to go the other direction, the library includes a method to convert a UTM tuple to a latitude/longitude tuple.


Convert to GeoJSON

GeoJSON is an open-source standard format for representing geospatial objects such as points, lines, and polygons. It is used by many GIS applications and is a logical next step if you have static latitude/longitude data from legacy data collection.

Using the geojson package, you can create each of these GIS shapes with a simple function call for the corresponding shape with the necessary information.

Notice that for a point, the coordinate tuple is passed directly, whereas the coordinate tuples are within a list when creating a line.


I hope these quick tips are helpful as you work with traditional coordinate data. Please leave your comments and questions down below!

Better Programming

Advice for programmers.

Jonathan Hsu

Written by

I’m a black belt problem-solver (literally) who likes to share his process. I enjoy the taking on new challenges and building mastery for tomorrow. 🥋

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade