我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用shapely.geometry.LinearRing()。
def cut_ring(ring: LinearRing) -> List[LinearRing]: rings = [] new_ring = [] # noinspection PyPropertyAccess for point in ring.coords: try: index = new_ring.index(point) except ValueError: new_ring.append(point) continue if len(new_ring) > 2+index: rings.append(LinearRing(new_ring[index:]+[point])) new_ring = new_ring[:index+1] return rings
def get_rings(geometry): if isinstance(geometry, Polygon): return chain((geometry.exterior, ), geometry.interiors) try: geoms = geometry.geoms except AttributeError: pass else: return chain(*(get_rings(geom) for geom in geoms)) if isinstance(geometry, LinearRing): return (geometry, ) return ()
def __generate_visivility_graph(self): def extend_line(line): return np.append(line, [line[0], line[1]], axis=0) H = self.__H join_style = JOIN_STYLE.mitre is_ccw = LinearRing(self.borders_points).is_ccw map_po = LineString(extend_line(self.borders_points)).parallel_offset( H, 'left' if is_ccw else 'right', join_style=join_style ) if map_po.geom_type == 'MultiLineString': geoms = list(map_po.geoms) map_po = list(chain(geoms[0].coords, geoms[1].coords)) self.__support_points = np.array(map_po) self.__holes = [] for item in self.items_border_points: if item.size > 0: is_ccw = LinearRing(item).is_ccw item_po = LineString(extend_line(item)).parallel_offset( H, 'right' if is_ccw else 'left', join_style=join_style ) if item_po.geom_type == 'MultiLineString': geoms = list(item_po.geoms) item_po = list(chain(geoms[0].coords, geoms[1].coords)) support_item_points = np.array(item_po) self.__holes.append(support_item_points) all_points = self.__support_points for hole in self.__holes: all_points = np.append(all_points, hole, axis=0) holes_p = [Polygon(h) for h in self.__holes] border_p = Polygon(self.__support_points) points_len = len(all_points) visibility_graph = np.zeros(shape=(points_len, points_len)) for i in range(all_points.shape[0]): for j in range(all_points.shape[0]): line = np.array((all_points[i], all_points[j])) if self.is_valid(LineString(line), border_p, holes_p): visibility_graph[i, j] = True return all_points, visibility_graph