簡體   English   中英

使用 Python GeoPandas 進行多邊形點分析

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM