\n", "\n", "**REMEMBER:**
\n", "\n", "* A `GeoDataFrame` allows to perform typical tabular data analysis together with spatial operations\n", "* A `GeoDataFrame` (or *Feature Collection*) consists of:\n", " * **Geometries** or **features**: the spatial objects\n", " * **Attributes** or **properties**: columns with information about each spatial object\n", "\n", "
\n", "\n", "**REMEMBER**:

\n", "\n", "Single geometries are represented by `shapely` objects:\n", "\n", "* If you access a single geometry of a GeoDataFrame, you get a shapely geometry object\n", "* Those objects have similar functionality as geopandas objects (GeoDataFrame/GeoSeries). For example:\n", " * `single_shapely_object.distance(other_point)` -> distance between two points\n", "\n", " * `geodataframe.distance(other_point)` -> distance for each point in the geodataframe to the other point\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting our different layers together" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = countries.plot(edgecolor='k', facecolor='none', figsize=(15, 10))\n", "rivers.plot(ax=ax)\n", "cities.plot(ax=ax, color='red')\n", "ax.set(xlim=(-20, 60), ylim=(-40, 40))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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": [ "## Let's practice!\n", "\n", "For the exercises, we are going to use some data of the city of Paris:\n", "\n", "- The administrative districts of Paris (https://opendata.paris.fr/explore/dataset/quartier_paris/): `paris_districts_utm.geojson`\n", "- Real-time (at the moment I downloaded them ..) information about the public bicycle sharing system in Paris (vĂ©lib, https://opendata.paris.fr/explore/dataset/stations-velib-disponibilites-en-temps-reel/information/): `paris_sharing_bike_stations_utm.geojson`\n", "\n", "Both datasets are provided as GeoJSON files.\n", "\n", "Let's explore those datasets:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "\n", "* Read both datasets into a GeoDataFrame called `districts` and `stations`.\n", "* Check the type of the returned objects (with `type(..)`)\n", "* Check the first rows of both dataframes. What kind of geometries do those datasets contain? \n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data1.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data2.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data3.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data4.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "\n", "* Make a plot of the `districts` dataset.\n", "* Set the figure size to (12, 6) (hint: the `plot` method accepts a figsize keyword).\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data5.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "\n", "* Make a plot of the `stations` dataset (also with a (12, 6) figsize).\n", "* Use the `'available_bikes'` colums to determine the color of the points. For this, use the `column=` keyword.\n", "* Use the `legend=True` keyword to show a color bar.\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data6.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "
\n", "
• Visualize the `stations` and `districts` datasets together on a single plot (of 20, 10)).
• \n", "
• Use a grey color for the `districts` dataset with an alpha of 0.5, but use black lines (tip: `edgecolor`).
• \n", "
• You can use `ax.set_axis_off()` to remove the axis (tick)labels.
• \n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data7.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "

\n", "

\n", "
• What is the largest district? (the biggest area)
• \n", "
\n", "

\n", "
HintYou can find the location of the largest value with `.idxmax()`
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data8.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data9.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "\n", "
\n", "
• Make a histogram showing the distribution of the number of bike stands in the stations.
• \n", "
\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/01-introduction-geospatial-data10.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "\n", "* Add a column `'population_density'` representing the number of inhabitants per squared kilometer (Note: The area is given in squared meter, so you will need to multiply the result with `10**6`).\n", "* Plot the districts using the `'population_density'` to color the polygons.\n", "\n", "