Sunday, May 19, 2019

Connecting to a Google Sheet from Python Script

It is very common when working with data sets in python to save processed data onto a local spreadsheet file. After which you will attached and send such a file to other users in some other locations. In a situation where you want the spreadsheet file to be readily available to those users as you push in process data, then you need to share a cloud hosted spreadsheet such as 'Google Sheet'.

So, in this post I will share with you how you can use python to connect to a 'Google Sheet' located in your Google Drive and push in data right from a python script running on your local machine. This post will guide you on loading data from a local python script into cloud based spreadsheet (Google Sheet).

Let's get started...

Python Google Sheet setup instructions

1)  Configuring Google account
a)  Go to: https://console.cloud.google.com/apis/dashboard and create a new project, give it a name and open it. You can use existing project if you already created one before.


Here my project is named “PySpreadSheetExample”.

b)  Open the project and enable “Google Drive API” and “Google Sheet API” by clicking on ‘Enable API and Services’ button.



You will search for “Google Drive API” and “Google Sheet API” and click on the ‘Enable’ button for each.




Wednesday, May 1, 2019

Geographic Coordinates Order - Latitude Longitude OR Longitude Latitude

There is this frustrating inconsistency in working with geospatial data as to whether an array of numbers like this "9.071, 7.499" means Latitude, Longitude OR Longitude, Latitude?

I have personally wasted valuable time when am using a new GIS tool trying to figure out the right coordinate order recognized by the tool.

Obviously, some GIS platforms use Latitude, Longitude while some uses Longitude, Latitude. The question now is which is the correct coordinates order? This is an opinion with no right answer. Vocal and written geographical theory favors Latitude, Longitude. Numerical and software prefer Longitude, Latitude.

It common to describe a location as *the Latitude and Longitude of ABC is "9.071, 7.499"*, thereby mentioning Latitude first instead of the Longitude. However technically speaking mathematics, Latitude represents Y coordinate while Longitude represents X coordinate. So Latitude, Longitude implies Y, X while Longitude, Latitude is X, Y.

If you include altitude or height (Z) of ABC location the two coordinates ordering above will read: Latitude, Longitude, Height (Y, X, Z) and Longitude, Latitude, Height (X, Y, Z) respectively.

The most common ordering is XYZ - Longitude, Latitude, Height. However, if you decide to adopt YXZ - Latitude, Longitude, Height you could still be right. The most important thing is for you to know the right order you need when working with a GIS platform especially a new one you haven't used before.

As an example, Google GIS products (such google maps, google earth, etc) use the format YXZ - Latitude, Longitude, Height. ESRI ArcGIS and QGIS adopted the format XYZ - Longitude, Latitude, Height.

This coordinate "9.071, 7.499" on Google maps is the Y, X- Latitude, Longitude values of "Millennium Park (Wupa River)", if you change the order like this "7.499, 9.071" (i.e X, Y - Longitude, Latitude) it points to a different location from the intended location in this case an Unnamed Road.