Working with the Google Maps API, I want to compute the intersection of a polyline and a polygon. I recall that polyline and polygon are sets of consecutive segments, the only difference is that a polygon is closed.
My first guess would be to check if any segment of the polyline intersects with any segment of the polygon. However my polylines can have up to 1e4 segments and my polygons up to 1e5 segments. Testing every pair would be too long.
Any idea of how to do that in a smarter way?
Related
I have a point (lat, lng) X and a route drawn on the google map as shown below.
In my app, I have a rule:
If the distance between point X to the nearest point that is passed by
the route is less than 5 meters, then the route can be traversed.
Otherwise, if the distance between points X to the closest point
passed by the route is equal to or greater than 5 meters, then the
route cannot be traversed.
Is this rule can be applied by using google map service?
The Google Maps Javascript API has a Geometry library.
The Geometry library has a isLocationOnEdge function. See the documentation.
To determine whether a point falls on or near a polyline, or on or near the edge of a polygon, pass the point, the polyline/polygon, and optionally a tolerance value in degrees to google.maps.geometry.poly.isLocationOnEdge(). The function returns true if the distance between the point and the closest point on the line or edge falls within the specified tolerance. The default tolerance value is 10-9 degrees.
Is there a possibilty to check that Polyline is in Polygon? Or I must check each points in Polyline containsLocation in Polygon?
I think about importing gpx files (my Polyline) and check what administrative area (my Polygons) contains this Polyline. I was thinking about reverse geocoding for each points in Polyline, but its impossible due to geocoding limitations. Any ideas?
You have to check every point of the Polyline against your Polygon. Take into account that a Polyline can be (according to DE-9IM):
Within your polygon (contained) = completely contained
Intersect your polygon = partially contained
Disjoint = not contained
So, a polyline can intersect two different Polygons (your Polyline can intersect two different administrative areas)
On one project , I recovered all the coordinates of the polygons of different postal code.
When I search a zip code, I draw the polygon using the google api.
Now I would like to know whether a given polygon is so much distance from another .
Is that possible ?
By parsing all my geojson , I need to know if a random polygon is 5km from the polygon drawn .
There is computeDistanceBetween method from the geometry library...but its for two points. Is there the same for the distance between two polygons ?
Thx u for your help
Not sure if this would solve your problem but you can somehow use this library to compute distances within your polygon.
BDCCgeo.js
There is a function called bdccGeoDistanceToPolyMtrs(), you can measure the distance between a point and a polygon edge or polyline. Perhaps you can get a certain point on your first polygon and compare with with the second using this function.
Reference:
Distance from point within a polygon to polygon edge
I need to draw polyline for the more than one vehicle that are being tracked in our Appln in PHP and google map. Could any one plz tell me how to draw poly line for multiple vehicle with latitude and longitude got from Mysql Database.
You'll have to fish out your lat and lon values per vehicle out of the database, and then use the API to create markers, as explained here
Is there a way to retrieve the polygon coordinates of buildings on Google Maps?
I could draw an overlay and grab polygon coordinates manually, then try to determine whether a latitude and longitude are in those coord boundaries. But is there a smarter way of doing this?
The goal is to programmatically understand where a set of lat/lng belong to a building.