【教程】11-ParaView将航天雷达地形数据进行可视化处理
SRTM数据是通过在航天飞机上搭载的合成孔径雷达(SAR)技术获取的地表雷达图像。本文将介绍如何使用可视化软件ParaView来可视化SRTM数据。 1.获取SRTM数据 SRTM数据可以从Shuttle Radar Topography Mission的官方网站下载。下载并解压缩该文件后,将得到一个名为N32E020.hgt的HGT格式文件。2.从SRTM(HGT格式)转换为CSV文件 SRTM的HGT格式是一个由1201x1201个坐标点组成的二进制文件,采用大端序(Big endian)存储。可以使用以下简单的Python程序将HGT格式转换为CSV文件:import sysnrows = ncols = 1201xdim = ydim = 0.000833 args = sys.argvfilename = args[1]name, ext = os.path.splitext(filename)outname = name + '.csv' longitude = float(name[1:3])latitude = float(name[4:7]) print('longitude: ' + name[0] + name[1:3])print('latitude: ' + name[3] + name[4:7]) ulxmap = longitude + (xdim/2.0)ulymap = (latitude+1.0) - (ydim/2.0) a = array.array('h')f = open(filename, 'rb')a.fromfile(f, nrows*ncols)f.close() a.byteswap()alist = a.tolist() out = open(outname, 'w') count = 0for row in range(nrows): for col in range(ncols): x = ulxmap + xdim * col y = ulymap - ydim * row z = max(0.0, alist[count]) out.write(str(x) + ',' + str(y) + ',' + str(z/10000.0) + '\n') count += 1 if count%100000 == 0: print(str(int(100.0 * count/(nrows*ncols))) + '%')print('100%')print('node number: ' + str(count))out.close() 执行以下命令:python hgtToCSV.py N32E020.hgt 将N32E020.hgt转换为N32E020.csv。注意:转换后的坐标可能不准确,实际使用时请确保转换为正确的坐标。 3.从CSV文件转换为VTS文件 接下来,将CSV文件转换为ParaView可以读取的VTS格式(VTK的结构化网格数据格式)。这里也使用一个简单的Python脚本来完成转换。import os.pathimport sysfrom paraview.simple import * paraview.simple._DisableFirstRenderCameraReset() args = sys.argvfilename = args[1]workingDir = './'fileName = args[1] csvReader = CSVReader(FileName=[workingDir + fileName + '.csv']) csvReader.DetectNumericColumns = 1csvReader.UseStringDelimiter = 1csvReader.HaveHeaders = 0csvReader.FieldDelimiterCharacters = ','csvReader.MergeConsecutiveDelimiters = 0 tableToStructuredGrid = TableToStructuredGrid(Input=csvReader)tableToStructuredGrid.WholeExtent = [0, 1200, 0, 1200, 0, 0]tableToStructuredGrid.XColumn = 'Field 0'tableToStructuredGrid.YColumn = 'Field 1'tableToStructuredGrid.ZColumn = 'Field 2' calculator = Calculator(Input=tableToStructuredGrid)calculator.AttributeMode = 'Point Data'calculator.CoordinateResults = 0calculator.ResultNormals = 0calculator.ResultTCoords = 0calculator.ResultArrayName = 'z'calculator.Function = 'coordsZ'calculator.ReplaceInvalidResults = 1calculator.ReplacementValue = 0.0 SaveData(workingDir + fileName + '.vts', proxy=calculator, Writealltimestepsasfileseries=0, DataMode='Appended', EncodeAppendedData=1, CompressorType='ZLib') 使用ParaView安装文件夹中的pvpython执行脚本:pvpython csvToVts.py N32E020 转换完成后,将生成N32E020.vts文件。4.使用ParaView进行可视化 将上述步骤生成的N32E020.vts文件加载到ParaView中,即可进行可视化。 来源:CFD饭圈