资源简介
已知空间坐标和对应的属性,利用python的matplotlib绘制等值线图,可进行不规则的凹边界约束。是本文原创博客https://blog.csdn.net/csubai07/article/details/106482015源文件
代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : Drawscript.py
# @Author: 白冬鑫
# @Date : 2020/6/1
# @Desc : Drawscript.py 用途:
# @license : Copyright(C) 中南大学 and 致力科技
# @Contact : baidongxin07@csu.edu.cn; baidongxin07@gmail.com
import xlrd
import numpy as np
from scipy.interpolate import griddata
import alphashape
from matplotlib import pyplot as plt
plt.rcParams[‘font.sans-serif‘] = [‘Times New Roman‘]
plt.rcParams[‘axes.unicode_minus‘] = False
def isPointinPolygon(point rangelist): # [[00][11][01][00]] [10.8]
# 判断是否在外包矩形内,如果不在,直接返回false
lnglist = []
latlist = []
for i in range(len(rangelist) - 1):
lnglist.append(rangelist[i][0])
latlist.append(rangelist[i][1])
# print(lnglist latlist)
maxlng = max(lnglist)
minlng = min(lnglist)
maxlat = max(latlist)
minlat = min(latlist)
# print(maxlng minlng maxlat minlat)
if (point[0] > maxlng or point[0] < minlng or
point[1] > maxlat or point[1] < minlat):
return False
count = 0
point1 = rangelist[0]
for i in range(1 len(rangelist)):
point2 = rangelist[i]
# 点与多边形顶点重合
if (point[0] == point1[0] and point[1] == point1[1]) or (point[0] == point2[0] and point[1] == point2[1]):
# print(“在顶点上“)
return True
# 判断线段两端点是否在射线两侧 不在肯定不相交 射线(-∞,lat)(lnglat)
if (point1[1] < point[1] and point2[1] >= point[1]) or (point1[1] >= point[1] and point2[1] < point[1]):
# 求线段与射线交点 再和lat比较
point12lng = point2[0] - (point2[1] - point[1]) * (point2[0] - point1[0]) / (point2[1] - point1[1])
# print(point12lng)
# 点在多边形边上
if (point12lng == point[0]):
# print(“点在多边形边上“)
return True
if (point12lng < point[0]):
count += 1
point1 = point2
# print(count)
if count % 2 == 0:
return False
else:
return True
if __name__ == ‘__main__‘:
workbook = xlrd.open_workbook(“slope01-t.xlsx“)
nsheet = workbook.nsheets
# 求点集的边界
sheet = workbook.sheets()[0]
nrows = sheet.nrows
ncols = sheet.ncols
verctices = []
x = []
y = []
value = []
for ni in range(1 nrows):
xi = sheet.cell_value(ni 1)
yi = sheet.cell_value(ni 2)
vi = sheet.cell_value(ni 3)
x.append(xi)
y.append(yi)
value.append(vi)
verctices.append((xi yi))
# 计算边界
alpha = alphashape.optimizealpha(verctices)
alpha_shape = alphashape.alphashape(verctices alpha)
boundary = alpha_shape.boundary.coords[:]
# 将list转为numpy的array
x y z = np.array(x) np.array(y) np.array(value)
# 准备待插值位置
xi = np.linspace(x.min() x.max() 200)
yi = np.linspace(y.min() y.max() 200)
X Y = np.meshgrid(xi yi)
# 插值
Z = griddata((x y) z
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 25930 2020-06-01 21:34 slope01-t.xlsx
文件 10904 2020-06-01 22:18 slope01.png
文件 3625 2020-06-01 21:45 Drawsc
评论
共有 条评论