Geoseries上的Geopandas接触方法无法正常工作 [英] Geopandas touches method on geoseries does not work as I expect

查看:100
本文介绍了Geoseries上的Geopandas接触方法无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一crs中有两个地理系列.我想从geoseries_1中提取所有与geoseries_2的多边形接触的多边形.在文档中说地理序列是按元素进行测试的,所以我这样做:

geoseries_1.touches(geoseries_2)

但输出是

0      False
1      False
2      False
      ...
569    False
597    False
598    False
Length: 599, dtype: bool

但是我知道geoseries_1的某些多边形实际上正在接触geoseries_2中的某些多边形,如果我这样做,例如:

geoseries_1.touches(geoseries_2.geometry.iloc [0])),结果是:

0      True
1      True
2      False
      ...
569    False
597    True
598    False
Length: 599, dtype: bool

这是预期的输出吗?我会误解文档吗? 预先感谢!

解决方案

是的,这是预期的(但有时令人惊讶)行为:如果将另一个GeoSeries作为参数传递,则"touches"操作是按元素进行的(因此地理系列_1的第一个,地理系列_2的第一个,地理系列_1的第二个,地理系列_2的第二个,...).

因此,它不具有针对geoseries_1中的所有元素,请检查geoseries_1中的每个元素"的行为.那更像是空间连接.但是,不幸的是,GeoPandas不支持sjoin函数

那么解决方案是什么?这取决于所需的输出:是否要重复具有多个匹配项的行?还是只想拥有接触多边形的列表?


顺便说一句:我最近在github上打开了一个问题,建议禁用此自动对齐功能(因此,如果geoseries_1和geoseries_2不具有相同的长度和索引,则至少上面的代码会出现错误): https://github.com/geopandas/geopandas/issues/750

I have two geoseries in the same crs. I want to extract from the geoseries_1 all the polygons touching any polygon of geoseries_2. In the documentation it says that geoseries are tested element-wise, so I do:

geoseries_1.touches(geoseries_2)

but the output is

0      False
1      False
2      False
      ...
569    False
597    False
598    False
Length: 599, dtype: bool

but I know some of the polygons of geoseries_1 are actually touching some polygons in geoseries_2 and if I do for example:

geoseries_1.touches(geoseries_2.geometry.iloc[0])), the result is:

0      True
1      True
2      False
      ...
569    False
597    True
598    False
Length: 599, dtype: bool

Is this the expected output? Am I misinterpreting the documentation? Thanks in advance!

解决方案

Yes, this is the expected (but sometimes surprising) behaviour: if you pass another GeoSeries as argument, the 'touches' operation is done element-wise (so first of geoseries_1 with first of geoseries_2, second of geoseries_1 with second of geoseries_2, ...).

So it does not the "for all elements in geoseries_1, check each element of geoseries_1" behaviour. That is more like a spatial join. But, unfortunately, GeoPandas does not support the 'touches' spatial relationships in its sjoin function

So what is the solution? This depends on the desired output: do you want to repeat the rows that have multiple matches? Or do you just want to have the list of touching polygons?


BTW: I recently opened an issue on github to propose disabling this automatic alignment (so at least the above would given an error if geoseries_1 and geoseries_2 don't have the same length and index): https://github.com/geopandas/geopandas/issues/750

这篇关于Geoseries上的Geopandas接触方法无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆