[英]How to check if a coordinate pair (lat,lon) exists in a coordinate grid?
[英]How to check if a lat/lon coordinate is within a polygon, using Python. (Taking into account the great circle.)
我有这个数据框,其中包含纬度/经度坐标:
Lat Lon
29.39291 -98.50925
29.39923 -98.51256
29.40147 -98.51123
29.38752 -98.52372
29.39291 -98.50925
29.39537 -98.50402
29.39343 -98.49707
29.39291 -98.50925
29.39556 -98.53148
这些是构成多边形的坐标:
Lat Lon
29.392945 -98.507696
29.406167 -98.509074
29.407234 -98.517039
29.391325 -98.517166
我想检查每个坐标(来自第一个数据帧)是否在多边形内,使用 Python,并考虑到大圆。
预期结果:
Lat Lon Within
29.39291 -98.50925 1
29.39923 -98.51256 1
29.40147 -98.51123 1
29.38752 -98.52372 0
29.39291 -98.50925 1
29.39537 -98.50402 0
29.39343 -98.49707 0
29.39291 -98.50925 1
29.39556 -98.53148 0
从这里检查一个点是否在 python 中的多边形内的最快方法是什么,假设您的多边形的 dataframe 是df_poly并且点是df_points :
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
polygon = Polygon([tuple(x) for x in df_poly[['Lat', 'Lon']].to_numpy()])
df_points['Within'] = df_points.apply(lambda x: polygon.contains(Point(x['Lat'], x['Lon'])), axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.