多边形中的点,简单的4顶点多边形,没有外部库 [英] point-in-polygon, simple 4 vertex polygon, no external libraries

查看:41
本文介绍了多边形中的点,简单的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] )

这篇关于多边形中的点,简单的4顶点多边形,没有外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆