簡體   English   中英

找到接觸幾何體相互接觸的點

[英]Find point where touching geometries touch each other

我有一個帶有 LineStrings 的 GeoDataFrame 並且想要獲取幾何圖形相互接觸的所有坐標。 到目前為止,我可以找到相互接觸的人,但是如何獲得接觸點的坐標? 它應該盡可能快,因為我有很多數據。

data = gpd.read_file("data.geojson")
heads, tails = data.sindex.query_bulk(data.geometry, predicate="touches")
touching_dataframe = data.iloc[heads]

使用 geopandas 依賴的 shapely 庫提供的交集方法。

# create a list to store the coordinates
coordinates = []

# iterate over the indexes of the touching geometries
for i in range(len(heads)):
    # get the geometry of the current touching pair
    head_geom = data.iloc[heads[i]]['geometry']
    tail_geom = data.iloc[tails[i]]['geometry']
    
    # get the intersection of the two geometries
    intersection = head_geom.intersection(tail_geom)
    
    # add the coordinates of the intersection to the list
    coordinates.append(intersection.coords[:])

# create a new dataframe with the coordinates
touching_coordinates = pd.DataFrame(coordinates, columns=["longitude", "latitude"])

您將擁有一個新的 DataFrame,其中包含幾何圖形相互接觸的所有坐標。 請注意,如果您有大量數據,此過程可能會很慢,因此您應該考慮使用多處理技術或 Dask 來並行執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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