Charting map of Nepal using geojson

Plotting Maps can be tricky if we don't have the right tools

Plotting maps can be a daunting task, especially when the visual analytics platforms don’t specifically support the geo-recognition of the political maps (on both national and local level) for countries like Nepal.

And charting maps is not something that we can move ahead with just the datasets ready like we would do in preparing our typical histograms, pie charts, box charts, whiskers – which can be pretty straightforward once we have the required dataset.
But with geo-plotting the data we need the geographical identities of the area we are going to plot – which is easy if your analytics platform supports it but it can be a nightmare otherwise.

However, with the right tools and techniques, it can become a straightforward process. In this post- let’s walk through the essential steps of plotting maps using GeoJSON data and plotly library in python.

Understanding geojson data

The first step in plotting maps is obtaining the GeoJSON data for the geographical area you want to visualize. GeoJSON is a format for encoding various geographic data structures, including points, lines, polygons, and more. We can find GeoJSON data for different regions from various sources, including government agencies, open data repositories, or community platforms like GitHub.

GeoJSON uses latitude and longitude figures to define the spatial extent and geometry of geographic features. Each point, line, or polygon in a GeoJSON feature is defined by its geographical coordinates, typically specified as pairs of latitude and longitude values.

In the context of a Polygon geometry, multiple [longitude, latitude] pairs represent the boundary of a closed shape. The first and last pairs usually represent the same point to close the polygon. The coordinates define the vertices of the polygon, and consecutive pairs are connected by straight lines to enclose the area.

Here’s an example of a GeoJSON Polygon geometry representing a closed shape (a polygon) with multiple [longitude, latitude] pairs defining its boundary:

            {
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [100.0, 0.0],
        [101.0, 0.0],
        [101.0, 1.0],
        [100.0, 1.0],
        [100.0, 0.0]  // Closing point (same as the first point)
      ]
    ]
  },
  "properties": {
    "name": "Example Polygon",
    "area": 1.0
  }
}

        

First, getting your geojson data

For our example, let’s say we want to plot a map of Nepal. National Geoportal is the government source where you can find the geospatial data relating to Nepal. I also found another GeoJSON data for Nepal’s districts on GitHub platforms. National Geoportal requires creating account and verification – so we will use the GeoJSON data from GitHub and then we’re ready to move on to the next step.

Here is the link: GitHub – mesaugat/geoJSON-Nepal

Second, using your visual analytics platform

The next step is to use a visual analytics platform to plot the map using the GeoJSON data. There are several tools available for this purpose, your typical visualizers like Power BI or Tableau or Google Looker Studio. But for our purposes we will use Python. 

One popular choice is Folium, a Python library that makes it easy to create interactive maps. Folium allows you to visualize spatial data on an interactive Leaflet map, making it ideal for exploring and analyzing geographical datasets. With Folium, we can customize your maps with various features like markers, choropleths, tooltips, and more. It provides a simple and intuitive interface for creating visually appealing maps with minimal code.

Last, pairing your geojson data with geographical datasets

Once we have our GeoJSON data and choose our visualization platform, the final step is to pair our GeoJSON data with relevant geographical datasets. These datasets can include information like population demographics, economic indicators, environmental data, and more.

For example, let’s say we want to create a population choropleth map of Nepal, where each district is shaded based on its population density. We can pair our GeoJSON data of Nepal’s districts with a dataset containing population data for each district. By combining these datasets, we can create an informative and visually appealing map that highlights population distribution across Nepal.

In conclusion, plotting maps using GeoJSON data is a powerful way to visualize geographical information. By following these steps and leveraging the right tools, we can create compelling maps that effectively communicate insights from your data.

Here is the link to the data from 2079 Census district wise – obtained from National Statistical Office: Census Nepal 2021
Cleaned up Excel Data: https://sushilparajuli.com/wp-content/uploads/2024/06/census2021.xlsx

A Google Colab to try it out

Link to Google Colab: Google Collaboratory Link
Click this to see the result in separate html file: Census Data 2079 Plotted District Wise