def remove_short_lines(line): if line.type == 'MultiLineString': passing_lines = [] for i, linestring in enumerate(line): other_lines = MultiLineString( [x for j, x in enumerate(line) if j != i]) p0 = Point(linestring.coords[0]) p1 = Point(linestring.coords[-1]) is_deadend = False if p0.disjoint(other_lines): is_deadend = True if p1.disjoint(other_lines): is_deadend = True if not is_deadend or linestring.length > 5: passing_lines.append(linestring) return MultiLineString(passing_lines) if line.type == 'LineString': return line
def test_binary_predicates(self): point = Point(0.0, 0.0) self.assertTrue(point.disjoint(Point(-1.0, -1.0))) self.assertFalse(point.touches(Point(-1.0, -1.0))) self.assertFalse(point.crosses(Point(-1.0, -1.0))) self.assertFalse(point.within(Point(-1.0, -1.0))) self.assertFalse(point.contains(Point(-1.0, -1.0))) self.assertFalse(point.equals(Point(-1.0, -1.0))) self.assertFalse(point.touches(Point(-1.0, -1.0))) self.assertTrue(point.equals(Point(0.0, 0.0)))
def is_timed_free(self, edge, t_node): if not self.is_obstacle_free(edge): return False t = 0 t_time = 3 * self.step / self.v for path in self.paths: t = 0 for i, p in enumerate(path): if i == len(path) - 1: break p1 = Point(p[0], p[1]) p2 = Point(path[i + 1][0], path[i + 1][1]) p4 = Point(edge[0][0], edge[0][1]) line = LineString([p, path[i + 1]]).buffer(self.width) dist = p1.distance(p2) edge_line = LineString(edge).buffer(self.width) if edge_line.intersects(line): inter_point = edge_line.intersection(line) # print(type(inter_point)) # print(inter_point) x = [] y = [] if isinstance(inter_point, (Point, LineString)): x, y = inter_point.coords.xy elif isinstance(inter_point, (MultiPoint)): x, y = [(p.x, p.y) for p in inter_point] else: x, y = inter_point.exterior.coords.xy # print(x, y) if not x and not y: continue for i in range(0, len(x)): p3 = Point(x[i], y[i]) time_edge_inter = round( t_node[1] - ((p4.distance(p3)) / self.v), 2) time_path_inter = round( (t + (p1.disjoint(p3)) / self.v), 2) time_diff = abs(time_edge_inter - time_path_inter) if time_diff < t_time: return False t += round(dist / self.v, 2) return True