地质空间选择

发布于 2025-02-01 10:45:42 字数 2886 浏览 2 评论 0原文

我有一个循环,根据我的情况,根据字段值选择了一组点。然后,我通过用X米来缓冲这些点,将其溶解并将其转换为单个部分来构建多边形。输出将是1多边形或多个多边形,具体取决于点簇的相距多远。这样做的目的是选择不同的点。当我循环穿过缓冲区以从属于多边形内的子集中选择点;

ValueError: cannot join with no overlapping index names

当我在此阶段打印和检查每个数据框时,它们显示为带有几何列的GeodataFrame。当我将缓冲区导出到功能赛上并在QGIS中查看时,我可以看到多边形表示点的缓冲区,并且多边形内有点需要选择。 不知道我在做什么错的

for TrackID in TrackIDList:
n=n+1 ## Loop counter
currentdf = gpd.GeoDataFrame(geo_df[geo_df['TrackID'] == (TrackID)]) ## From all TrackPoints select only those where TrackID = TrackID
bufferdf = gpd.GeoDataFrame(geo_df[geo_df['TrackID'] == (TrackID)]) ## Set the buffer Dataframe to the point dataframe for buffering
bufferdf['geometry'] = currentdf.geometry.buffer(m) ## Buffer in metres (m = 55560)
bufferdf = bufferdf.dissolve('TrackID') ## Dissolve the buffers by TrackID
bufferdf = bufferdf.explode() ## Multipart to Singlepart
bufferdf['gid'] = range(1, len(bufferdf) +1) ## Assign Unique ID to the buffer features
bufferList = bufferdf.gid.unique().tolist() ## Create a list of unique gid to iterate over
for gid in bufferList: ## Iterator for the buffers
    cbuffer = bufferdf[bufferdf['gid'] == (gid)] ## Isolates the buffer with the curent gid numebr
    trakpoints = currentdf[currentdf.geometry.within(cbuffer)] ## Collect the points in the buffer
    print(trakpoints) ## Print the track points captured in the buffer

追溯

Traceback (most recent call last):
  File "C:\Users...\BuildTracks.py", line 43, in <module>
    trakpoints = currentdf[currentdf.geometry.within(cbuffer)]
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\geopandas\base.py", line 458, in within
    return _binary_op("within", self, other)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\geopandas\base.py", line 67, in _binary_op
    data, index = _delegate_binary_method(op, this, other, *args, **kwargs)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\geopandas\base.py", line 40, in _delegate_binary_method
    this, other = this.align(other.geometry)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\series.py", line 4274, in align
    return super().align(
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\generic.py", line 8559, in align
    return self._align_series(
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\generic.py", line 8662, in _align_series
    join_index, lidx, ridx = self.index.join(
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3446, in join
    return self._join_multi(other, how=how, return_indexers=return_indexers)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3548, in _join_multi
    raise ValueError("cannot join with no overlapping index names")
ValueError: cannot join with no overlapping index names

Process finished with exit code 1

I have a loop that selects a group of points based on a field value, in my case a trackID. I then have polygons built by buffering the those points by x meters, dissolving it, and converting it into single parts. The output will either be 1 polygon or multiple polygons depending on how far apart the point clusters are. The purpose of this is to select distinct groups of points. When I loop through the buffers to select the points from the subset that fall within the polygon I get;

ValueError: cannot join with no overlapping index names

When I print and inspect each dataframe at this stage they show as being geodataframes with a geometry column. When I export the buffers to a featureclass and view it in QGIS I can see the polygons represent buffers of the points and that there are points within the polygons to select.
Not sure what I am doing wrong

for TrackID in TrackIDList:
n=n+1 ## Loop counter
currentdf = gpd.GeoDataFrame(geo_df[geo_df['TrackID'] == (TrackID)]) ## From all TrackPoints select only those where TrackID = TrackID
bufferdf = gpd.GeoDataFrame(geo_df[geo_df['TrackID'] == (TrackID)]) ## Set the buffer Dataframe to the point dataframe for buffering
bufferdf['geometry'] = currentdf.geometry.buffer(m) ## Buffer in metres (m = 55560)
bufferdf = bufferdf.dissolve('TrackID') ## Dissolve the buffers by TrackID
bufferdf = bufferdf.explode() ## Multipart to Singlepart
bufferdf['gid'] = range(1, len(bufferdf) +1) ## Assign Unique ID to the buffer features
bufferList = bufferdf.gid.unique().tolist() ## Create a list of unique gid to iterate over
for gid in bufferList: ## Iterator for the buffers
    cbuffer = bufferdf[bufferdf['gid'] == (gid)] ## Isolates the buffer with the curent gid numebr
    trakpoints = currentdf[currentdf.geometry.within(cbuffer)] ## Collect the points in the buffer
    print(trakpoints) ## Print the track points captured in the buffer

Traceback

Traceback (most recent call last):
  File "C:\Users...\BuildTracks.py", line 43, in <module>
    trakpoints = currentdf[currentdf.geometry.within(cbuffer)]
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\geopandas\base.py", line 458, in within
    return _binary_op("within", self, other)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\geopandas\base.py", line 67, in _binary_op
    data, index = _delegate_binary_method(op, this, other, *args, **kwargs)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\geopandas\base.py", line 40, in _delegate_binary_method
    this, other = this.align(other.geometry)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\series.py", line 4274, in align
    return super().align(
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\generic.py", line 8559, in align
    return self._align_series(
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\generic.py", line 8662, in _align_series
    join_index, lidx, ridx = self.index.join(
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3446, in join
    return self._join_multi(other, how=how, return_indexers=return_indexers)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3548, in _join_multi
    raise ValueError("cannot join with no overlapping index names")
ValueError: cannot join with no overlapping index names

Process finished with exit code 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2025-02-08 10:45:42

此错误是由于指数。您需要首先重置索引。

尝试以下操作:

trakpoints = currentdf[currentdf['geometry'].reset_index().within(cbuffer.reset_index())]

This error is because of the indices. You need to reset indices first.

Try this:

trakpoints = currentdf[currentdf['geometry'].reset_index().within(cbuffer.reset_index())]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文