python - 查找轮廓内的网格点
问题描述
我想知道每个闭合轮廓中有多少个网格点。
假设一个网格。我有一个形成闭合(连接)轮廓的点列表。
我想知道分别在闭合轮廓中有多少个网格点?
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
import math
#calculate area
def area(vs):
a = 0
x0, y0 = vs[0]
for [x1, y1] in vs[1:]:
dx = (x1 - x0) * 119.19
dy = (y1 - y0) * 103.09
a += 0.5 * (y0 * dx - x0 * dy)
x0 = x1
y0 = y1
return a
# Read data
ds1 = xr.open_dataset('2015.nc')
lons = ds1.variables['lon'][:]
lats = ds1.variables['lat'][:]
times = ds1.variables['time'][:]
surf_els = ds1.variables['surf_el'][:]
lon = np.asarray(lons)
lat = np.asarray(lats)
time = np.asarray(times)
surf_el = np.asarray(surf_els)
ds1.close()
surf_el_mean = np.nanmean(surf_el[0])
surf_el[0] = (surf_el[0]) - surf_el_mean
#contour level -35/1000
cs = plt.contour(lon, lat, surf_el[0], [-35/1000],colors='r')
#extract path or contours level -35/1000
p = cs.collections[0].get_paths()[0]
v = p.vertices
x = v[:, 0]
y = v[:, 1]
vs = p.vertices
print(p)
plt.show()
#All of p are not closed.Closed contour important for me. but i don't know #how many points inside a closed contour? this problem is similar Pick's #theorem in math.
解决方案
推荐阅读
- wpf - 将依赖属性绑定到祖先视图模型的属性的正确方法是什么
- mysql - 如何在mysql中踢出具有一半相同约束键的元组
- reactjs - Material-ui FormControlLabel 值不反映更新状态时的变化
- angular - 以角度全局处理 HTTP 错误
- java - 错误:无法找到或加载主类
- android - 静态变量会导致android中的内存泄漏吗?
- java - 如何在不知道文本坐标的情况下使用 PDFBox 周围的文本在 PDF 中创建颜色划分?
- google-chrome - 如何预授权 URL 以在 Electron(或 Chrome)中使用麦克风?
- mysql - 在表中插入多行的存储过程
- git - 创建新分支时运行任务