【发布时间】:2018-12-12 20:28:51
【问题描述】:
我正在尝试在 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 是穿过水平线的边数? (经过一些预处理。)
标签: python pandas geometry shapely geopandas