\n", "REFERENCE:

\n", "\n", "Overview of the different functions to check spatial relationships (*spatial predicate functions*):\n", "\n", "* `equals`\n", "* `contains`\n", "* `crosses`\n", "* `disjoint`\n", "* `intersects`\n", "* `overlaps`\n", "* `touches`\n", "* `within`\n", "* `covers`\n", "\n", "\n", "See https://shapely.readthedocs.io/en/stable/manual.html#predicates-and-relationships for an overview of those methods.\n", "\n", "See https://en.wikipedia.org/wiki/DE-9IM for all details on the semantics of those operations.\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Let's practice!\n", "\n", "We will again use the Paris datasets to do some exercises. Let's start importing them again:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "districts = geopandas.read_file(\"data/paris_districts_utm.geojson\")\n", "stations = geopandas.read_file(\"data/paris_sharing_bike_stations_utm.geojson\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE:\n", "\n", "\n", "* Create a shapely `Point` object for the Notre Dame cathedral (which has x/y coordinates of (452321.4581477511, 5411311.330882619))\n", "* Calculate the distance of each bike station to the Notre Dame.\n", "* Check in which district the Notre Dame is located.\n", " \n", "
\n", "REMEMBER:

\n", "\n", "GeoPandas (and Shapely for the individual objects) provides a whole lot of basic methods to analyse the geospatial data (distance, length, centroid, boundary, convex_hull, simplify, transform, ....), much more than the few that we can touch in this tutorial.\n", "\n", "\n", "* An overview of all methods provided by GeoPandas can be found here: http://geopandas.readthedocs.io/en/latest/reference.html\n", "\n", "\n", "
\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Let's practice!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " EXERCISE: What are the districts close to the Seine?\n", " \n", "

\n", " Below, the coordinates for the Seine river in the neighbourhood of Paris are provided as a GeoJSON-like feature dictionary (created at http://geojson.io). \n", "

\n", " \n", "

\n", " Based on this `seine` object, we want to know which districts are located close (maximum 150 m) to the Seine. \n", "

\n", " \n", " \n", "

\n", "

\n", "
• Create a buffer of 150 m around the Seine.
• \n", "
• Check which districts intersect with this buffered object.
• \n", "
• Make a visualization of the districts indicating which districts are located close to the Seine.
• \n", "
\n", "

\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# created a line with http://geojson.io\n", "s_seine = geopandas.GeoDataFrame.from_features({\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[2.408924102783203,48.805619828930226],[2.4092674255371094,48.81703747481909],[2.3927879333496094,48.82325391133874],[2.360687255859375,48.84912860497674],[2.338714599609375,48.85827758964043],[2.318115234375,48.8641501307046],[2.298717498779297,48.863246707697],[2.2913360595703125,48.859519915404825],[2.2594070434570312,48.8311646245967],[2.2436141967773438,48.82325391133874],[2.236919403076172,48.82347994904826],[2.227306365966797,48.828339513221444],[2.2224998474121094,48.83862215329593],[2.2254180908203125,48.84856379804802],[2.2240447998046875,48.85409863123821],[2.230224609375,48.867989496547864],[2.260265350341797,48.89192242750887],[2.300262451171875,48.910203080780285]]}}]},\n", " crs={'init': 'epsg:4326'})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# convert to local UTM zone\n", "s_seine_utm = s_seine.to_crs(epsg=32631)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "fig, ax = plt.subplots(figsize=(20, 10))\n", "districts.plot(ax=ax, color='grey', alpha=0.4, edgecolor='k')\n", "s_seine_utm.plot(ax=ax)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# access the single geometry object\n", "seine = s_seine_utm.geometry.squeeze()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/02-spatial-relationships-operations5.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/02-spatial-relationships-operations6.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/02-spatial-relationships-operations7.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "clear_cell": true }, "outputs": [], "source": [ "# %load _solved/solutions/02-spatial-relationships-operations8.py" ] }, { "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }