Skip to content

How to determine if a coordinate locates within any distance from a reference point such as center of city – Python

Simple code project in Python GIS tutorial

example

Use-Case: 

I wanted to create consistency and customization in how geographical units such as city is defined in my data. I have a set of observation with their address coordinates within different cities and states/provinces. Based on the use-case, we decided to defined city label in this data based on being located within a radius of 50 km from city centers in the data. Here’s is a practical code piece doing this job.

The video tutorial, complementing this blog, can be seen here:


Step1 Initial Settings

We add the necessary packages here and also connect the python code to google sheets where the sample data on coordinates exist there.

Read input data from google sheets:

Dateset 1: called coords data. This is a sample of coordinates latitudes and longitudes that we want to specify whether they exist in a specific radius of X kilo-meters or miles from specific reference points such as center downtowns of some cities Dataset 2: called reference data. This is the set of reference points

Step2: overview the data and data cleaning fixes if needed

Step3: define the main function

Identifying whether a given point exist in a specific R distance from a reference point

last step save the data in a google sheet tab

Related links

1 thought on “How to determine if a coordinate locates within any distance from a reference point such as center of city – Python”

Leave a Reply

Your email address will not be published. Required fields are marked *