多边形中的点,简单的4顶点多边形,没有外部库
我正在使用matplot lib在地图上绘制事物,并具有一个坐标图集,我有4个顶点集,这些点定义了地图上的边界,我想清除地图集中所有不包含的条目落在那个界限内.
I'm plotting things on a map with matplot lib and have an atlas of coordinates, I have a 4 vertex set of points that define a boundary on the map, I want to clear all entries in my atlas that don't fall within that boundary.
我一直在尝试使用.contains_points尝试使用matplotlib路径,但是该路径似乎无法正常工作,并且输出的绘制地图已删除了一些点,但并非在边界之外的所有点.
I've been trying the matplotlib path with .contains_points however that doesn't appear to working and the output plotted map has some points removed but not all that is outside the boundry.
我的地图集数据包含特定地理区域的动植物目击数据,
My atlas data contains sightings of flora/fauna for a particular geographical area,
border= [(-35.2825, 149.108), (-35.2873, 149.118), (-35.2714, 149.118), (-35.2758, 149.127)]
border_path= Path(border, codes=None, closed=True)
# Atlas data is defined in another part. contains [name, lat, lon]
for n, i in enumerate(atlas_data):
lat_lon = (i[1], i[2])
if not border_path.contains_points([lat_lon], transform=None):
del atlas_data[n]
未经测试,但是如果您随后使用 inboundspoints 而不是 atlas_data 来绘制点,这应该可以工作 - 请注意 contains_points if 语句没有 not代码>:
Untested, but this should work if you then use inboundspoints to plot points instead of atlas_data - note the contains_points if statement doesn’t have not
any more:
border= [(-35.2825, 149.108), (-35.2873, 149.118), (-35.2714, 149.118), (-35.2758, 149.127)]
border_path= Path(border, codes=None, closed=True)
inboundspoints = []
# Atlas data is defined in another part. contains [name, lat, lon]
for n, i in enumerate(atlas_data):
lat_lon = (i[1], i[2])
if border_path.contains_points([lat_lon], transform=None):
inboundspoints.append( atlas_data[n] )