Skip to content
Snippets Groups Projects
Commit 0d9c7037 authored by Marvin Kastner's avatar Marvin Kastner
Browse files

Minor changes

parent 8acb4063
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Punkte und Polygone # Punkte und Polygone
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. 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.
Dies kann bspw. mit dem Modul `shapely` einfach überprüft werden. Dies kann bspw. mit dem Modul `shapely` einfach überprüft werden.
Weitere geometrische Figuren und Methoden sind in der [Dokumentation von shapely](https://shapely.readthedocs.io/en/stable/manual.html) nachlesbar. Weitere geometrische Figuren und Methoden sind in der [Dokumentation von shapely](https://shapely.readthedocs.io/en/stable/manual.html) nachlesbar.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from shapely.geometry import Point from shapely.geometry import Point
from shapely.geometry import Polygon from shapely.geometry import Polygon
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Einführendes Beispiel ## Einführendes Beispiel
![title](Quadrat.png) ![title](Quadrat.png)
Zunächst wird ein Punkt und ein Polygon definiert. Zunächst wird ein Punkt und ein Polygon definiert.
Das Polygon entspricht einem Quadrat, der `point_1` liegt genau in der Mitte. Das Polygon entspricht einem Quadrat, der `point_1` liegt genau in der Mitte.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
point_1 = Point((.5, .5)) point_1 = Point((.5, .5))
polygon = Polygon(((0, 0), (0, 1), (1, 1), (1, 0))) polygon = Polygon(((0, 0), (0, 1), (1, 1), (1, 0)))
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Ob sich der Punkt im Polygon befindet, kann über die Methode `contains` abgefragt werden. Ob sich der Punkt im Polygon befindet, kann über die Methode `contains` abgefragt werden.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
polygon.contains(point_1) polygon.contains(point_1)
``` ```
%% Output %% Output
True True
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Der nächste Punkt liegt nun eindeutig außerhalb des Quadrats. Der nächste Punkt liegt nun eindeutig außerhalb des Quadrats.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
point_2 = Point((2, 2)) point_2 = Point((2, 2))
polygon.contains(point_2) polygon.contains(point_2)
``` ```
%% Output %% Output
False False
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Polygone auf Karten
Polygone können auch mithilfe von Geo-Koordinaten erstellt werden.
Dafür wird anstellen mit eines Ellipsoiden mit einem 2d-Rechteck gearbeitet.
%% Cell type:markdown id: tags:
![title](Hamburg.png) ![title](Hamburg.png)
Webseite: https://www.keene.edu/campus/maps/tool/ Webseite: https://www.keene.edu/campus/maps/tool/
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
hamburg_rathaus = Point((9.9937391, 53.5513486)) hamburg_rathaus = Point((9.9937391, 53.5513486))
hamburg = Polygon(((10.23, 53.62), (10.21, 53.75), (9.93, 53.67), (9.72, 53.63), (9,72, 53.5), (10, 53.4), (10.26, 53.47), (10.23, 53.62))) ```
%% Cell type:code id: tags:
``` python
hamburg = Polygon(((10.23, 53.62), (10.21, 53.75), (9.93, 53.67), (9.72, 53.63), (9,72, 53.5), (10, 53.4),
(10.26, 53.47), (10.23, 53.62)))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
hamburg.contains(hamburg_rathaus) hamburg.contains(hamburg_rathaus)
``` ```
%% Output %% Output
True True
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
bremen = Point((8.8014221, 53.0756713)) bremen = Point((8.8014221, 53.0756713))
hamburg.contains(bremen) hamburg.contains(bremen)
``` ```
%% Output %% Output
False False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment