将 Geopandas Dissolve 与 ArcGIS Dissolve 相匹配在多段线上

问题描述 投票:0回答:2

我正在尝试使用 geopandas 在一组河流流线上复制 ArcGIS

Dissolve
的输出。本质上,df/stream_0 层是使用
pysheds
从 DEM 中提取的流网络。该输出有一些随机重叠的区域,我试图将其删除。通过 ArcGIS Pro 运行 Dissolve 可以很好地实现这一点,但我希望不必处理 ArcGIS/
ArcPy
来解决此问题。

Stream Network

ArcGIS Dissolve Setting

#streams_0.geojson = df.shp = streams_0.shp from Dissolve Setting image
#~~~~~~~~~~~~~~~~~~~~
import geopandas as gpd
df = gpd.read_file('streams_0.geojson')
df.head()
Out[3]: 
                                            geometry
0  LINESTRING (400017.781 3000019.250, 400017.781...
1  LINESTRING (400027.781 3000039.250, 400027.781...
2  LINESTRING (400027.781 3000039.250, 400037.781...
3  LINESTRING (400027.781 3000029.250, 400037.781...
4  LINESTRING (400047.781 3000079.250, 400047.781... 

我尝试使用 gpd.dissolve() 使用填充列,但没有成功。

df['dissolvefield'] = 1;
df2 = df.dissolve(by='dissolvefield')
df3 = gpd.geoseries.GeoSeries([geom for geom in df2.geometry.iloc[0].geoms])

同样尝试在 shapely 中使用 unary_union 但没有成功。

import fiona
shape1 = fiona.open("df.shp")
first = shape1.next()

from shapely.geometry import shape
shp_geom = shape(first['geometry'])


from shapely.ops import unary_union
shape2 = unary_union(shp_geom)

似乎是一个简单的解决方案,想知道为什么我遇到了这么多问题。我的 GeoDataFrame 仅包含线几何图形,因此不一定有其他属性可以聚合。我本质上只是试图保持线条的几何形状不变,但删除可能存在的任何重叠特征。我不想分割线,也不想将它们聚合成多部分特征。

python gis geojson geopandas shapely
2个回答
0
投票

我使用unary_union,但不需要将其视为形状特征。

读取文件并将其放入 GPD 中(您可以直接从 *.shp 文件中执行此操作):

df = gpd.read_file('streams_0.geojson')

尝试绘制它以查看输出是否正确

df.plot()

而不是像这样使用 unary_union ,然后再次绘制:

shape2 = df.unary_union 
shape2

最后一步(如果有必要),是再次设置为geopandas:

# transform Geometry Collection to shapely multilinestirng
segments = [feature for feature in shape2]

# set back as geopandas
gdf = gpd.GeoDataFrame(list(range(len(segments))),  geometry=segments, 
crs=crs)
gdf .columns = ['index', 'geometry']

0
投票

se volessi unire solamente le geometrie con comune, ovvero le polilinee dove vertice Finale è uguale al vertice iniziale, che corrisponderebbe al Dissolved in arcmap con opzione di 'unslitlines' come posso fare?

© www.soinside.com 2019 - 2024. All rights reserved.