stplanpy.srtm module

This module performs operations on the Digital Elevation Model (DEM) from the NASA Shuttle Radar Topographic Mission (SRTM).

stplanpy.srtm.elev(points: geopandas.geodataframe.GeoDataFrame, file_name, tmp_dir='tmp') geopandas.geodataframe.GeoDataFrame

Compute the elevation at the locations in the points GeoDataFrame

Read a (zipped) GeoTIFF file, reproject it the right coordinate reference system (crs), and use it to compute the elevation at the locations give in the points GeoDataFrame.

Parameters
  • points – GeoDataFrame with points at which the elevation is computed.

  • file_name (str) – Name and path of the (zipped) GeoTIFF file.

  • tmp_dir (str, defaults to "tmp") – Name of temporary directory to store reprojected GeoTIFF file and extract the zip archive to.

Returns

DataFrame with elevation data

Return type

pandas.DataFrame

Examples

The example data file, “srtm_12_05.zip”, can be downloaded from github.

import pandas as pd
import geopandas as gpd
from shapely import wkt
from stplanpy import srtm

# Create GeoDaFrame with some points
df = pd.DataFrame(
{"tazce": ["00101565", "00101589", "00101488", "00101503", "00101594"],
'coordinates': ["POINT(-11822098.758 4499746.118)",
"POINT(-11820711.661 4497355.121)", "POINT(-11820275.989 4496557.912)",
"POINT(-11826751.214 4506575.748)", "POINT(-11823373.407 4503632.347)"]})

# Parse wkt format:
df['coordinates'] = gpd.GeoSeries.from_wkt(df['coordinates'])

# Create GeoDataFrame
points = gpd.GeoDataFrame(df, geometry="coordinates")

# Set coordinate reference system (crs)
points = points.set_crs("EPSG:6933")

# Compute elevation at points
points = points.elev("srtm_12_05.zip")
stplanpy.srtm.reproj(file_name_in, file_name_out, crs='EPSG:6933')

Reproject a GeoTIFF file

Read a GeoTIFF file, reproject it to another coordinate reference system (crs), and write it to disk. The default crs is “EPSG:6933”.

Parameters
  • file_name_in (str) – Name and path of the input GeoTIFF file.

  • file_name_out (str) – Name and path of the output GeoTIFF file.

  • crs (str, defaults to "EPSG:6933") – The coordinate reference system (crs) of the output GeoTIFF file.

Examples

The example data file, “srtm_12_05.zip”, can be downloaded from github.

import os
import shutil
import zipfile
from stplanpy import srtm

# Extract to temporal location
with zipfile.ZipFile("srtm_12_05.zip", "r") as zip_ref:
    zip_ref.extractall("tmp")

# reproject GeoTIFF file and write to disk
srtm.reproj("tmp/srtm_12_05.tif", "srtm_12_05_EPSG6933.tif")

# Clean up tmp files
shutil.rmtree("tmp")