zly272823 2019-09-19 09:00 采纳率: 0%
浏览 666
已结题

python读取hgt文件的坐标不统一

第一张为Global mapper打开3个hgt文件——N39E115.hgt、N39E116.hgt、N39E117.hgt第二张为下列python程序打开3个hgt文件——N39E115.hgt、N39E116.hgt、N39E117.hgt

为什么每个数据块显示的方向会不一样,不应该栅格数据自己本身是有经纬度,能够定位的吗?

import os
# Original file:
#'ftp://e0srp01u.ecs.nasa.gov/srtm/version2/SRTM1/Region_04/N39E115.hgt.zip'
if not os.path.exists('N39E115.hgt.zip'):
    # Download the data
    try:
        from urllib import urlopen
    except ImportError:
        from urllib.request import urlopen
    print('Downloading data, please wait (10M)')
    opener = urlopen('ftp://e0srp01u.ecs.nasa.gov/srtm/version2/SRTM1/Region_04/N39E115.hgt.zip')
    open('N39E115.hgt.zip', 'wb').write(opener.read())

# Load the data (signed 2 byte integers, big endian) ##########################
import zipfile
import numpy as np

a=np.fromstring(zipfile.ZipFile('N39E115.hgt.zip').read('N39E115.hgt'),'>i2')
b=np.fromstring(zipfile.ZipFile('N39E116.hgt.zip').read('N39E116.hgt'),'>i2')
c=np.fromstring(zipfile.ZipFile('N39E117.hgt.zip').read('N39E117.hgt'),'>i2')
d=np.fromstring(zipfile.ZipFile('N40E115.hgt.zip').read('N40E115.hgt'),'>i2')
e=np.fromstring(zipfile.ZipFile('N40E116.hgt.zip').read('N40E116.hgt'),'>i2')
f=np.fromstring(zipfile.ZipFile('N40E117.hgt.zip').read('N40E117.hgt'),'>i2')
g=np.fromstring(zipfile.ZipFile('N41E115.hgt.zip').read('N41E115.hgt'),'>i2')
h=np.fromstring(zipfile.ZipFile('N41E116.hgt.zip').read('N41E116.hgt'),'>i2')
i=np.fromstring(zipfile.ZipFile('N41E117.hgt.zip').read('N41E117.hgt'),'>i2')

A=np.hstack((a,b,c)) 
C=np.concatenate([a,b],axis=0)
B=np.append(a,b,axis=0)
data=A
data.shape = (3603,1201)
data = data.astype(np.float32)

# Plot an interesting section #################################################
from mayavi import mlab
data = data[:6000, 0:6000]
# Convert missing values into something more sensible.
data[data == -32768] = data[data > 0].min()
0
mlab.figure(size=(400, 320), bgcolor=(0.16, 0.28, 0.46))
mlab.surf(data, colormap='gist_earth', warp_scale=0.2,
            vmin=0, vmax=3000)
# The data takes a lot of memory, and the surf command has created a
# copy. We free the inital memory.
del data

# A view of the canyon
mlab.view(-5.9, 83, 570, [5.3, 20, 238])
mlab.show()

展开全部

  • 写回答

2条回答 默认 最新

  • dabocaiqq 2019-09-19 09:14
    关注
    评论
  • 关注

     

    这是我参考你的代码修改的,把数据xy轴调换即可

    效果图

    展开全部

    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部