我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用shapely.geometry.MultiLineString()。
def test_point_projects_to_edge(self): # p = (114.83299055, 26.8892277) p = (121.428387, 31.027371) a = time.time() edges, segments = self.sg.point_projects_to_edges(p, 0.01) print(time.time() - a) if self.show_plots: plt.figure() s2g.plot_lines(MultiLineString(segments), color='orange') # original roads for i in range(0, len(edges)): s, e = edges[i] sxy = self.sg.node_xy[s] exy = self.sg.node_xy[e] plt.plot([sxy[0], exy[0]], [sxy[1], exy[1]], color='green') # graph edges plt.plot(p[0], p[1], color='red', markersize=12, marker='o') # bridges plt.show()
def to_Trajectory(self, inter): if (inter.has_z == False): raise Exception('O objeto precisa ser uma geometria com um atributo z') if isinstance(inter, MultiLineString) or isinstance(inter, MultiPolygon): array_traj = [] for multi in inter: array_traj.append(self.__set_data__(multi)) return array_traj return self.__set_data__(inter)
def clean_edges(Rlinelist,elect0,elect1): plot = False Electrodes = shapely_geom.MultiLineString([elect0,elect1]) Rline_cleaned = [[],[]] for polarity in range(len(Rlinelist)): #Rline = shapely_geom.collection.GeometryCollection(Rlinelist[polarity]) for n in range(len(Rlinelist[polarity])): Rline = Rlinelist[polarity][n] Rsegments = Rline.difference(Electrodes) check_linear_ring = Rsegments.geoms[0].coords[0]==Rsegments.geoms[-1].coords[-1] check_no_intersection = not shapely_geom.Point(Rsegments.geoms[0].coords[0]).buffer(1e-9).intersects(Electrodes) if check_linear_ring and check_no_intersection: #there seems to be a bug in the linear ring intersection of shapely Rsegments_geoms_0 = shapely_ops.linemerge([Rsegments.geoms[0],Rsegments.geoms[-1]]) Rsegments_temp = [Rsegments_geoms_0] for i in range(len(Rsegments.geoms)-2): Rsegments_temp.append(Rsegments[i+1]) Rsegments = shapely_geom.MultiLineString(Rsegments_temp) for segment in Rsegments.geoms: if plot: ax = plt.subplot(111) segmentarray = numpy.array(segment.coords) elect0array = numpy.array(elect0.coords) elect1array = numpy.array(elect1.coords) ax.plot(segmentarray[:,0].tolist(), segmentarray[:,1].tolist(), color='k', linewidth=3) ax.plot(elect0array[:,0].tolist(), elect0array[:,1].tolist(), color='b', linewidth=3) ax.plot(elect1array[:,0].tolist(), elect1array[:,1].tolist(), color='r', linewidth=3) ax.axis([min(segmentarray[:,0]),max(segmentarray[:,0]),min(segmentarray[:,1]), max(segmentarray[:,1])]) ax.set_aspect(1) ax.grid(True) plt.show() if segment.buffer(1e-9).intersects(elect0) and segment.buffer(1e-9).intersects(elect1): #there seems to be a numerical issue with small segments Rline_cleaned[polarity].append(segment) return Rline_cleaned
def test_empty_multilinestring(self): self.assertTrue(sgeom.MultiLineString([]).is_empty)
def setUp(self): self.point = Point(1, 1) self.line1 = LineString(([0, 0], [2, 0])) self.line2 = LineString(([3, 0], [3, 6])) self.multiline = MultiLineString([ list(self.line1.coords), list(self.line2.coords) ])
def test_array_interface(self): m = geometry.MultiLineString([((0, 0), (1, 1)), ((2, 2), (3, 3))]) ai = m.geoms[0].__array_interface__ self.failUnlessEqual(ai['shape'], (2, 2))
def test_index_multigeom_misc(self): g = geometry.MultiLineString() # empty self.assertRaises(IndexError, lambda: g[0]) self.assertRaises(TypeError, lambda: g[0.0])
def assert_multilinestring(geometry: Union[LineString, MultiLineString, GeometryCollection]) -> List[LineString]: """ given a LineString or MultiLineString, return a list of LineStrings :param geometry: a LineString or a MultiLineString :return: a list of LineStrings """ if geometry.is_empty: return [] if isinstance(geometry, LineString): return [geometry] return [geom for geom in geometry.geoms if isinstance(geom, LineString)]
def create(cls, geom, face_centers): """ Create from existing facets and just select the ones that lie inside this polygon. """ if isinstance(geom, (LineString, MultiLineString)): return HybridGeometry(geom, set()) faces = tuple( set(np.argwhere(shapely_to_mpl(subgeom).contains_points(face_centers)).flatten()) for subgeom in assert_multipolygon(geom) ) return HybridGeometry(geom, tuple(f for f in faces if f))
def create_full(cls, geom, vertices_offset, faces_offset): """ Create by triangulating a polygon and adding the resulting facets to the total list. """ if isinstance(geom, (LineString, MultiLineString)): return HybridGeometry(geom, set()), np.empty((0, 2), dtype=np.int32), np.empty((0, 3), dtype=np.uint32) vertices = deque() faces = deque() faces_i = deque() for subgeom in assert_multipolygon(geom): new_vertices, new_faces = triangulate_polygon(subgeom) new_faces += vertices_offset vertices.append(new_vertices) faces.append(new_faces) faces_i.append(set(range(faces_offset, faces_offset+new_faces.shape[0]))) vertices_offset += new_vertices.shape[0] faces_offset += new_faces.shape[0] if not vertices: return HybridGeometry(geom, set()), np.empty((0, 2), dtype=np.int32), np.empty((0, 3), dtype=np.uint32) vertices = np.vstack(vertices) faces = np.vstack(faces) return HybridGeometry(geom, tuple(faces_i)), vertices, faces
def data_manipulation_sh (network): from shapely.geometry import Point, LineString, MultiLineString from geoalchemy2.shape import from_shape, to_shape #add connection from Luebeck to Siems new_bus = str(int(network.buses.index.max())+1) new_trafo = str(int(network.transformers.index.max())+1) new_line = str(int(network.lines.index.max())+1) network.add("Bus", new_bus,carrier='AC', v_nom=220, x=10.760835, y=53.909745) network.add("Transformer", new_trafo, bus0="25536", bus1=new_bus, x=1.29960, tap_ratio=1, s_nom=1600) network.add("Line",new_line, bus0="26387",bus1=new_bus, x=0.0001, s_nom=1600) network.lines.loc[new_line,'cables']=3.0 #bus geom point_bus1 = Point(10.760835,53.909745) network.buses.set_value(new_bus, 'geom', from_shape(point_bus1, 4326)) #line geom/topo network.lines.set_value(new_line, 'geom', from_shape(MultiLineString([LineString([to_shape(network.buses.geom['26387']),point_bus1])]),4326)) network.lines.set_value(new_line, 'topo', from_shape(LineString([to_shape(network.buses.geom['26387']),point_bus1]),4326)) #trafo geom/topo network.transformers.set_value(new_trafo, 'geom', from_shape(MultiLineString([LineString([to_shape(network.buses.geom['25536']),point_bus1])]),4326)) network.transformers.set_value(new_trafo, 'topo', from_shape(LineString([to_shape(network.buses.geom['25536']),point_bus1]),4326)) return