diff --git a/01-introduction-geospatial-data.ipynb b/01-introduction-geospatial-data.ipynb index 5c00070..cbcaa5c 100644 --- a/01-introduction-geospatial-data.ipynb +++ b/01-introduction-geospatial-data.ipynb @@ -182,6 +182,40 @@ "africa.plot()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: create a plot of South America\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "countries.head()" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -486,6 +520,31 @@ "Note the different scale of x and y." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: project the countries to [Web Mercator](http://epsg.io/3857), the CRS used by Google Maps, OpenStreetMap and most web providers.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -512,6 +571,34 @@ "See the [04-more-on-visualization.ipynb](04-more-on-visualization.ipynb) notebook for more details on visualizing geospatial datasets." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: replicate the figure above by coloring the countries in black and cities in yellow\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -629,6 +716,37 @@ "source": [ "See http://geopandas.readthedocs.io/en/latest/gallery/create_geopandas_from_pandas.html#sphx-glr-gallery-create-geopandas-from-pandas-py for full example" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: use [geojson.io](http://geojson.io) to mark five points, and create a `GeoDataFrame` with it. Note that coordinates will be expressed in longitude and latitude, so you'll have to set the CRS accordingly.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] } ], "metadata": { @@ -647,7 +765,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.5" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/02-spatial-relationships-operations.ipynb b/02-spatial-relationships-operations.ipynb index c413dcc..945093a 100644 --- a/02-spatial-relationships-operations.ipynb +++ b/02-spatial-relationships-operations.ipynb @@ -125,8 +125,41 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "You can recognize the abstract shape of Belgium.\n", + "You can recognize the abstract shape of Belgium." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", "\n", + "**Exercise**: produce a similar figure as above that includes France, Spain, Paris, Madrid, and a line that connects both capitals" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "Brussels, the capital of Belgium, is thus located within Belgium. This is a spatial relationship, and we can test this using the individual shapely geometry objects as follow:" ] }, @@ -302,6 +335,32 @@ "" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: find all of the countries contiguous to Brazil" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -326,7 +385,7 @@ "metadata": {}, "outputs": [], "source": [ - "geopandas.GeoSeries([belgium, brussels.buffer(1)]).plot(alpha=0.5, cmap='tab10')" + "geopandas.GeoSeries([belgium, brussels.buffer(1), brussels]).plot(alpha=0.5, cmap='tab10')" ] }, { @@ -399,6 +458,52 @@ "africa" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: Create a single polygon for Europe" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "**Exercise**: Create a single polygon with all of the countries that you would have to cross to travel directly (as the crow flies) from Beijing to Sydney" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "code", "execution_count": null, @@ -445,7 +550,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.5" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/03-spatial-joins.ipynb b/03-spatial-joins.ipynb index 12fb751..66f6f37 100644 --- a/03-spatial-joins.ipynb +++ b/03-spatial-joins.ipynb @@ -239,6 +239,92 @@ "joined['continent'].value_counts()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: Which rivers pass within 1 degree of Paris? And for Hong Kong?\n", + "\n", + "Tip: `rivers` contains empty geometries, make sure to get rid of them before anything else\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise** [PRO]: Find all European cities within 1 degre of at least one river\n", + "\n", + "\n", + "This requires:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Obtaining a list of European cities\n", + "1. Creating a `GeoDataFrame` with all river lines\n", + "1. For every European city, checking whether at least one river \"crosses\" the area within 1 degree\n", + "1. If so, saving the record of a city" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -300,6 +386,45 @@ "\n", "" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: if we define rural as those areas that are not within 50Km of the centre of a city, what is the extention of rural North America? What is the percentage that it covers?\n", + "\n", + "Tip: make sure your projection allows you to calculate distances in metres ([wink wink](http://epsg.io/3083))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] } ], "metadata": { @@ -318,7 +443,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.5" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/04-more-on-visualization.ipynb b/04-more-on-visualization.ipynb index 563c2df..bc34a29 100644 --- a/04-more-on-visualization.ipynb +++ b/04-more-on-visualization.ipynb @@ -90,6 +90,32 @@ "ax.set_axis_off()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: create a 12 by 12 plot of the world rivers without axes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -144,6 +170,36 @@ "ax.set_axis_off()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: create an equal interval map of the length of world rivers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -176,6 +232,39 @@ "ax.set(xlim=(-20, 60), ylim=(-40, 40))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### `matplotlib`tic approach\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "f, ax = plt.subplots(1, figsize=(15, 10))\n", + "countries.plot(edgecolor='k', facecolor='none', ax=ax)\n", + "rivers.plot(ax=ax)\n", + "cities.plot(ax=ax, color='C1')\n", + "ax.axis('equal')\n", + "ax.set(xlim=(-20, 60), ylim=(-40, 40))\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "\n", + "**Exercise**: make a map of Europe with its rivers and cities\n", + "\n", + "---" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -346,7 +435,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.5" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/img/TopologicSpatialRelarions2.png b/img/TopologicSpatialRelarions2.png new file mode 100644 index 0000000..bf0e631 Binary files /dev/null and b/img/TopologicSpatialRelarions2.png differ