资源简介
使用python实现了可视域计算的几种经典算法,包括LOS算法,Xdraw算法,参考面算法等
代码片段和文件信息
#-*-coding:utf8-*-
“““
written: 2014.04.02; by guoning; vision: 0.1
function: 比较三种算法的效率
“““
import gdal
import time
import math
import numpy
#边界扫描算法(基于bresenham近似)
def Los_sweep(arearadius):
blockvisib = [[0 for i in range(radius+1)]for i in range(radius+1)] #可视性存储矩阵(r+1)*(r+1)
blockvisib[0][0] = 1
#area = band.ReadAsArray(int(x0)int(y0)int(radius+1)int(radius+1))
area = numpy.transpose(area) #转置,使x,y符合使用习惯
viewheight = area[0][0]
mslope = -65535
x = 0
y = 0
dx = radius
for i in range(radius+1):
dy = i
dp = 2*dy-dx
while(x < dx):
x+=1
if(dp < 0):
dp+=2*dy
else:
y+=1
dp+=2*(dy-dx)
tslope = (area[x][y] - viewheight)/math.sqrt(x*x+y*y)
if(tslope > mslope):
blockvisib[y][x] = 1
mslope = tslope
#将两矩阵转置进行相同的运算
area = numpy.transpose(area)
blockvisib = numpy.transpose(blockvisib)
mslope = -65535
x = 0
y = 0
dx = radius
for i in range(radius+1):
dy = i
dp = 2*dy-dx
while(x < dx):
x+=1
if(dp < 0):
dp+=2*dy
else:
y+=1
dp+=2*(dy-dx)
tslope = (area[x][y] - viewheight)/math.sqrt(x*x+y*y)
if(tslope > mslope):
blockvisib[y][x] = 1
mslope = tslope
#得到完整区块可视性
blockvisib = numpy.transpose(blockvisib)
return blockvisib
#xdraw算法
def XDraw(arearadius):
blockvisib = [[0 for i in range(radius+1)]for i in range(radius+1)] #可视性存储矩阵(r+1)*(r+1)
blockvisib[0][0] = 1
#area = band.ReadAsArray(int(x0)int(y0)int(radius+1)int(radius+1))
area = numpy.transpose(area) #转置,使x,y符合使用习惯
lowestvisibalh = [[0 for i in range(radius+1)]for i in range(radius+1)] #初始化最低可视海拔存储矩阵为原海拔矩阵
lowestvisibalh[0][0] = area[0][0]
viewheight = area[0][0] #视点高度
#判断x轴方向可视性并存入可视矩阵,更新最低可视海拔矩阵
heightlist1 = [area[i+1][0] for i in range(radius)]
mslope = -65535
for i in range(radius):
tslope = float(heightlist1[i] - viewheight)/(i+1)
if(tslope > mslope):
blockvisib[i+1][0] = 1
mslope = tslope
lowestvisibalh[i+1][0] = area[i+1][0]
else:
lowestvisibalh[i+1][0] = lowestvisibalh[i][0]+mslope
#判断y轴方向可视性并存入可视矩阵,更新最低可视海拔矩阵
heightlist2 = [area[0][i+1] for i in range(radius)]
mslope = -65535
for i in range(radius):
tslope = float(heightlist2[i] - viewheight)/(i+1)
if(tslope > mslope):
blockvisib[0][i+1] = 1
mslope = tslope
lowestvisibalh[0][i+1] = area[0][i+1]
else:
lowestvisibalh[0][i+1] = lowestvisibalh[0][i]+mslope
#判断对角线方向可视性并存入可视矩阵,更新最低可视海拔矩阵
heightlist3 = [area[i+1][i+1] for i in range(radius)]
sqrt2 = math.sqrt(2)
mslope = -65535
for i in range(radius):
tslope = float(heightlist3[i] - viewheight
- 上一篇:Python爬取东方财富公司公告
- 下一篇:python3.4爬取网络图片
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论