计算DEM上的Profile图
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, gdal, os
from gdalconst import GA_ReadOnly
from os.path import realpath
from shapely.geometry import LineString #根据坐标点计算该点所在栅格上的值
def get_elevation(x_coord, y_coord, raster, bands, geo_trans):
"""
get the elevation value of each pixel under
location x, y
:param x_coord: x coordinate
:param y_coord: y coordinate
:param raster: gdal raster open object
:param bands: number of bands in image
:param gt: raster limits
:return: elevation value of raster at point x,y
"""
elev_list = []
x_origin = geo_trans[0]
y_origin = geo_trans[3]
pix_width = geo_trans[1]
pix_height = geo_trans[5]
#计算栅格点的位置
x_pt = int((x_coord - x_origin) / pix_width)
y_pt = int((y_coord - y_origin) / pix_height)
for band_num in range(bands):
ras_band = raster.GetRasterBand(band_num + 1)
#计算栅格点的值
ras_data = ras_band.ReadAsArray(x_pt, y_pt, 1, 1)
elev_list.append(ras_data[0][0])
return elev_list def write_to_csv(csv_out, profil_x_z):
# check if output file exists on disk if yes delete it
if os.path.isfile(csv_out):
os.remove(csv_out) # create new CSV file containing X (distance) and Z value pairs
with open(csv_out, 'a') as outfile:
# write first row column names into CSV
outfile.write("distance,elevation" + "\n")
# loop through each pair and write to CSV
for x, z in profil_x_z:
outfile.write(str(round(x, 2)) + ',' + str(round(z, 2)) + '\n') if __name__ == '__main__':
# set directory
in_dem = realpath("../geodata/dem_3857.dem") # open the image
ds = gdal.Open(in_dem, GA_ReadOnly) if ds is None:
print('Could not open image')
sys.exit(1) # get raster bands
bands = ds.RasterCount # get georeference info
transform = ds.GetGeoTransform() # line defining the the profile
line = LineString([(-13659328.8483806, 6450545.73152317), (-13651422.7820022, 6466228.25663444)])
# length in meters of profile line
length_m = line.length # lists of coords and elevations
x = []
y = []
z = []
# distance of the topographic profile
distance = []
#每隔20取一个点
for curent_dist in range(0, int(length_m), 20):
#利用线性分段计算点的坐标
# creation of the point on the line
point = line.interpolate(curent_dist)
xp, yp = point.x, point.y
x.append(xp)
y.append(yp)
#获取该点的高程值
# extraction of the elevation value from the MNT
z.append(get_elevation(xp, yp, ds, bands, transform)[0])
distance.append(curent_dist) print (x)
print (y)
print (z)
print (distance) # combine distance and elevation vales as pairs
profile_x_z = zip(distance, z) csv_file = os.path.realpath('../geodata/output_profile.csv')
# output final csv data
write_to_csv(csv_file, profile_x_z)
计算DEM上的Profile图的更多相关文章
- 相机拍的图,电脑上画的图,word里的文字,电脑屏幕,手机屏幕,相机屏幕显示大小一切的一切都搞明白了!
相机拍的图,电脑上画的图,word里的文字,电脑屏幕,手机屏幕,相机屏幕显示大小一切的一切都搞明白了! 先说图片X×dpi=点数dotX是图片实际尺寸,简单点,我们只算图片的高吧,比如说拍了张图片14 ...
- java 计算地球上两点间距离
/** * 计算地球上任意两点(经纬度)距离 * * @param long1 * 第一点经度 * @param lat1 * 第一点纬度 * @param long2 * 第二点经度 * @para ...
- JAVA 计算地球上任意两点(经纬度)距离
/** * 计算地球上任意两点(经纬度)距离 * * @param long1 * 第一点经度 * @param lat1 * 第一点纬度 * @param long2 * 第二点经度 * @para ...
- OpenStack-Ocata版+CentOS7.6 云平台环境搭建 — 6.在计算节点上安装并配置计算服务Nova
安装和配置计算节点这个章节描述如何在计算节点上安装和配置计算服务. 计算服务支持几种不同的 hypervisors.为了简单起见,这个配置在计算节点上使用 :KVM <kernel-based ...
- vue 弹性布局 实现长图垂直居上,短图垂直居中
vue 弹性布局 实现长图垂直居上,短图垂直居中 大致效果如下图,只考虑垂直方向.长图可以通过滚动条看,短图居中效果,布局合理 html代码(vue作用域内): <div class=" ...
- 帝国CMS7.2新增多图同时上传插件,上传多图效率更高
原来上传多图文件,需要挨个选择文件,然后再点批量上传,比较麻烦.所以帝国CMS7.2新增了多图上传插件:为采用FLASH方式实现同时选择多个图片一起上传,提高多图上传效率. 帝国CMS多图上传插件特性 ...
- 计算地球上两个坐标点(经度,纬度)之间距离sql函数
go --计算地球上两个坐标点(经度,纬度)之间距离sql函数 --作者:lordbaby --整理:www.aspbc.com CREATE FUNCTION [dbo].[fnGetDistanc ...
- 计算地图上两点间的距离PHP类
计算地图上两点间的距离,使用的是谷歌地图 <?php class GeoHelper { /** * @param int $lat1 * @param int $lon1 * @param i ...
- 在IOS中根据圆心坐标、半径和角度计算圆弧上的点坐标
/** 日期:2015-10-15 版本: 1.0.0 -------------------------------------------------------------- 功能说明 ---- ...
随机推荐
- Linux rsync实现断点续传
Linux 主机之间即时传送文件,scp命令大家都很熟悉但当要传送的文件较大,过程中如果网络中断了,就比较悲剧了.这时候可以考虑使用rsync命令替代scp,实现断点续传文件. 试验:rsync使用 ...
- QT学习笔记6
事件(event) 一般来说,使用Qt编程时,我们并不会把主要精力放在事件上,因为在Qt中,需要我们关心的事件总会发出一个信号.比如,我们关心的是QPushButton的鼠标点击,但我们不需要关心这个 ...
- UWP开发入门(二十三)——WebView
本篇讨论在UWP开发中使用WebView控件时常见的问题,以及一些小技巧. WebView是实际开发中常用的控件,很多大家抱怨的套网页的应用都是通过WebView来实现的.这里要澄清一个问题,套网页的 ...
- ansible写一个简单的playbook
前言 实现的功能很简单,就是通过ansible批量完成某个账户sudo权限的开通或关闭 目录结构 ├── group_vars #放置各种变量的目录,我这里没用 ├── hosts #主机和组配置,默 ...
- 使用Spark分析拉勾网招聘信息(三): BMR 入门
简述 本文,意在以最小的篇幅,来帮助对大数据和Spark感兴趣的小伙伴,能尽快搭建一个可用的Spark开发环境.力求言简意赅.文章,不敢自称BMR的最佳实践,但绝对可以帮助初学者,迅速入门,能够专心于 ...
- 基于WinCE的JSON 类库 源码
基于WinCE的JSON 类库,可以将对象序列化成字符串和文件. 提示,其在反序列化时有一个BUG: 如果对象的某个字段值为 null,将其序列化成字符串,然后将该字符串反序列化成对象时会报异常. 这 ...
- Entity Framework 实体框架的形成之旅--实体框架的开发的几个经验总结
在前阵子,我对实体框架进行了一定的研究,然后把整个学习的过程开了一个系列,以逐步深入的方式解读实体框架的相关技术,期间每每碰到一些新的问题需要潜入研究.本文继续前面的主题介绍,着重从整体性的来总结一下 ...
- C#中的可空值类型
C# 不允许把 null 赋给一个值类型的数据.在 C# 中,以下语句是非法的: int a = null; // 非法 但是,利用 C# 定义的一个修饰符,可将一个变量声明为一个可空(null ...
- 【Java每日一题】20161024
20161021问题解析请点击今日问题下方的"[Java每日一题]20161024"查看 package Oct2016; public class Ques1024 { publ ...
- 你知道url中的特殊符号含义么
1.# #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如,http://www.example.com/index.html#print就代表网页index.html的print位置.浏 ...