def intersection(request): if request.method == 'POST': intersecting_routes = [] # get user_line coordinates from client post user_line = [] try: json_data = json.loads(request.body) for coordinate in json_data: user_line.append([coordinate["lat"], coordinate["lng"]]) except Exception as e: return Response(status=status.HTTP_400_BAD_REQUEST) # get lines from saved routes routes = Route.objects.all() for route in routes: route_line = list( Location.objects.filter( route_id=route.id).order_by("timestamp").values_list( 'latitude', 'longitude')) path1 = mpPath(user_line) path2 = mpPath(route_line) if path1.intersects_path(path2): intersecting_routes.append(route.id) return Response({'routes': intersecting_routes})
def polyContains(polyBounds, points, plot=False): """find the points that are contained in the bounding polygon""" boxcodes = [mpPath.MOVETO] polyBounds = np.append(polyBounds, polyBounds[0]).reshape((-1, 2)) for k in range(len(polyBounds) - 1): boxcodes.append(mpPath.LINETO) boxcodes[-1] = mpPath.CLOSEPOLY bbPoly = mpPath(polyBounds, boxcodes) if plot: # debugging patch import matplotlib as mpl fig = myfig('debug patch') ax = fig.add_subplot(111) patch = mpl.patches.PathPatch(bbPoly, facecolor='orange', lw=2, alpha=0.5) ax.add_patch(patch) fpa = np.asarray(points) scatter(fpa[:, 0], fpa[:, 1]) myshow() withinbox = bbPoly.contains_points(points) return withinbox
def which_zone(xcoord, ycoord, zone): point = (xcoord, ycoord) in_zone_1 = mpPath(zone[0]).contains_point(point) in_zone_2 = mpPath(zone[1]).contains_point(point) in_zone_3 = mpPath(zone[2]).contains_point(point) in_zone_4 = mpPath(zone[3]).contains_point(point) #print in_zone_1, in_zone_2, in_zone_3, in_zone_4 if in_zone_1 == True: return "Zone 1" elif in_zone_2 == True: return "Zone 2" elif in_zone_3 == True: return "Zone 3" elif in_zone_4 == True: return "Zone 4"
def point_in_poly(vertices, x, y): path = mpPath(vertices) point = (x, y) return path.contains_point(point)
def point_in_poly(vertices,x,y): from matplotlib.path import Path as mpPath path = mpPath(vertices) point = (x,y) return path.contains_point(point)
def point_in_poly(vertices, x, y): path =mpPath(vertices) point = (x,y) return path.contains_point(point)