SRTM DEM with Python/Basemap

Hi,

i didn’t wrote anything in weeks, so it is time to change that. My goal for the next few months is to replace all my GIS stuff with little Python-scripts. So here is a simple one, which plots SRTM data with basemap and gdal. This is quite easy but a little bit slow!

First you need - surprise- SRTM-data (as GeoTIFFs). These are available for free in the net (even corrected versions!)

You can merge them to one file with this command:

gdal_merge.py -o out.tiff SRTM*.tiff

The rest is easy. The can be read in Python with

gdal.Open(‘path/to/tiff’).ReadAsArray()

into a numpy-array. You only need to create a basemap of your area. Then you need to mesh a grid within the basemap and plot the GeoTIFF using that grid with contourf()!

Here is the complete code:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
from osgeo import gdal

s1 = gdal.Open(‘srtm/thur.tif’).ReadAsArray()
s1m = np.ma.masked_less(s1,s1<0)

ThuringianMap = Basemap(llcrnrlon=6,
                        llcrnrlat=46.2,
                        urcrnrlon=16.6,
                        urcrnrlat=55.6,
                        projection=’tmerc’,lon_0=9,lat_0=0,
                        resolution=’i’)

levels = np.arange(100,1000,25)
x = np.arange(10.3,11,0.1)
y = np.arange(50.4,51,0.1)

lons = np.linspace(10,12,np.shape(s1m)[1])
lats = np.linspace(52,50,np.shape(s1m)[0])
x, y = ThuringianMap(*np.meshgrid(lons, lats))
cs = ThuringianMap.contourf(x, y, s1m, levels,alpha=0.6)
              
ThuringianMap.drawrivers(color=’blue’)
ThuringianMap.drawcountries()
ThuringianMap.drawcoastlines()
ThuringianMap.drawmeridians(np.arange(6,17,1))
ThuringianMap.drawparallels(np.arange(46,57,1))

plt.show()

And here is what it looks like. A map of Germany (with borders, coastlines and rivers) and a color-coded height map between the Harz-mountains and the Thuringian Forest:

Have fun!

P.S. The code is faster and has an acceptable reasolution on this scale with resolution=’i’, Full or high resolutions is really slow!

"Dancing Sundogs" Das heutige APOD. Sehr coole Sache. Wahrscheinlich richten sich die Eiskristalle im Elektrischen Feld neu aus. Das E-Feld ändert sich rapide bei Blitzentladungen!

theguywhomarriedjuliecooper:

I liked this video.

Seismic activity in Germay

A lot of small Earthquakes in Germany these days.

Seismic swarms at Voigtland Region

and ML4.6 Quake near the border to Holland.

http://linap6.geo.uni-leipzig.de/cgi-bin/plot.cgi?day=08&month=SEP&year=2011&hours=19&min=03&stations=MOX&lang=de&sec=00&kanal=BH&komponente=Z&length=800&filter=none&zoom=1.0

Recent Swarm Earthquakes in Czech/Germany (Voigtlang Region)

Recent Swarm Earthquakes in Czech/Germany (Voigtlang Region)

bonesinabox:

Why do geologists love beer?

(via bonesinabox-deactivated20130217)

Me having a snack in Norway.

Me having a snack in Norway.

Grantic augen gneiss near Preikestolen (Norway).
Does anyone know how this structure could be formed?

Grantic augen gneiss near Preikestolen (Norway).

Does anyone know how this structure could be formed?