Constructing A Topographic Map of Nepal Utilizing Python


Introduction

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

Studying Aims

  • Acquire proficiency in knowledge evaluation methods for digital elevation knowledge.
  • Discover ways to use geospatial knowledge and associated evaluation instruments in Python.
  • Purchase data of mapping methods.
  • Develop expertise in efficient knowledge visualization for communication.
  • Perceive the significance of elevation for inequality and poverty.

This text was revealed as part of the Information 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 worthwhile device 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 personal sector tasks round infrastructure growth, to establish areas weak to pure disasters or with restricted entry to important companies, equivalent to 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 put up, we are going to use Python to create a topographic map for Nepal, a rustic with a very fascinating topographic atmosphere.

Information Description

To generate our map, we are going to depend on knowledge revealed by the United States Geological Survey (USGS). USGS is a scientific company of the USA federal authorities that generates knowledge and analysis round pure assets, geology, geography, water assets, and pure hazards. To get to their knowledge web page, kind “USGS Information” in Google or click on the hyperlink that directs you to their Earth Explorer. The Earth Explorer is a web-based device and knowledge portal that lets you search, entry, and obtain a variety of Earth science knowledge. You should arrange an account and log in to completely use the info.

Information Obtain

This weblog put up will use Nepal for instance as a consequence of its distinctive topographic traits. Nepal has some of the difficult and fascinating topographies on this 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 reveals that the topography of Nepal makes it difficult to attach the nation, ship important companies to its inhabitants, and impose dangers and obstacles to a sustainable growth path.

To this finish, we are going to 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 Information Units tab and select Digital Elevation. There are a number of choices for Digital Elevation Information, and when you may use a number of of those datasets, we are going to use the World Multi-resolution Terrain Elevation Information 2010 GMTED2010 knowledge. This knowledge supplies world 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 knowledge, 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 too can 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 knowledge and mix them later. You will notice that the ensuing knowledge set is in a tif format, which signifies raster knowledge.

Topographic Map | Python

Python supplies a number of instruments for geospatial evaluation. On this weblog put up, we depend on the Rasterio library that makes it potential to learn and write geospatial raster knowledge (gridded knowledge). Let’s get began and browse 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 = rasterio.open(r'path10n060e_20101117_gmted_mea075.tif')
dataset = file.learn()
print(dataset.form)

Let’s additionally add the second mosaic and mix them by merging them. To this finish, we comply with commonplace raster knowledge studying and manipulation methods in Python as follows:

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


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

#Create empty listing
src_files_to_mosaic = []

#Append the listing with each recordsdata
src_files_to_mosaic.append(file)
src_files_to_mosaic.append(file2)
src_files_to_mosaic

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

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

#Replace Metadata
output_meta.replace(
    {"driver": "GTiff",
        "top": mosaic.form[1],
        "width": mosaic.form[2],
        "remodel": out_trans,
    }
)

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

with rasterio.open(out_fp, "w", **output_meta) as dest:
        dest.write(mosaic)

#Open the mixed raster knowledge
file_mosaic = rasterio.open(out_fp)

#Learn the info
dataset_mosaic = file_mosaic.learn()
print(file_mosaic.form)

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

World Multi-resolution Terrain Elevation Information

We now have a mixed World Multi-resolution Terrain Elevation Information 2010 GMTED2010 knowledge for all of Nepal, however the file additionally covers giant components of the encompassing space that aren’t a part of Nepal. Let’s limit 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 knowledge 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 knowledge, and clipped_transform, which represents the transformation info 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')

#Limit to Nepal
nepal = df.loc[df.name=="Nepal"]
nepal.head()

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

#

There may be one remaining downside. The no knowledge values in raster knowledge 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 downside as follows, as described in this weblog put up:

  • Let’s construct a perform that takes care of no knowledge values. We assemble a no-data parameter to specify the worth thought of “no knowledge” within the clipped array. On this case, it’s set to (np.amax(clipped_array[0]) + 1), which implies that it is the same as the utmost worth within the clipped array plus one. This worth will likely be thought of because the “no knowledge” worth.
  • Regulate 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 current one (the seismic one) and outline our background colour for the “no knowledge” values.
  • Within the final step, we plot the map with the brand new colour vary referred to as new_seismic.
#Let's examine no knowledge values

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

#Change worth of nodata to at least one 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
print(value_range)


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

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

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

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

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

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

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

plt.savefig(r'pathTopographic_Map_Nepal.png', bbox_inches="tight")
plt.present()
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.

Conclusion

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

Policymakers or practitioners can now use this map for additional evaluation, equivalent to combining it with different maps, equivalent to maps of poverty, or pure disasters, to investigate if there may be some connection. We have now generated a worthwhile device 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 a vital position in city planning, service supply, and inequality.
  • Python has helpful instruments for analyzing geospatial knowledge.
  • Taking good care of no knowledge values in one of these knowledge is essential for visualization.
  • Visualizing geospatial knowledge can generate worthwhile info at disaggregated ranges.

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

Often Requested Questions

Q1. What’s on a topographic map?

A. Topographic maps comprehensively symbolize a particular 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 supply 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 knowledge. Geospatial knowledge 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 knowledge obtained from numerous sources, such because the Shuttle Radar Topography Mission (SRTM), Canadian elevation knowledge, Spot 5 Reference3D knowledge, and the Ice, Cloud, and land Elevation Satellite tv for pc (ICESat). These new sources contribute to enhanced accuracy and protection of world topographic knowledge. GMTED2010 represents a major development in world topographic knowledge, facilitating numerous geospatial analyses and supporting many necessary functions.

The media proven on this article is just not owned by Analytics Vidhya and is used on the Writer’s discretion.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles