Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from shapely.geometry import LineString, Polygon
- # Installation --> pip install shapely
- import logging
- def intersects_polygon_path(polygon_mat, path_mat):
- polygon_points = [tuple(p) for p in polygon_mat]
- path_points = [tuple(p) for p in path_mat]
- logging.debug(f"polygon_points: {polygon_points}")
- logging.debug(f"path_points: {path_points}")
- polygon = Polygon(polygon_points)
- result = False
- i = 0
- while (not result) and (i < len(path_points) - 1):
- segment = LineString([path_points[i], path_points[i + 1]])
- result = polygon.intersects(segment)
- logging.debug(f"iteracion: {i}, result: {result}.")
- i += 1
- logging.info(f"result: {result}.")
- return result
- # Define a rectangular polygon
- polygon_mat = [
- [50.097986, 14.410436],
- [50.093511, 14.41595],
- [50.087722, 14.409767],
- [50.084028, 14.4086],
- [50.088344, 14.387347],
- [50.094278, 14.388269],
- [50.097986, 14.410436]
- ]
- # Define a path (sequence of GPS points)
- path_mat = [
- [50.105262981329595, 14.267437167464884],
- [50.105262981329595, 14.267437167464884],
- [50.074607754755135, 14.474670112031129],
- [50.0760853, 14.4747344]
- ]
- logging.basicConfig(
- filename='salidaLog.log',
- level=logging.DEBUG,
- encoding='utf-8',
- format='[%(asctime)s] %(process)d-[%(threadName)s-%(thread)d] %(levelname)s %(module)s.%(funcName)s L:%(lineno)d: %(message)s'
- )
- print("Intersects?", intersects_polygon_path(polygon_mat, path_mat))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement