我想在shapefile的多邊形內找到一個點。如何在多邊形內找到點?
我需要寫一個循環,可以遍歷的多邊形,並返回其中點位於多邊形的指數。
我怎麼會寫一個循環來找出哪些多邊形點是?
這裏是我迄今寫的:
import pandas as pd
import pylab as pl
import os
import zipfile
import geopandas as gp
import shapely
%pylab inline
# Read in the shapefile
ct_shape = gp.read_file(path)
# Segmented the file so it only contains Brooklyn data & set projection
ct_latlon = ct_shape[ct_shape.BoroName == 'Brooklyn']
ct_latlon = ct_latlon.to_crs({'init': 'epsg:4326'})
ct_latlon.head()
# Dataframe image
[Head of the dataframe image][1]: https://i.stack.imgur.com/xAl6m.png
# Created a point that I need to look for within the shapefile
CUSP = shapely.geometry.Point(40.693217, -73.986403)
輸出可以是這樣的:「3001100」(在正確的多邊形的BCTCB2010)
問題是什麼?我在你的文章中沒有看到問題,也沒有描述你正在掙扎的內容。 –
@OliverW。我需要編寫一個可以找到多邊形內點的索引的循環。 –
假設總共有N條邊。你可以使用一個解決方案,依次嘗試每個多邊形,總工作量爲O(N),或者你想要更高效,比如O(log(N)+ K),其中K是橫過水平線的邊的數量? (經過一些預處理。) –