Commit a5d873dd authored by Marvin Kastner's avatar Marvin Kastner
Browse files

Add "Punkte und Polygone", "Weite Distanzen auf dem Globus"

parent 8349c41c
**/.ipynb_checkpoints
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Punkte und Polygone\n",
"\n",
"Ob sich ein Objekt an einem bestimmten Ort aufhält können in der Geometrie als die Frage umformuliert werden, ob sich ein Punkt in einem Polygon befindet.\n",
"Dies kann bspw. mit dem Modul `shapely` einfach überprüft werden.\n",
"Weitere geometrische Figuren und Methoden sind in der [Dokumentation von shapely](https://shapely.readthedocs.io/en/stable/manual.html) nachlesbar."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from shapely.geometry import Point\n",
"from shapely.geometry import Polygon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Einführendes Beispiel\n",
"\n",
"Zunächst wird ein Punkt und ein Polygon definiert.\n",
"Das Polygon entspricht einem Quadrat, der `point_1` liegt genau in der Mitte."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"point_1 = Point((.5, .5))\n",
"polygon = Polygon(((0, 0), (0, 1), (1, 1), (1, 0)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ob sich der Punkt im Polygon befindet, kann über die Methode `contains` abgefragt werden."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"polygon.contains(point_1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Der nächste Punkt liegt nun eindeutig außerhalb des Quadrats."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"point_2 = Point((2, 2))\n",
"polygon.contains(point_2)"
]
}
],
"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.6.5"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Weite Distanzen auf dem Globus\n",
"\n",
"Anhand eines einfachen Beispiels wird gezeigt, wie sich \n",
"(a) verschiedene Ellipsoide und \n",
"(b) verschiedene Formeln zur Berechnung der Distanz auswirken.\n",
"Probieren Sie gerne auch andere Werte aus!\n",
"Mögliche Parameter lassen sich in der [Dokumentation von geopy](https://geopy.readthedocs.io/en/stable/#module-geopy.distance) finden."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from geopy import distance\n",
"import folium"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Exemplarisch wird die Distanz zwischen Hamburg und Cleveland bestimmt."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"hamburg = (53.5, 10)\n",
"cleveland = (41.45, -81.67)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zur Veranschaulichung plotten wir dies zunächst auf eine Karte"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"width:100%;\"><div style=\"position:relative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ogICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICBsZWZ0OiAwLjAlOwogICAgICAgICAgICAgICAgdG9wOiAwLjAlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICA8L3N0eWxlPgogICAgICAgIAo8L2hlYWQ+Cjxib2R5PiAgICAKICAgIAogICAgICAgICAgICA8ZGl2IGNsYXNzPSJmb2xpdW0tbWFwIiBpZD0ibWFwX2MxOTgwMmJjMTUzZjQwYTViNmIxZWJjNmE5NTFkNjQ3IiA+PC9kaXY+CiAgICAgICAgCjwvYm9keT4KPHNjcmlwdD4gICAgCiAgICAKCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgdmFyIGJvdW5kcyA9IG51bGw7CiAgICAgICAgICAgIAoKICAgICAgICAgICAgdmFyIG1hcF9jMTk4MDJiYzE1M2Y0MGE1YjZiMWViYzZhOTUxZDY0NyA9IEwubWFwKAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ21hcF9jMTk4MDJiYzE1M2Y0MGE1YjZiMWViYzZhOTUxZDY0NycsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7Y2VudGVyOiBbNDUsLTQ1XSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHpvb206IDMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhCb3VuZHM6IGJvdW5kcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxheWVyczogW10sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JsZENvcHlKdW1wOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyXzA0NmRmNzI4ZDA0YjQzZTNiNzM2YjA5OGI4NmVhODhlID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAnaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmcnLAogICAgICAgICAgICAgICAgewogICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICJtYXhab29tIjogMTgsCiAgIm1pblpvb20iOiAxLAogICJub1dyYXAiOiBmYWxzZSwKICAic3ViZG9tYWlucyI6ICJhYmMiCn0KICAgICAgICAgICAgICAgICkuYWRkVG8obWFwX2MxOTgwMmJjMTUzZjQwYTViNmIxZWJjNmE5NTFkNjQ3KTsKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgY2lyY2xlX21hcmtlcl85YWFiYjY0MWMxZTk0MTAxYmJmNjU4MTU2NWEzODMxOCA9IEwuY2lyY2xlTWFya2VyKAogICAgICAgICAgICAgICAgWzUzLjUsMTBdLAogICAgICAgICAgICAgICAgewogICJidWJibGluZ01vdXNlRXZlbnRzIjogdHJ1ZSwKICAiY29sb3IiOiAiIzMzODhmZiIsCiAgImRhc2hBcnJheSI6IG51bGwsCiAgImRhc2hPZmZzZXQiOiBudWxsLAogICJmaWxsIjogZmFsc2UsCiAgImZpbGxDb2xvciI6ICIjMzM4OGZmIiwKICAiZmlsbE9wYWNpdHkiOiAwLjIsCiAgImZpbGxSdWxlIjogImV2ZW5vZGQiLAogICJsaW5lQ2FwIjogInJvdW5kIiwKICAibGluZUpvaW4iOiAicm91bmQiLAogICJvcGFjaXR5IjogMS4wLAogICJyYWRpdXMiOiAxMCwKICAic3Ryb2tlIjogdHJ1ZSwKICAid2VpZ2h0IjogMwp9CiAgICAgICAgICAgICAgICApLmFkZFRvKG1hcF9jMTk4MDJiYzE1M2Y0MGE1YjZiMWViYzZhOTUxZDY0Nyk7CiAgICAgICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBjaXJjbGVfbWFya2VyXzZiOTRiYzIxYzg5NjRlZWM4MjYxNjlkZGE1YzhkMjdiID0gTC5jaXJjbGVNYXJrZXIoCiAgICAgICAgICAgICAgICBbNDEuNDUsLTgxLjY3XSwKICAgICAgICAgICAgICAgIHsKICAiYnViYmxpbmdNb3VzZUV2ZW50cyI6IHRydWUsCiAgImNvbG9yIjogIiMzMzg4ZmYiLAogICJkYXNoQXJyYXkiOiBudWxsLAogICJkYXNoT2Zmc2V0IjogbnVsbCwKICAiZmlsbCI6IGZhbHNlLAogICJmaWxsQ29sb3IiOiAiIzMzODhmZiIsCiAgImZpbGxPcGFjaXR5IjogMC4yLAogICJmaWxsUnVsZSI6ICJldmVub2RkIiwKICAibGluZUNhcCI6ICJyb3VuZCIsCiAgImxpbmVKb2luIjogInJvdW5kIiwKICAib3BhY2l0eSI6IDEuMCwKICAicmFkaXVzIjogMTAsCiAgInN0cm9rZSI6IHRydWUsCiAgIndlaWdodCI6IDMKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfYzE5ODAyYmMxNTNmNDBhNWI2YjFlYmM2YTk1MWQ2NDcpOwogICAgICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
],
"text/plain": [
"<folium.folium.Map at 0x271aca25f60>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"world_map = folium.Map(location=(45, -45), zoom_start=3)\n",
"marker = folium.CircleMarker(location=hamburg)\n",
"marker.add_to(world_map)\n",
"marker = folium.CircleMarker(location=cleveland)\n",
"marker.add_to(world_map)\n",
" \n",
"world_map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Verschiedene Ellipsoide führen zu verschiedenen Entfernungen bei der geodätischen Distanz."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6548.180670303868\n",
"6547.553054810947\n"
]
}
],
"source": [
"print(distance.geodesic(hamburg, cleveland, ellipsoid='GRS-80').km)\n",
"print(distance.geodesic(hamburg, cleveland, ellipsoid='Airy (1830)').km)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Verschiedene Formeln führen zu verschiedenen Entfernungen."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6548.180670250658\n",
"6530.029728113453\n"
]
}
],
"source": [
"print(distance.distance(hamburg, cleveland).km)\n",
"print(distance.great_circle(hamburg, cleveland).km)"
]
}
],
"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.6.5"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment