You are not logged in.
- Topics: Active | Unanswered
Announcement
Please create new topics on the new site at community.openstreetmap.org. We expect the migration of data will take a few weeks, you can follow its progress here.***
#1 2013-09-11 15:23:09
- 2cent
- Member
- Registered: 2013-09-04
- Posts: 6
Prüfen, ob Punkt innerhalb von Multipolygon
Hallo,
gibt es mit der OSM-API die Möglichkeit, herauszubekommen, ob ein Punkt innerhalb eines Multipolygons liegt (im konkreten Fall eines Bundeslandes)? Oder kennt jemand dazu ein entsprechendes PHP-Skript? Habe schon versucht, meine Mathematik-Kenntnisse mal wieder vorzukramen, dachte aber nach einiger Denkarbeit, dass das entsprechende Rad ja sicher schon erfunden wurde.
Vielen Dank
Johannes
Offline
#2 2013-09-11 17:16:54
- Oli-Wan
- Member

- From: NRW
- Registered: 2010-09-14
- Posts: 2,814
Re: Prüfen, ob Punkt innerhalb von Multipolygon
No animals were harmed in the writing of this posting.
Offline
#3 2013-09-12 15:26:29
- 2cent
- Member
- Registered: 2013-09-04
- Posts: 6
Re: Prüfen, ob Punkt innerhalb von Multipolygon
Vielen Dank!
Ich habe eine weitere Methode außerhalb vom OSM gefunden, den Punkt-in-Polygon-Test nach Jordan:
http://de.wikipedia.org/wiki/Punkt-in-P … ach_Jordan
Habe den Pseudocode aus dem Wikipedia-Eintrag mal in PHP übersetzt:
function punktInPolygon($p,$q) {
$n = count($p)-1;
$p[0] = $p[$n];
$t = -1;
for($i=0;$i<$n;$i++) {
$t = $t*kreuzProdTest($q,$p[$i],$p[$i+1]);
}
return $t;
}
function kreuzProdTest($A,$B,$C) {
$xA = $A[0]; $yA = $A[1];
$xB = $B[0]; $yB = $B[1];
$xC = $C[0]; $yC = $C[1];
if($yA == $yB AND $yB == $yC) {
if(($xB <= $xA AND $xA <= $xC) OR ($xC <= $xA AND $xA <= $xB)) {
return 0;
}
else {
return 1;
}
}
if($yB > $yC) {
$xBtemp = $xB;
$yBtemp = $yB;
$xB = $xC;
$yB = $yC;
$xC = $xBtemp;
$yC = $yBtemp;
}
if($yA == $yB AND $xA == $xB) {
return 0;
}
if($yA <= $yB OR $yA > $yC) {
return 1;
}
$delta = (($xB-$xA)*($yC-$yA))-(($yB-$yA)*($xC-$xA));
if($delta > 0) {
return -1;
}
elseif($delta < 0) {
return 1;
}
else {
return 0;
}
}Vielleicht kann es jemand gebrauchen!
Gruß
Johannes
Last edited by 2cent (2013-09-12 15:27:42)
Offline
#4 2013-09-12 16:08:06
- Netzwolf
- Member
- Registered: 2008-04-01
- Posts: 1,681
- Website
Re: Prüfen, ob Punkt innerhalb von Multipolygon
Nahmd,
Habe den Pseudocode aus dem Wikipedia-Eintrag mal in PHP übersetzt:
function punktInPolygon($p,$q) { $n = count($p)-1; $p[0] = $p[$n]; [...]
Ich würde an dieser Stelle schreiben:
$n = count($p);
$p[n] = $p[0]:alldieweil mit 1 beginnende Indizes beim Programmieren eher unüblich sind und somit schnell zu Fehlern führen.
Just my 2.38¢
Gruß Wolf
Last edited by Netzwolf (2013-09-12 16:23:37)
Fragen zu meinen Posts via Mastodon oder per Twitter-DM.
Offline