Wednesday, December 6, 2023
HomeComputer VisionConstructing A Topographic Map of Nepal Utilizing Python

Constructing A Topographic Map of Nepal Utilizing Python


Ever questioned how the topography of your nation influences financial and political improvement? Topographic maps – maps of the earth’s floor that use contour strains for visualization – can assist reply these questions! We’ll use Python to create a topographic map for Nepal, a rustic with an fascinating topographic atmosphere. You’ll learn to learn geospatial information that describes the topography of a rustic, how one can interpret this information, and how one can visualize it. The ensuing map could be mixed with different information of curiosity at very disaggregated subnational ranges to grasp how the topography of a rustic influences its financial and/or political improvement. This weblog submit will educate you how one can generate a extremely fascinating instrument that may inform insurance policies and personal sector improvement!

Studying Targets

  • Acquire proficiency in information evaluation strategies for digital elevation information.
  • Learn to use geospatial information and associated evaluation instruments in Python.
  • Purchase information of mapping strategies.
  • Develop abilities in efficient information visualization for communication.
  • Perceive the significance of elevation for inequality and poverty.

This text was printed as part of the Knowledge Science Blogathon.

What are Topographic Maps?

Topographic maps are maps of the earth’s floor that use contour strains for visualization. Topographic maps are a invaluable instrument for navigating unfamiliar terrain and function city planning and catastrophe administration inputs. They’re usually used to grasp the spatial context of insurance policies or non-public sector initiatives round infrastructure improvement, to establish areas weak to pure disasters or with restricted entry to important providers, reminiscent of schooling, healthcare, and infrastructure, or for pure useful resource administration. In the end, these maps can function enter for evidence-based decision-making. On this weblog submit, we’ll use Python to create a topographic map for Nepal, a rustic with a extremely fascinating topographic atmosphere.

Knowledge Description

To generate our map, we’ll depend on information printed by the United States Geological Survey (USGS). USGS is a scientific company of the USA federal authorities that generates information and analysis round pure sources, geology, geography, water sources, and pure hazards. To get to their information web page, kind “USGS Knowledge” in Google or click on the hyperlink that directs you to their Earth Explorer. The Earth Explorer is a web-based instrument and information portal that permits you to search, entry, and obtain a variety of Earth science information. It’s essential to arrange an account and log in to totally use the info.

Knowledge Obtain

This weblog submit will use Nepal for instance resulting from its distinctive topographic traits. Nepal has one of the crucial difficult and fascinating topographies on the planet. 8 out of the 14 mountains above 8,000 m are in Nepal (Trekking Path Nepal), and the nation is split into three very totally different topographic areas: the Mountains, Hills, and Terai (or plains) (DHS). Whereas these traits make the nation distinctive and fascinating, some analysis exhibits that the topography of Nepal makes it difficult to attach the nation, ship important providers to its inhabitants, and impose dangers and boundaries to a sustainable improvement path.

To this finish, we’ll filter for Nepal within the Search Standards, as indicated within the image beneath. As soon as we chosen Nepal, we chosen our dataset of curiosity. To take action, click on the Knowledge Units tab and select Digital Elevation. There are a number of choices for Digital Elevation Knowledge, and when you might use a number of of those datasets, we’ll use the International Multi-resolution Terrain Elevation Knowledge 2010 GMTED2010 information. This information offers international protection of the Earth’s terrain at a number of resolutions (starting from 7.5 arc-seconds (roughly 250 meters) to 30 arc-seconds (roughly 1 kilometer)). It’s generated from spaceborne and airborne distant sensing information, together with satellite tv for pc altimetry, stereo-imagery, and topographic maps.

When you select the info, click on on the Outcomes tab. Now you can obtain the info by clicking the image with obtain choices. You can even show the info through the footprint icon. We obtain the info in its highest decision (7.5 arc seconds). Importantly, to cowl all of Nepal, we have to obtain two totally different mosaics (components) of the underlying information and mix them later. You will notice that the ensuing information set is in a tif format, which signifies raster information.

Topographic Map | Python

Python offers a number of instruments for geospatial evaluation. On this weblog submit, we depend on the Rasterio library that makes it potential to learn and write geospatial raster information (gridded information). Let’s get began and skim the primary mosaic (half) of the info we beforehand downloaded into our Jupyter Pocket book:

#import related libraries (after putting in them)
import rasterio
import matplotlib.pyplot as plt
import numpy as np

#Learn the info and present the form of the dataset
file ='path10n060e_20101117_gmted_mea075.tif')
dataset = file.learn()

Let’s additionally add the second mosaic and mix them by merging them. To this finish, we observe normal raster information studying and manipulation strategies in Python as follows:

#Add second dataset and present the form of the dataset
file2 ='path30n060e_20101117_gmted_mea075.tif')
dataset2 = file2.learn()

#Mix each datasets
from rasterio.merge import merge
from rasterio.plot import present

#Create empty record
src_files_to_mosaic = []

#Append the record with each recordsdata

#Merge each recordsdata
mosaic, out_trans = merge(src_files_to_mosaic)

# Copy Metadata
output_meta = file.meta.copy()

#Replace Metadata
    {"driver": "GTiff",
        "top": mosaic.form[1],
        "width": mosaic.form[2],
        "rework": out_trans,

#Write to vacation spot
# Write the mosaic raster to disk
out_fp = r"pathNepal_Mosaic.tif"

with, "w", **output_meta) as dest:

#Open the mixed raster information
file_mosaic =

#Learn the info
dataset_mosaic = file_mosaic.learn()

#Present the info
plt.imshow(dataset_mosaic[0], cmap='Spectral')
Topographic Map | Python

International Multi-resolution Terrain Elevation Knowledge

We now have a mixed International Multi-resolution Terrain Elevation Knowledge 2010 GMTED2010 information for all of Nepal, however the file additionally covers giant components of the encircling space that aren’t a part of Nepal. Let’s prohibit the world to Nepal by utilizing a shapefile of Nepal. We’ll use a shapefile with nation borders for the world. You’ll be able to obtain this dataset right here. Let’s then clip the raster information and shapefile utilizing the masks perform. We’ll solely use the primary row of the shapefile and the geometry column. The results of this operation is saved in clipped_array, which is the clipped raster information, and clipped_transform, which represents the transformation data of the clipped raster.

import geopandas as gpd
from shapely.geometry import mapping
from rasterio import masks as msk#import csv

#Add shapefile with nation boarders of the world
df = gpd.read_file(r'path/world-administrative-boundaries.shp')

#Prohibit to Nepal
nepal = df.loc["Nepal"]

#Clip information
clipped_array, clipped_transform = msk.masks(file_mosaic, [mapping(nepal.iloc[0].geometry)], crop=True)


There may be one remaining drawback. The no information values in raster information are extremely damaging. Due to this fact, would distort the visualization of our map, as these type a part of the worth vary.

Perceive the Drawback

Let’s deal with this drawback as follows, as described in this weblog submit:

  • Let’s construct a perform that takes care of no information values. We assemble a no-data parameter to specify the worth thought of “no information” within the clipped array. On this case, it’s set to (np.amax(clipped_array[0]) + 1), which signifies that it is the same as the utmost worth within the clipped array plus one. This worth shall be thought of because the “no information” worth.
  • Alter the clipped array by including absolutely the worth of the minimal worth within the clipped array to the primary band (index 0) of the clipped array. This step ensures that every one values within the clipped array grow to be non-negative.
  • We additionally calculate the worth vary of the clipped array. It provides the utmost and absolute worth of the minimal worth within the clipped array. The value_range variable will maintain the calculated worth vary.
  • Use a manually constructed color-value dictionary primarily based on an present one (the seismic one) and outline our background coloration for the “no information” values.
  • Within the final step, we plot the map with the brand new coloration vary referred to as new_seismic.
#Let's examine no information values

nodata_value = file_mosaic.nodata 
print("Nodata worth:", nodata_value)
#Nodata worth: -32768.0

#Change worth of nodata to 1 greater than the utmost elevation
 def clip_raster(gdf, img):
     clipped_array, clipped_transform = msk.masks(img, [mapping(gdf.iloc[0].geometry)], crop=True)
     clipped_array, clipped_transform = msk.masks(img, [mapping(gdf.iloc[0].geometry)],
                                                           crop=True, nodata=(np.amax(clipped_array[0]) + 1))
     clipped_array[0] = clipped_array[0] + abs(np.amin(clipped_array))
     value_range = np.amax(clipped_array) + abs(np.amin(clipped_array))
     return clipped_array, value_range

nepal_topography, value_range = clip_raster(nepal, file_mosaic)

#Test that this labored

#Let's give the nodata worth a brand new background coloration
from matplotlib import cm
from matplotlib.colours import ListedColormap,LinearSegmentedColormap

new_seismic = cm.get_cmap('seismic', 8828)

#Outline background coloration
background_color = np.array([0.9882352941176471, 0.9647058823529412, 0.9607843137254902, 1.0])

#Use coloration map
newcolors = new_seismic(np.linspace(0, 1, 8828))

# Add the background coloration because the final row to the newcolors array.
newcolors = np.vstack((newcolors, background_color))

#Use new Italy Shade Map
new_seismic = ListedColormap(newcolors)

#Create remaining map and save
c = plt.imshow(nepal_topography[0], cmap = new_seismic)
clb = plt.colorbar(c, shrink=0.4)'Elevation (meters)',fontsize=10)

plt.savefig(r'pathTopographic_Map_Nepal.png', bbox_inches="tight")
Topographic Map | Python

Voilá! We have now a topographic map of Nepal that clearly signifies the totally different elevations within the nation and the three topographic zones.


You discovered to generate a topographic map in Python utilizing geospatial information from the United States Geological Survey (USGS). You additionally discovered the significance of caring for lacking values within the remaining dataset for visualization.

Policymakers or practitioners can now use this map for additional evaluation, reminiscent of combining it with different maps, reminiscent of maps of poverty, or pure disasters, to investigate if there may be some connection. We have now generated a invaluable instrument that may inform evidence-based decision-making in politics!

Key Takeaways

  • Topographic Maps are helpful instruments for evidence-based decision-making.
  • Topography and elevation play an important position in city planning, service supply, and inequality.
  • Python has helpful instruments for analyzing geospatial information.
  • Taking good care of no information values in this sort of information is essential for visualization.
  • Visualizing geospatial information can generate invaluable data at disaggregated ranges.

Hope you discovered this text informative. Be happy to achieve out to me on LinkedIn. Let’s join and work in direction of leveraging information for constructive change.

Incessantly Requested Questions

Q1. What’s on a topographic map?

A. Topographic maps comprehensively symbolize a selected geographical area, offering exact details about pure and human parts. They depict the terrain’s traits, together with mountains, valleys, and plains, utilizing contour strains, which point out factors of equal elevation above sea degree. Topographic maps provide an in depth file of the land’s options, enabling customers to grasp its form and elevation precisely.

Q2. What’s a topographic map used for?

A. Topography goals to exactly find numerous options and factors on the Earth’s floor utilizing a horizontal coordinate system like latitude, longitude, and altitude. It includes figuring out positions, naming recognized options, and figuring out widespread patterns of landforms. Topography seeks to grasp and symbolize the spatial association and traits of the Earth’s floor options.

Q3. What’s geospatial evaluation in Python?

A. Geospatial evaluation in Python includes utilizing Python programming language and specialised libraries to work with and analyze geospatial information. Geospatial information encompasses details about the Earth’s options and occasions, together with geographical positions, spatial connections, and traits related to these areas.

This autumn. What’s the GMTED2010 Dataset?

A. The GMTED2010 dataset advantages from the supply of higher-quality elevation information obtained from numerous sources, such because the Shuttle Radar Topography Mission (SRTM), Canadian elevation information, Spot 5 Reference3D information, and the Ice, Cloud, and land Elevation Satellite tv for pc (ICESat). These new sources contribute to enhanced accuracy and protection of worldwide topographic information. GMTED2010 represents a major development in international topographic information, facilitating numerous geospatial analyses and supporting many essential purposes.

The media proven on this article just isn’t owned by Analytics Vidhya and is used on the Creator’s discretion.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments