![](/img/trans.png)
[英]Is my adaptation of point-in-polygon (jordan curve theorem) in python correct?
[英]Point-in-Polygon Analysis Using Python GeoPandas
有一个日期框架,其中包含:
0 1 POLYGON ((37.787073 55.74702199999999, 37.7843... 1 POINT (37.34519 55.73756)
1 1 POLYGON ((37.787073 55.74702199999999, 37.7843... 2 POINT (37.23459 56.23456)
2 1 POLYGON ((37.787073 55.74702199999999, 37.7843... 3 POINT (36.29575 55.23458)
3 2 POLYGON ((37.458311 55.803885, 37.464054 55.80... 1 POINT (37.34519 55.73756)
4 2 POLYGON ((37.458311 55.803885, 37.464054 55.80... 2 POINT (37.23459 56.23456)
5 2 POLYGON ((37.458311 55.803885, 37.464054 55.80... 3 POINT (36.29575 55.23458)
同时,geopandas 不允许使用几何类型定义 2 列。 点是几何数据类型,但多边形不是。
Int64Index: 6 entries, 0 to 5
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 place_id 6 non-null int64
1 polygon_zone 6 non-null object
2 user_id 6 non-null int64
3 geometry 6 non-null geometry
dtypes: geometry(1), int64(2), object(1)
我想检查这样的点的发生:
result['result'] = result['geometry'].within(Polygon(result['polygon_zone']))
但是,这种方法不起作用,告诉我如何解决此问题。 感谢帮助!
很难说你是如何得到带有 2 个几何列的 GDF 的,但你可能想要使用sjoin
,这将返回一个 GDF,然后你可以从中提取你需要的东西。
gpd.sjoin(PolyDF, PointDF)
如果您需要解构您拥有的单个 GDF...不确定必须出现哪些特定的列
PolygonDF = result[["place_id", "polygon_zone"]]
PolygonDF.columns = ["place_id", "geometry"]
PointDF = result[["user_id", "geometry"]]
如果你可以添加你是如何想出最初的 GeoDataFrame 的,它会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.