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.

Monday, March 19, 2018

Geolocating INEC State Offices

Hello there,
Counting from today (19th of March, 2018), Nigeria: General Elections 2019 (Time until Saturday, 16 February 2019) is less than 360 days away.

 INEC SCHEDULES 2019 GENERAL ELECTIONS FOR SATURDAY 16TH FEBRUARY AND SATURDAY 2ND MARCH 2019


In this post, I will share with you how you can Geocode and Map INEC State Offices. The final product will be useful for finding direction to the INEC State Offices using Google map navigation system.


The Data

The dataset is a CSV file that contains list of addresses of INEC State Offices. This list has no geographical information (as seen below), so I will be converting the address into geographical location in form of latitude and longitude (a process know as geocoding) after which I will map the addresses on an interactive map. With this map, you can find you direction to any of the addresses of INEC State Offices by panning and zooming around the map.




The Tools

I will use a python module to geocode the addresses and then use Google maps to map the addresses.

Let's get started...

Wednesday, March 14, 2018

Convert OpenStreetMap of Abuja in Raster to Vector map

Hello there,
In this post, I will demo how to easily download the vector map of the city center of Abuja, Nigeria. We will be converting and OpenStreetMap Raster map to Vector map suing QGIS and related plugins.

Simply download and install QGIS with the following plugins: OpenStreetMap Downloader and OpenLayer plugins




Steps to follow...

Step 1:
From QGIS menu go to Web >> OpenLayers plugin >> OpenStreetMap >> OpenStreetMap


When the OpenStreetMap layer finished loading, zoom to Abuja metropolis or any area you want to download its vector map.



Step 2: Next, go to: Vector >> OpenStreetMap >> Download Data


On the dialog box that opened, specify the extent and select where to save the .OSM file, then click on OK to run the process. This will download all points, line and polygon feature with the area selected.



Step 3: Load the .osm file into QGIS just as you will load any other vector file. The result is as seen below....


That is it!


Note: Another useful plugin to get information from OSM is the OSMInfo plugin.


Thursday, March 8, 2018

An Interactive Map of Nigeria showing State Governors

Hello there,

Here I present to you an Interactive Map of Nigeria that showcase the states and their Governors in picture (we can add more states' attribute if we want to).

Just point your mouse over any state to reveal the name of the state, the governor's name, the governor's picture etc.

The following interactive map presents a visualization of Nigeria's state governors. Governors are elected for a term of four years (maximum of two terms). A person shall be eligible for the office of Governor if he or she is a citizen of Nigeria by birth, at least 35 years of age, is a member of a political party and is sponsored by that political party. The constitution limits state governors to only two four-year terms in office.









Happy viewing....

Do you like the map you saw above? Would you like to have a similar map made for you? Give me a call or send me an email: +2348039508010 or umaryusuf49@gmail.com

Tuesday, March 6, 2018

Distance Between Two Geographic Coordinates (Latitude and Longitude)

Using python to compute distance between two latitude and longitude points

Latitude and Longitude coordinates assume the earth is sphere in shape (i.e NOT flat). So, since the earth is a sphere, you can't use the distance formula that works for two points in a plane. Instead you will use a formular that approximates and assumes the earth is a sphere or ellipsoid namely:-
1- Vincenty formula
2- Haversine formula
3- Great-circle distance
4- Spherical Law of Cosines formula for distance calculations


Here are some Python based Geographic Coordinates distance calculations using Haversine formula and Vincenty formula.

First lets see how to calculate the distance between two point on a flat plane using the distance formula
            Distance=(x2−x1)2+(y2−y1)2−−−−−−−−−−−−−−−−−−√



In python it should look like this...

def distance(x1, y1, x2, y2):
     dist = ((x1 - x2)**2 + (y1-y2)**2)**.5 
     return dist

x1, y1, x2, y2 = 3.52, 7.02, 10.55, 9.60

print (distance(x1, y1, x2, y2)) # Result is 7.49meters

Friday, March 2, 2018

QGIS Multipart to Singleparts


Here we have an administrative polygon layer with series of Islands as seen below...



Now, we don't want the Islands to be part of the main polygon, so we have to split them apart. Thanks to the "Multipart to Singleparts" command tool under the "Vector >> Geometry Tools" menu. This command takes a vector layer with multipart geometries and generates a new one in which all geometries contain a single part. Features with multipart geometries are divided in as many different features as parts the geometry contain, and the same attributes are used for each of them.







Happy reading :)

Monday, February 26, 2018

Export Shapefile Attribute to Text File using PyQGIS

Hello there,

Lets use QGIS python scripting (PyQGIS) to create a text file of attributes from a shapefile.

Here I loaded onto QGIS a point layer representing capitals of Nigeria states with four attributes namely: "State_name", "Capital", "Area" and "Population".




Open the python console and with the point layer selected on the layers panel, enter the code below on the console to create an active layer object.
layer = iface.activeLayer()



Wednesday, February 14, 2018

Deploying python Flask web app on Amazon Lightsail

Hello there,

Let me start off this with this question "What is Flask and Amazon Lightsail"?

Chances are you already know what a Flask web framework is (a light weight python web framework), so I will only give a brief on Amazon Lightsail before we deploy a simple flask app on it.

Amazon Lightsail is a Virtual Private Servers (VPS) which enables you to easily set up servers on the Amazon Web Services (AWS) cloud. It is also a fast and simple VPS hosting service from Amazon.

Alternatives to Amazon Lightsail include Heroku, DigitalOcean, Linode, Microsoft Azure etc



How to deploy Flask applications on a Virtual Private Server (VPS) running Ubuntu OS, Apache server, and WSGI


Step 1: Use your existing Amazon account or sign up for a new to subscribe for a LightSail VPS service. You can get this for as low as $5 per month.






Step 2: By now you should have you flask app fully developed and ready for deployment. My app is a simple one that doesn't require a database, so I will skip and for of database configuration.





Wednesday, January 17, 2018

Identifying the type of shapefile in a given folder

Python script to separate shapefile based on type (Point, Line and Polygon)

A shapefile can be point, line or polygon. When in a folder there is no way to know what type it is until you opened it in a GIS environment such as QGIS or ArcGIS. That means you have to install a heavy duty software just to know what type of shapefiles you have in a given directory/folder. Also if you have thousands of shapefiles to identify their type, that will be a lot of work and also time consuming to access each shapefile via a GIS environment to identity its type.

Here is a smart solution in using Python that will allow you to determine the shapefile type in an efficient manner. Run the script once and it tells you what type of shapefile it is.

Lets get started...

The code

The script makes use of a python module called "PyShp". It reads the shapefiles contained in a given folder and classify them based on there type.


import glob
import shapefile
# Read in all the SHP and DBF files in the directory/folder
shp_files = glob.glob("path_to_folder\\foldername\\*.shp")
dbf_files = glob.glob("path_to_folder\\foldername\\*.dbf")

# loop through the files
for s, d in zip(shp_files, dbf_files):
    shp = open(s, 'rb')
    dbf = open(d, 'rb')
    complete_shp = shapefile.Reader(shp=shp, dbf=dbf)
    
    # Close the files for further usage..
    shp.close()
    dbf.close()
    
    # Checking the type of shapefile (Point=1, Line=3 or Polygon=5/Polygonz=15)?
    #     complete_shp.shapes()[0].shapeType
    # --------------POINT SHP ----------------------
    if complete_shp.shapeType == shapefile.POINT:
        print ("This is a POINT Shapefile")

    # --------------LINE SHP ----------------------        
    if complete_shp.shapeType == shapefile.POLYLINE:
        print ("This is a LINE Shapefile")
        
    # --------------POLYGON SHP ----------------------        
    if complete_shp.shapeType == shapefile.POLYGONZ:
        print ("This is a POLYGON Shapefile")

First we import the glob module to read contents of a directory and the shapefile module to read shapefiles. Next, we loop through the files and use if conditional statement to check if the shapefile is a point, line or polygon type.

Note: you can perform additional actions after you have identified the type by adding the relevant code snippet just below the conditional statements.




The list above was extracted from the PyShp github repo. It shows that Shapefile types are represented by numbers between 0 and 31 as defined by the shapefile specification.

That is it!


The video shows demo of the script...