Wednesday, April 11, 2018

Scrape data from Google maps

Scrapping data from Google maps made by third party

Often, you will find Google maps published by someone you don't have access to and you really want to extract some data from the map.

Lets consider this map below, assuming it was published by someone you don't know and you have to have access to the raw data behind the map.



When you click on individual features on the map, the required data of that point is displayed on the left side panel. Now, the task is to extract or collect those data for every point feature on the map into a spreadsheet for further use/consumption.




Step to extract the data

Here is how to go about extracting such dataset.

Step 1: On the main page, click on the three vertical dots to expand the menu


Step 2: Select "Download KML" to download a file that can be read by Google Earth software, text editor and other GIS software.




Step 3: Open this downloaded KML file in any software of your choice to access the data contained there in. In my case, I used QGIS to open the kml file and exported the content into a CSV/Excel spreadsheet.

That is it!
Now if you come across any Google maps that you want to access the data used in preparing the map, that is how to go about accessing it. Enjoy!

Sunday, April 8, 2018

GPS coordinates of INEC Offices across the country

Find GPS coordinates of INEC Offices in Nigeria

Few days ago, I wrote on finding addresses of INEC states' offices. I even showed the locations of each INEC state headquarters on Google maps.

On this post, you will find list of Latitude and Longitude GPS coordinates of INEC offices across the country. There is at least on major office in each state of the federation, here is the list below:-

STATE
Name
Latitude
Longitude
Abia
INEC Abia Hqtr, Umuahia
5.525982
7.513276
Adamawa
INEC Adamawa Hqtr, Jimeta
9.28333
12.46667
Akwa-Ibom
INEC Akwa-Ibom Hqtr, Calabar
4.9988714
8.334555
Anambra
INEC Anambara Hqtr, Awka
6.234931
7.080384
Bauchi
INEC Bauchi Hqtr, Bauchi
10.31689
9.8296
Benue
INEC Benue Hqtr, Makurdi
7.709681
8.527267
Borno
INEC Borno Hqtr, Maiduguri
11.8436599
13.0861767
Bayelsa
INEC Bayelsa Hqtr, Yenagoa
4.9378742
6.2714292
Cross-River
INEC Cross-River Hqtr, Calabar
5.011425
8.329815
Delta
INEC Delta Hqtr, Asaba
6.218859
6.683576
Ebonyi
INEC Ebonyi Hqtr, Abakaliki
6.3267112
8.1099312
Edo
INEC Edo Hqtr, Benin City
6.3496306
5.6609366
Ekiti
INEC Ekiti Hqtr, Ekiti
7.63232
5.21787
Enugu
INEC Enugu Hqtr, Enugu
6.4562096
7.5294245
FCT
INEC Nigeria Hqtr, Abuja
9.039736
7.4846524
Gombe
INEC Gombe Hqtr, Gombe
10.290956
11.133903
Imo
INEC Imo Hqtr, Owerri
5.476379
7.010559
Jigawa
INEC Jigawa Hqtr, Dutse
11.71923
9.35991
Kebbi
INEC Kebbi Hqtr, Birnin Kebbi
12.4527
4.20065
Kaduna
INEC Kaduna Hqtr, Kaduna
10.5478485
7.4566833
Kogi
INEC Kogi Hqtr, Lokoja
7.80137152
6.746167975
Kano
INEC Kano Hqtr, Kano
12.027758
8.522139
Katsina
INEC Katsina Hqtr, Katsina
12.991684
7.638025
Kwara
INEC Kwara Hqtr, Ilorin
8.4801977
4.4988242
Lagos
INEC Lagos Hqtr, Lagos
6.5089256
3.3801858
Niger
INEC Niger Hqtr, Minna
9.615976
6.5656279
Nassarawa
INEC Nasarawa Hqtr, Lafia
8.53333
8.55
Ondo
INEC Ondo Hqtr, Alagbaka
7.24653
5.217
Ogun
INEC Ogun Hqtr, Abeokuta
7.1259889
3.3588871
Osun
INEC Osun Hqtr, Osogbo
7.791994
4.54179
Oyo
INEC Oyo Hqtr, Ibadan
7.398063938
3.978493573
Plateau
INEC Plateau Hqtr, Jos
9.8629268
8.8662419
Rivers
INEC Rivers Hqtr, Port Harcourt
4.817084248
7.009455249
Sokoto
INEC Sokoto Hqtr, Sokoto
13.06092
5.23902
Taraba
INEC Taraba Hqtr, Jalingo
8.879033
11.385662
Yobe
INEC Yobe Hqtr, Damaturu
11.7444
11.96255
Zamfara
INEC Zamfara Hqtr, Gusau
12.190819
6.661709

If you find any inconsistent or missing data, please let me know to correct immediately at: umaryusuf49 (at) gmail.com.


Thank you for following.

Friday, April 6, 2018

How to setup MySQL Database on PythonAnyWhere.com

Hello there,
PythonAnyWhere.com is one of the platforms that allows you to easily host scripts written in python. In this post, I will show how to setup a database server on the platform and load in data from a simple python script.

There are several databases supported on the PythonAnyWhere.com platform. the common once are:-
1- SQLite (a server less database that requires not setup at all)
2- MySQL (a server based database available for free account holders)
3- PostgreSQL (a server based database available for paid account holders)

I will be using the MySQL database for this demonstration as it is the one that requires setup and is available to every on account (free and paid accounts).

Step 1:
If you haven't already, create a free account on PythonAnyWhere.com


Step 2:
Login to your account dashboard and go to the "Databases" tab. Then Create a database by specifying the Database name and MySQL password




Step 3:
After creating a Database name and MySQL password, you should have a MySQL Console added to you list of consoles under the console tab. The name will look like this: MySQL: username$dbname



Open it and you should have your MySQL console running just like mine...



Step 4:
Now, you can enter MySQL commands to interact with your MySQL database via the console. For example, lets display the databases and tables in our account by entering: show databases; and show tables;



Step 5:
To create a table, enter this query....
CREATE TABLE test_table (
id int,
member_id int,
status varchar(255)
);
The above query creates a new table named "test_table" with three fields namely; 'id', 'member_id' and 'status'. The 'id' and 'member_id' fields are integer fields while 'status' is a varchar.



Connecting your app/script:
To connect your web application or any python .py script to the database, you simply
host='username.mysql.pythonanywhere-services.com'
user='username'
pass='password'
database='username$databasename'
For example if you are using the MySQLdb module, you connection will look like this:-
conn = MySQLdb.connect(
    host='username.mysql.pythonanywhere-services.com',
    user='username',
    passwd='pass123',
    db='username$your_db_name')


That is it!
You have learned how to create a MySQL database on PythonAnyWhere.

Note: To create another database, just repeat step 2 above. Also, note that whatever database name and password you specified at that point are the credentials you will use if you a connecting to the database from an external script such as python .py script.