Wednesday, April 28, 2021

Merge images to PDF Using 'Python Imaging Library' (PIL)

 This script will merge any given amount of images into a single PDF file.

from PIL import Image

# List of images... 4 images in this case, so we should get a pdf with 4 pages.
image_files = [r"C:\Users\Yusuf_08039508010\Desktop\L1.jpeg", r"C:\Users\Yusuf_08039508010\Desktop\L2.jpeg", r"C:\Users\Yusuf_08039508010\Desktop\L3.jpeg", r"C:\Users\Yusuf_08039508010\Desktop\L4.jpeg"]

imagelist = []
for img in image_files:
    print('Processing...', img)
    # read in image
    img1 =
    # convert to RGP
    img2 = img1.convert('RGB')
    print('Done for...', img.split('\\')[-1])
# To prevent appending last image to the beginning...
start_img =[0])
start_img = start_img.convert('RGB')

# Delete first image from list 'imagelist'...
del imagelist[0] # imagelist.pop(0) or imagelist[1:]

# merge images to pdf...'merged_L1-4.pdf', save_all=True, append_images=imagelist)

That is it!

Tuesday, April 13, 2021

Testing Google Maps Geocoder API by Geocoding COVID-19 Vaccination sites in Lagos, Nigeria

 Recently, the Lagos state government listed 88 COVID-19 vaccination sites in the state. These sites cut across 20 local government areas.

Lets test how good Google Maps covers Nigeria by using the geocoder API to retrieve the 'Latitudes and longitudes' of those vaccination sites so we can plot them on Lagos state map.

Lets get stated, the list of the sites is seen below.

Friday, April 9, 2021

Extracting data from .HAR file

 A HTTP Archive file (shorten as 'HAR file'), is a JSON format used for tracking information between a web browser and a website. The common extension for these files is '.har'.

In python there is third party module called "Haralyzer" developed for getting useful stuff out of HAR files.

Since HAR files are in JSON formats, I will not use the "Haralyzer" module instead I will read the .har file and extract data from the text. Another reason I don't want to use the library is that I don't want to install new third party library on my machine most especially that the haralyzer module depends on another third library "six".

Other than that nothing wrong in using a library that reads the .har file directly.

Let's get our hands dirty...

How to get a HAR file

Practically, any website that uses JSON format as its data communication pipeline will generate a .har file on clients browser which can be accessed from the browser's developer tool.

Lets use this use this website on Earthquake data by USGS. Open the website and go to your browser developer tool, then select 'Network' tab >> XHR >> Expot HAR...

This will download a HAR files that contains JSON representation of the earthquake data as seen below...

You can save the file with any name in a location you can remember, we will use it in the next section. Note that the file is a GeoJSON with Padding.

Thursday, April 1, 2021

How to make black and white Road network map in Mapbox Studio

Mapbox Studio is a platform used by developers to prepare maps for mobile, desktop and web applications.

In this post, we are going to prepare a black and white road network map similar to what you see below.

There are many startup web applications that allow you create this kind of map and download it for a fee! In few moments, you will learn how to make your own maps and you don't have to spend money buying maps.

See an example below that cost $59.

Step-by-step instructions

  • Create a new map by clicking on "New Style" button.

  • Select from the map style templates (here we will use the Blank Template)

  • Rename the map to a suitable name and add map components and layers.

To achieve this type of map, we need to add the following map components and layers:-

  1. Road Network
  2. Land, Water and Sky
  3. Administrative Boundaries

On each component/layer adjust the settings to fit what you wanted. For example, I set the administrative boundaries base to white etc.

After which you can publish and share the map as WMTS for use in a desktop software like QGIS for further map processing as you will see below in a moment.