Reverse GeoCoding with QGIS (And bypass costly GoogleMap API calls)
Here is the problem.
The data we collect from BASS users (www.projectbass.org) contain GPS coordinates (Latitude and Longitude). These are not readily readable by us humans. We needed a way to add geographic labels like Region, Province, Municipality and Barangay. In the IT world, we call this process Reverse Geocoding.
The usual route an IT guy like me would take is to make an API (application programming Interface) call to a map service like Google Maps API. We send it the GPS coordinate, and Google Map API will return with the geographic labels the GPS data belongs to. But not only is this cumbersome, it also has a price per API call.
QGIS to the Rescue
Since we have the barangay boundary information from the nice folks at PHILGIS.org, it should be possible for us to extract the information based on the boundaries that the GPS point falls inside of. In layman’s terms, if the GPS is inside Bonuan Gueset, Dagupan City, Pangasinan, Philippines, we should be able to add these geographic labels BACK to the GPS data table.
It turns out there is a simple and brilliant solution using QGIS. It uses the [Join Attributes by Location] And here are the steps I followed from https://www.qgistutorials.com/en/docs/3/performing_spatial_joins.html
We load two layers (the data layer and the shape layer). I used Layer/Add Layer/Add Delimited Text Layer for my CSV file. I used Layer/Add Layer/Add Vector Layer for my Barangay.shp file. We should end up with this:
A zoom in view will reveal the dots (GPS points of BASS measures) and the boundaries of each Barangay in Pangasinan.
Layered view of Pangasinan over OpenStreet Maps, Barangay boundaries and GPS measures
Add Geographic Labels to GPS data
Choose Join Attributes by Location as pictured below:
Select the “Join Attributes by Location” option
Then fill in the required settings as shown in the picture below:
As to which predicates to use: https://en.wikipedia.org/wiki/DE-9IM#Spatial_predicates
Once you hit “run” this is the next screen…
Once the process completes, you will see a NEW layer. Right click on that new layer and select [Export][Save Vector Layer as: CSV]. Your GPS coordinates will now have the Region, Province, City/Municipality and Barangay Labels!