OSGeoLive-Notebooks/Cartopy/cartopy-feature-creation.ipynb

111 lines
2.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Feature Creation\n",
"----------------\n",
"\n",
"This example manually instantiates a\n",
":class:`cartopy.feature.NaturalEarthFeature` to access administrative\n",
"boundaries (states and provinces).\n",
"\n",
"Note that this example is intended to illustrate the ability to construct\n",
"Natural Earth features that cartopy does not necessarily know about\n",
"*a priori*.\n",
"In this instance however, it would be possible to make use of the\n",
"pre-defined :data:`cartopy.feature.STATES` constant."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"import matplotlib.pyplot as plt\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"from matplotlib.offsetbox import AnchoredText\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" fig = plt.figure()\n",
" ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())\n",
" ax.set_extent([80, 170, -45, 30], crs=ccrs.PlateCarree())\n",
"\n",
" # Put a background image on for nice sea rendering.\n",
" ax.stock_img()\n",
"\n",
" # Create a feature for States/Admin 1 regions at 1:50m from Natural Earth\n",
" states_provinces = cfeature.NaturalEarthFeature(\n",
" category='cultural',\n",
" name='admin_1_states_provinces_lines',\n",
" scale='50m',\n",
" facecolor='none')\n",
"\n",
" SOURCE = 'Natural Earth'\n",
" LICENSE = 'public domain'\n",
"\n",
" ax.add_feature(cfeature.LAND)\n",
" ax.add_feature(cfeature.COASTLINE)\n",
" ax.add_feature(states_provinces, edgecolor='gray')\n",
"\n",
" # Add a text annotation for the license information to the\n",
" # the bottom right corner.\n",
" text = AnchoredText(r'(c) {}; license: {}'\n",
" ''.format(SOURCE, LICENSE),\n",
" loc=4, prop={'size': 10}, frameon=True)\n",
" ax.add_artist(text)\n",
"\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"main()"
]
},
{
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}