我有一个形状文件,如图所示。
如何使用 python 实现此目的?
我到目前为止所尝试的如下所示。
import geopandas as gpd ; import shapefile ; import numpy as np ; import pandas as pd
from shapely.geometry import Polygon, Point
import matplotlib.pyplot as plt ;
lat_1=6 ; lat_2=20 ; lon_1=70 ; lon_2=90
A=gpd.read_file(shp_file)
points=[]
for shape_rec in A.shapeRecords():
#print(shape_rec)
pts = pd.DataFrame(np.array(shape_rec.shape.points))
pts.columns=['lon','lat']
points.append(pts)
points_1=pd.concat(points)
points_2=points_1[(points_1.lon >=lon_1)&(points_1.lon <=lon_2) & (points_1.lat >=lat_1)&(points_1.lat <=lat_2)]
gdf = gpd.GeoDataFrame( points_2, geometry=gpd.points_from_xy(points_2.lon , points_2.lat ), crs='EPSG:4326')
gdf.drop(['lat', 'lon'], axis=1, inplace=True) # optional
gdf.to_file(main+'shp_files/test.shp')
这是将输出作为多点线 非常感谢任何帮助
Shapely 有一个用线分割多边形的函数:shapely.ops.split(geom, splitter).
因为 geopandas 几何实际上存储为引擎盖下的形状对象,你可以很容易地对它们使用形状操作。 在 geopandas 用户指南 中可以找到更多信息和示例。