我想在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是横过水平线的边的数量? (经过一些预处理。) –