.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "vaporApplicationReference/imageRenderer/makeGeotiff.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_vaporApplicationReference_imageRenderer_makeGeotiff.py: makeGeotiff.py ========================= This script creates a GeoTiff image that can be read by VAPOR, when given a set of lat/lon coordinates. It performs the the following: - Takes user-specified lat/lon coordinates to query NASA's WorldView WTMS server for satellite imagery - WTMS servers and layers can be changed by modifying the "url" and "layer" global variables - A NaturalEarth shapfile describing roads in North America are added to the produced GeoTiff - Coastlines are added to the map through Cartopy .. GENERATED FROM PYTHON SOURCE LINES 15-25 .. code-block:: default # sphinx_gallery_thumbnail_path = '_images/map.png' targetDir = "/Users/pearse/" fileName = "landSat_test2" west = -105.5 north = 40.25 east = -104.75 south = 39.6 .. GENERATED FROM PYTHON SOURCE LINES 26-31 Size of our output figure. Note: If your specified lat/lon extents have a different aspect ratio than your width and height, the geotiff will have either its dimensions scaled to match the aspect ratio of the specified extents of the west/north/east/south variables. .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: default width = 1920 height = 1080 .. GENERATED FROM PYTHON SOURCE LINES 35-38 For the generated tiff to have the correct width and height, the "dpi" variable must be set according to that of your monitor. To find your DPI, see here: https://www.infobyip.com/detectmonitordpi.php .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: default dpi = 96 .. GENERATED FROM PYTHON SOURCE LINES 41-42 URL for NASA's EarthData/WorldView web map tile service .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: default url = 'https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi' .. GENERATED FROM PYTHON SOURCE LINES 45-54 Specify the layer from the EarthData WMTS to draw to our geotiff. See Vapor's Image Renderer documentation for a complete list of available layers. Some options include: MODIS_Terra_CorrectedReflectance_TrueColor Landsat_WELD_CorrectedReflectance_Bands157_Global_Annual VIIRS_CityLights_2012 GOES-West_ABI_Band2_Red_Visible_1km To preview these layers, visit https://worldview.earthdata.nasa.gov/ .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: default layer = 'Landsat_WELD_CorrectedReflectance_TrueColor_Global_Annual' .. GENERATED FROM PYTHON SOURCE LINES 57-58 Generate our matplotlib figure with a subplot to draw our map upon .. GENERATED FROM PYTHON SOURCE LINES 58-71 .. code-block:: default import matplotlib.pyplot as plt import cartopy.crs as ccrs fig = plt.figure( figsize=(width/dpi, height/dpi), tight_layout=True ) ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree()) ax.add_wmts(url, layer) ax.set_extent( [west, east, south, north], crs=ccrs.PlateCarree() ) .. GENERATED FROM PYTHON SOURCE LINES 72-73 Add coastlines from Cartopy .. GENERATED FROM PYTHON SOURCE LINES 73-75 .. code-block:: default ax.coastlines(resolution='50m', color='yellow') .. GENERATED FROM PYTHON SOURCE LINES 76-77 Add roads from NaturalEarth .. GENERATED FROM PYTHON SOURCE LINES 77-84 .. code-block:: default import cartopy.feature as cf ax.add_feature( cf.NaturalEarthFeature('cultural', 'roads_north_america', '10m'), edgecolor='yellow', facecolor='none' ) .. GENERATED FROM PYTHON SOURCE LINES 85-86 Generate our initial tiff file .. GENERATED FROM PYTHON SOURCE LINES 86-93 .. code-block:: default tiffFile = targetDir + fileName + ".tif" fig.savefig( tiffFile, bbox_inches='tight', pad_inches=0 ) .. GENERATED FROM PYTHON SOURCE LINES 94-95 Write our tiff file with GeoTiff extent information .. GENERATED FROM PYTHON SOURCE LINES 95-105 .. code-block:: default from osgeo import gdal gdal.OpenShared( tiffFile, gdal.GA_Update) translatedTiff = targetDir + fileName + "Translated.tif" gdal.Translate( srcDS=tiffFile, destName=translatedTiff, format = 'GTiff', outputBounds = [ west, north, east, south ], outputSRS = 'EPSG:4326' ) .. GENERATED FROM PYTHON SOURCE LINES 106-108 Give our GeoTiff file a projected coordinate system, equivalent to the following proj4 string: Proj4: "+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84" .. GENERATED FROM PYTHON SOURCE LINES 108-114 .. code-block:: default gdal.Warp( destNameOrDestDS=tiffFile, srcDSOrSrcDSTab=translatedTiff, srcSRS = 'EPSG:4326', dstSRS='EPSG:32662' ) .. GENERATED FROM PYTHON SOURCE LINES 115-116 Clean up intermediate translated file .. GENERATED FROM PYTHON SOURCE LINES 116-118 .. code-block:: default import os os.remove(translatedTiff) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_vaporApplicationReference_imageRenderer_makeGeotiff.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: makeGeotiff.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: makeGeotiff.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_