Question

I have some polylines (an array of coordinates, representing a route)

I also have a polygon (a rectanble made from 4 coordinates)

They are used in Google Maps (API v3).

--

I need to know if any of theese polylines intersect the polygon, and if so, wich polyline(s) intersects?

I'm hoping for a function I can send the polygon object and polyline array to, so it will return a list of intersecting polylines.

For example to be called like:

var result = checkForIntersects(radiusPoly, polylines);

The result could be "0,1" if the first two polylines intersects, or "" if none intersects.

Hope it makes sense :-)

Sample polygon and polylines available here: JSfiddle (Update 2018-02-01: Sorry, I just noticed my example no longer works. But the coordinates are there. Better than nothing, I guess.)

Was it helpful?

Solution

From what I can tell, there is currently no way of achieving what I was hoping for.

Overlapping polygons can be detected, but polylines only if one of the points are accually inside the polygon.

In short: I could not find a way to detect if a polyline with points on either side of a polygon, was accually "touching" the polygon.

A workaround could have been to take each "leg" of the polyline, split into several lines (256 for example, depending on the resolution you need), and checking each of these points, to see if they are inside the polygon.

This however, was much to slow for what I needed, since it would result i many many thousands of points to be checked individually.

Also it's more of a hack than a solution, and I don't approve of that in a solution ment for production.

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