How to check if geocode is close to or on path defined in a KML LineString with PHP or MySQL

StackOverflow https://stackoverflow.com/questions/1750040

  •  20-09-2019
  •  | 
  •  

Question

I have a KML file defining several paths/routes (representing actual roads) enclosed in the <LineString><coordinates></coordinates></LineString> tags. Parsing the file to other formats (arrays/MySQL) is already in place, so that's not a problem.

Given a point (longitude/latitude) I would like to be able to check if the point is on or close to (within a few meters) one of the routes in the KML file. I've been looking for a solution in PHP, but I haven't been able to find one - and I'm not really sure, what I'm looking for. This does however seem to me like a common problem, so I suspect someone already solved the problem. Does anybody know of a solution? ;)

Thanks in advance!

Was it helpful?

Solution

You need to break this down into two problems:

  • Generate a set of polygons from each section of your path.
  • Do a simple point in polygon test on the above polygons.

There should be some php out there to accomplish those two tasks.

OTHER TIPS

pnpoly is actually quite fast if done correctly. I wrote a check against many hundreds of thousands of polygon vertices in MySQL well under second processing. Pulling the data into PHP and performing the pnpoly loop there can do it in not a whole lot more time.

Post the code you're using?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top