-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rasterio example in docs (#1881)
* Fix rasterio example in docs * Review
- Loading branch information
Showing
3 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
.. _recipes.rasterio_rgb: | ||
============================ | ||
imshow() and map projections | ||
============================ | ||
Using rasterio's projection information for more accurate plots. | ||
This example extends :ref:`recipes.rasterio` and plots the image in the | ||
original map projection instead of relying on pcolormesh and a map | ||
transformation. | ||
""" | ||
|
||
import os | ||
import urllib.request | ||
import xarray as xr | ||
import cartopy.crs as ccrs | ||
import matplotlib.pyplot as plt | ||
|
||
# Download the file from rasterio's repository | ||
url = 'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif' | ||
urllib.request.urlretrieve(url, 'RGB.byte.tif') | ||
|
||
# Read the data | ||
da = xr.open_rasterio('RGB.byte.tif') | ||
|
||
# Normalize the image | ||
da = da / 255 | ||
|
||
# The data is in UTM projection. We have to set it manually until | ||
# https://github.com/SciTools/cartopy/issues/813 is implemented | ||
crs = ccrs.UTM('18N') | ||
|
||
# Plot on a map | ||
ax = plt.subplot(projection=crs) | ||
da.plot.imshow(ax=ax, rgb='band', transform=crs) | ||
ax.coastlines('10m', color='r') | ||
plt.show() | ||
|
||
# Delete the file | ||
os.remove('RGB.byte.tif') |