Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Nearest point on polygon from a point #51

Open
sumit2201 opened this issue May 16, 2019 · 6 comments
Open

[Feature] Nearest point on polygon from a point #51

sumit2201 opened this issue May 16, 2019 · 6 comments

Comments

@sumit2201
Copy link

No description provided.

@sumit2201
Copy link
Author

With Reference to this requirement
https://stackoverflow.com/questions/56048358/using-php-find-nearest-point-in-polygon-from-a-given-point

I want to find nearest point on polygon(An Area on map) from a particular point (Lat, Long).
Can you please help if this library support such functionality or is it achievable by any means in PHP only>

@acidjazz
Copy link

@sumit2201 did you ever happen to find this elsewhere?

@sumit2201
Copy link
Author

I could not find any PHP solution for this, and my requirement was GIS centric, so I used postGIS queries to find nearest point. I used ST_ClosestPoint of postGIS/postgresql.
@acidjazz We can close this requirement if you want

@acidjazz
Copy link

@sumit2201 Lets keep it open since its a sweet feature, last question, did St_CLosestPoint give you the actual point that was found on the Line? and not only the distance?

@mjaschen
Copy link
Owner

Hi,

is such an implemention available in source code in any language and with a permissive license? If that's the case, I'd be happy to translate it to PHP and integrate it into phpgeo.

@acidjazz
Copy link

acidjazz commented Dec 13, 2019

@mjaschen I think you're pretty darn close already.

You have your PerpendicularDistance utility which I use in combination with polygon getSegments() to find the closest segment

foreach ($this->polygon->getSegments() as $line) {
    if ($line->getLength($haversine) !== 0.0) {
        $polyline = new Polyline();
        $polyline->addPoint($line->getPoint1());
        $polyline->addPoint($line->getPoint2());
        $distances[] = [
           'value' => $perp->getPerpendicularDistance($this->point, $line),
           'geometry' => json_decode($formatter->format($polyline), true),
        ];
    }
}
usort($distances, function($a, $b) {
    return $a['value'] - $b['value'];
});

return reset($distance)

All that I think is missing from this @mjaschen is getting that Utility to tell us WHERE on the line did you find was the closest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants