我对确定如何使现有多边形集合中列出的集合点感到困惑
我已经尝试过,但是只尝试了一个多边形,对于许多我仍感到困惑的多边形,有人想帮忙吗?
from shapely.geometry import Point,Polygon
import shapely.wkt
import pandas as pd
if __name__ == '__main__':
list_of_samples = [
{
'sample_id' : '1', 'lat' : 106.510234,'long' : -5.800502,'rsrp' : '5', 'rsrq' : '6'
},{
'sample_id' : '2', 'lat' : 106.511421,'long' : -5.802832,'rsrp' : '6', 'rsrq' : '7'
},{
'sample_id' : '3', 'lat' : 106.511045,'long' : -5.805545,'rsrp' : '6', 'rsrq' : '7'
},{
'sample_id' : '4', 'lat' : 106.510345,'long' : -5.803045,'rsrp' : '6', 'rsrq' : '7'
}
]
results = []
for index in range(len(list_of_samples)):
# print(list_of_samples[index])
point = Point(list_of_samples[index]['long'], list_of_samples[index]['lat'])
# print(point)
grid = shapely.wkt.loads('POLYGON ((106.511421 -5.802852, 106.511421 -5.80251, 106.511765 -5.80251, 106.511765 -5.802852, 106.511421 -5.802852))')
temp = grid.contains(point)
if temp == True:
results.append(list_of_samples[index])
print(results)
else:
print(results)