{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'NoneType' object has no attribute 'RasterXSize'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0;31m#Get the dimentions of column and row\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0mnc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRasterXSize\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 37\u001b[0m \u001b[0mnr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRasterYSize\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'RasterXSize'" ] } ], "source": [ "# pip install --user https://github.com/matplotlib/basemap/archive/master.zip\n", "\n", "import os\n", "from mpl_toolkits.basemap import Basemap\n", "import matplotlib.pyplot as plt\n", "from osgeo import gdal\n", "from osgeo import osr\n", "import numpy as np\n", "import math\n", "\n", "#Plot setup\n", "fig= plt.figure(figsize=(10,8))\n", "\n", "ax = plt.subplot(111,aspect = 'equal')\n", "plt.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0, hspace=0)\n", "\n", "#Map setup\n", "map = Basemap(resolution='f', projection='cyl', llcrnrlon=-75, llcrnrlat=-5, urcrnrlon=-46, urcrnrlat=0)\n", "\n", "parallels = np.arange(-50,50,1.)\n", "meridians = np.arange(0,360,1)\n", "\n", "map.drawparallels(parallels,labels=[1,0,0,0],color='w', fontsize=10, fontweight='bold')\n", "meri = map.drawmeridians(meridians,labels=[0,0,0,1],color='w', fontsize=10, fontweight='bold')\n", "\n", "#Load colormap and setup elevation contour levels\n", "cmap=plt.get_cmap(\"jet\")\n", "clevs = np.linspace(0, 305, 21)\n", "\n", "# Load GeoTiff data\n", "raster = 'geo_dem_v2_52-50.tif'\n", "\n", "ds = gdal.Open(raster)\n", "\n", "#Get the dimentions of column and row\n", "nc = ds.RasterXSize\n", "nr = ds.RasterYSize\n", "\n", "#Read elevation data\n", "data = ds.ReadAsArray()\n", "\n", "#Get Longitude and Latitude info\n", "geotransform = ds.GetGeoTransform()\n", "xOrigin = geotransform[0]\n", "yOrigin = geotransform[3]\n", "pixelWidth = geotransform[1]\n", "pixelHeight = geotransform[5]\n", "\n", "#Generate Longitude and Latitude array\n", "lons = xOrigin + np.arange(0, nc)*pixelWidth\n", "lats = yOrigin + np.arange(0, nr)*pixelHeight\n", "\n", "#Contour plot\n", "x, y = map(*np.meshgrid(lons, lats))\n", "cs=map.contourf(x, y, data, clevs, cmap=cmap)\n", "\n", "map.drawparallels(parallels,labels=[1,0,0,0],color='k', fontsize=10, fontweight='bold')\n", "meri = map.drawmeridians(meridians,labels=[0,0,0,1],color='k', fontsize=10, fontweight='bold')\n", "\n", "cb = map.colorbar(cs, 'bottom', size='5%', pad='10%')\n", "\n", "cb.set_label('Elevation (m)', fontsize=12, fontweight='bold')\n", "cb.ax.tick_params(labelsize=10)\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }