SRTM DEM hgt格式转成GRID格式的问题解决

原创 2012年03月27日 14:38:05

SRTM数据主要是由美国太空总署(NASA)和国防部国家测绘局(NIMA)联合测量的,SRTM的全称是Shuttle Radar Topography Mission,即航天飞机雷达地形测绘使命。获取的雷达影像数据经过两年多的处理,制成了数字地形高程模型,该测量数据覆盖中国全境。SRTM数据每经纬度方格提供一个文件,精度有1 arc-second和3 arc-seconds两种,称作SRTM1和SRTM3,或者称作30M和90M数据,SRTM1的文件里面包含3601*3601个采样点的高度数据,SRTM3的文件里面包含1201*1201个采样点的高度数据。目前能够免费获取中国境内的RTM3文件,是90米的数据,每个90米的数据点是由 9个30米的数据点算术平均得来的。 SRTM数据下载的地址是:ftp://e0mss21u.ecs.nasa.gov/srtm/ 。我国境内的数据在Eurasia目录下,每经纬度方格一个文件,文件命名方法是X1X2X3X4.hgt.zip,X1是N或S表示南北,X2是下方纬度数,X3是E或W表示东西,X4是左方经度数。

我们在进行地学研究时有时会用到这种免费下载但分辨率适中的数据,可是SRTM数字高程模型的格式是hgt,我们怎么把其转换成ArcGIS支持的格式以供我们查看呢?美国地质调查局的工程师们用AML和地图代数语言混合编程写了一个小程序,专门用来将SRTM数据由hgt转换成GRID格式。把下列代码拷贝到记事本上,另存为srtmgrid.aml。

电脑上需要先安装ArcGIS workstation。

1.打开cmd窗口,用“cd /d 路径”的格式进入hgt数据所存放的位置;

2.然后输入"arc",在ArcGIS workstation arc环境下进行命令行操作;

3.输入“&r srtmgrid.aml”,表示运行我们刚才复制粘贴生成的AML程序。可以看到这个命令的用法。这里提示我们在运行该程序时要输入两个参数:输入文件名和输出文件;

4.明白了第3步以后,让我们正式开始执行该程序。输入“&r srtmgrid.aml N39E114.hgt N39E114”。注意该空格的地方要空格。该命令表示运行(run)srtmgrid.aml程序,输入文件为N39E114.hgt,输出文件为N39E114文件。由文件名我们也能看到:该文件的经纬度方格的范围是北纬39东经114.点击回车,即可执行。

5.再次输入quit,就从GRID环境退回到arc环境中,再次重复输入第4、5步的命令,只需将输入输出文件名改一下,就能将其他hgt文件转成GRID文件了,直到把所有的hgt文件全部转换完成为止。

6.输入“grid”,进入GRID 环境。我们要将第4、5步转换的GRID文件拼接(mosaic)成一个文件。输入“mosaic”,回车,就能看到mosaic命令的用法。我们要指定一个输出文件名,再将第4、5步生成的GRID文件名依次输进去,就行了。我们输入“bjdem = mosaic(N39E114,N39E115,N39E116,N39E117,N40E114,N40E115,N40E116,N40E117,N41E114,N41E115,N41E116,N41E117,N42E114,N42E115,N42E116,N42E117)”,回车,就把这些GRID文件全都拼接成一张图了。

7.有了第6步的成果,数据就算转换完成了,就可以用来进行自己的工作了。如果还想转成tiff格式或shp格式等,在ArcMap里面操作即可,也不难的。这里就不再赘述了。

srtmgrid.aml代码如下:

/*--------------------------------------------------------------------------
/* Program: SRTMGRID.AML
/* Purpose: Convert raw prelminary SRTM elevation data files
/* (.hgt extension) to ESRI GRID format. Many thanks to
/* Arthur Tarr, USGS, (atarr@usgs.gov) for figuring out how
/* to convert SRTM image files to ArcInfo GRID format.
/*
/* The georeferencing and grid-cell resolution
/* for the output grid is determined from the file
/* name and the size of the file.
/*--------------------------------------------------------------------------
/* Usage: &r srtmgrid <dat_file> <out_grid>
/*
/* Arguments:
/*
/* <dat_file> *.hgt binary file of elevation data
/* File must be named according to convention
/* on FTP site, e.g. N45W103.hgt
/*
/* <out_grid> Output grid name (must conform to ArcInfo naming
/* conventions)
/*--------------------------------------------------------------------------
/* Calls: *none*
/*--------------------------------------------------------------------------
/*
/* History:
/* 01/28/02 Curtis Price, USGS, cprice@usgs.gov
/* Original coding. Thanks to Arthur Tarr for figuring
/* out the integer data transformation in GRID.
/* 08/28/02 cprice
/* Updated to work with newer data
/* posted at ftp://edcsgs9.cr.usgs.gov/pub/data/srtm/GDPS
/* Also fixed header to match documentation
/* 11/19/03 cprice
/* Updated to work with global data (all dd quadrants)
/*
/* **********************************************************************
/*
/* Although this program has been used by the U.S. Geological
/* Survey, no warranty, expressed or implied, is made by the USGS as to
/* the accuracy and functioning of the program and related program
/* material nor shall the fact of distribution constitute any such
/* warranty, and no responsibility is assumed by the USGS in connection
/* therewith.
/*
/************************************************************************
&args datfile outgrid
&s os [extract 1 [show &os]]
&if [null %outgrid%] &then &do
&type Usage: &r srtmgrid <dat_file> <out_grid>
&type Example: &r srtmgrid N45W122.hgt srtm1g
&return
&end
&if %:program%_ eq ARC_ &then grid
&if %:program%_ ne GRID_ &then
&return This program must be run from ARC or GRID.
&if %os%_ nc Windows_NT &then &do
&s uxname %datfile%
&s datfile [locase %datfile%]
&if %datfile% ne %uxname% &then &sys mv %uxname% %datfile%
&end
&if ^ [exists %datfile% -file] &then
&return *** Data file %datfile% not found
&if [exists %outgrid% -dir] &then
&return *** %outgrid% exists. Cannot create a grid with that name.
/* extract image parameters from filename
&s fn [locase %datfile%]
&s xxll [unquote [translate %fn% ' ' nsew.hgt]]
&s xxlat [extract 1 %xxll%]
&s xxlon [extract 2 %xxll%]
&if [type %xxlat%] ge 0 &then &s badfn
&if [type %xxlon%] ge 0 &then &s badfn
&if [variable badfn] &then &do
&type Bad filename: %datfile%
&type This AML requires that the original SRTM filename be used.
&type For example: N44W103.hgt
&return
&end
/* determine lat long sign
&if [substr %fn% 1 1]_ eq s_ &then &s xxlat %xxlat% * -1
&if [substr %fn% 4 1]_ eq w_ &then &s xxlon %xxlon% * -1
/* calculate upper left corner of tile
&s xxlat [calc %xxlat% + 1]
/* determine arc-second resolution from filesize
&s tmpfil [scratchname -suf .dat]
&if %os% cn 'Windows_NT' &then &do
&sys dir %datfile% /l /-c > %tmpfil%
&s ch [open %tmpfil% st -r]
&s rec [read %ch% st]
&do &while %st% eq 0 and %rec% nc [locase %datfile%]
&s rec [read %ch% st]
&end
&s st [close %ch%]
&s xfn [unquote %rec%]
&s filesize = [extract [calc [token %xfn% -count] - 1] %xfn%]
&end
&else &do
&sys ls -l %datfile% > %tmpfil%
&s ch [open %tmpfil% st -r]
&s rec [read %ch% st]
&s st [close %ch%]
&s filesize [extract 5 [unquote %rec%]]
&end
&s st [delete %tmpfil%]
&if [type %filesize%] > 0 &then &return ** ERROR problem determining file size
&if %filesize% gt 5e6 &then &s arcsec 1
&else &s arcsec 3
/* calculate image size
&s ncells [calc 3600 / %arcsec% + 1]
&s cellsize [calc %arcsec% / 3600]
&type Reading %datfile% as %arcsec%-arc-second DEM ...
&type Copying image file ...
/* create bil file
&s tmpimg [scratchname -file -suf .bil]
&s st [copy %datfile% %tmpimg%]
/* write hdr file
&s tmphdr [before %tmpimg% .bil].hdr
&s ch [open %tmphdr% st -w]
&s st [write %ch% 'BYTEORDER M']
&s st [write %ch% 'LAYOUT BIL']
&s st [write %ch% [quote NROWS %ncells%]]
&s st [write %ch% [quote NCOLS %ncells%]]
&s st [write %ch% 'NBITS 16']
&s st [write %ch% [quote ULXMAP %xxlon%]]
&s st [write %ch% [quote ULYMAP %xxlat%]]
&s st [write %ch% [quote XDIM %cellsize%]]
&s st [write %ch% [quote YDIM %cellsize%]]
&s st [close %ch%]
&type Image parameters:
&type
&s ch [open %tmphdr% st -r]
&s rec [read %ch% st]
&do &while %st% eq 0
&type %rec%
&s rec [read %ch% st]
&end
&s st [close %ch%]
&type
/* read into data file into grid format
&s tmpgrid [scratchname -dir -suf g]
arc imagegrid %tmpimg% %tmpgrid%
/* convert image values as read to signed integer
/* (imagegrid does not support signed integers)
/* (Thanks to Arthur Tarr, USGS)
%outgrid% = con(~
%tmpgrid% gt 32768, %tmpgrid% - 65536, ~
%tmpgrid% lt 32768, %tmpgrid%)
/* Document projection for ArcInfo applications
arc projectdefine grid %outgrid%
projection geographic
units dd
zunits meters
datum wgs84
param
log %outgrid% add
Created from SRTM input file %datfile%
listoutput %tmphdr% init
&format 6
describe %outgrid%
&format 3
listoutput screen
&s ch [open %tmphdr% st -r]
&lv st ch
&do &until %st% ne 0
&type [read %ch% st]
&end
&s st [close %ch%]
kill %tmpgrid% all
&s st [delete %tmpimg% -file]
&s st [delete %tmphdr% -file]
&if %os% nc 'Windows_NT' &then
&if %datfile% ne %uxname% &then &sys mv %datfile% %uxname%
&return Processing completed.

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

关于js字符串转成日期格式的问题

最近在做项目时,后台传过来的时间是时间戳的,就需要前端来转了,现在的后台是php的,而以前都是Java做的后台,就没考虑,直接调用: function formatDate(date){ ...

【iOS解决方案】网络请求返回GB2312格式的xml数据转成UTF-8后为空(适用于论坛bbs)

一些高校的bbs由于历史久远,没有适应新的数据结构,请求返回的数据还是xml格式的,而现在常用的返回是json,这是个很头疼的地方,碰到的问题网上很难搜到资料,走了很多弯路。 现在具体讲一下在解析返...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

window下文本格式问题解决

【已解决】cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r” 2012 年 6 月 1 日 下午 5:00crifan...

java页面导出csv格式乱码问题解决

问题描述:java页面导出的csv格式的表格,用excel打开有乱码,但是用记事本打开没有乱码能够正常显示。 问题代码:ServletActionContext.getResponse().rese...

Ajax数据返回格式问题解决

Ajax数据返回格式问题解决      服务端返回的数据格式为:      response.setContentType("text/xml;charset=utf-8");      设...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)