计算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 -------------------------------------------------------------- 功能说明 ---- ...
随机推荐
- IOS开发-KVC
1. 什么是kvc kvc--key-value coding,健值编码 可以通过key直接访问对象属性的value的方法 2.使用场景 kvc主要是为了让代码变的更简介明了 用的比较多的是在后台数据 ...
- Spring MVC 学习总结(二)——控制器定义与@RequestMapping详解
一.控制器定义 控制器提供访问应用程序的行为,通常通过服务接口定义或注解定义两种方法实现. 控制器解析用户的请求并将其转换为一个模型.在Spring MVC中一个控制器可以包含多个Action(动作. ...
- LeetCode:Maximum Depth of Binary Tree_104
LeetCode:Maximum Depth of Binary Tree [问题再现] Given a binary tree, find its maximum depth. The maximu ...
- [software development] 需求分析checklist
[software development] 需求分析checklist // */ // ]]> [software development] 需求分析checklist Table of ...
- 【模式匹配】Aho-Corasick自动机
1. 多模匹配 AC自动机(Aho-Corasick Automaton)是多模匹配算法的一种.所谓多模匹配,是指在字符串匹配中,模式串有多个.前面所介绍的KMP.BM为单模匹配,即模式串只有一个.假 ...
- ElasticSearch 配置详解
配置文件位于es根目录的config目录下面,有elasticsearch.yml和logging.yml两个配置,主配置文件是elasticsearch.yml,日志配置文件是logging.yml ...
- PhotoKit框架介绍及使用
PhotoKit 是一套比 AssetsLibrary 更新更完整也更高效的ios照片处理库,对资源的处理跟 AssetsLibrary 有很大的不同.下面简单介绍下PhotoKit的几个基本概念 P ...
- 【转载】8天学通MongoDB——第八天 驱动实践
作为系列的最后一篇,得要说说C#驱动对mongodb的操作,目前驱动有两种:官方驱动和samus驱动,不过我个人还是喜欢后者, 因为提供了丰富的linq操作,相当方便. 官方驱动:https://gi ...
- 解决未能加载文件或程序集'WebGrease‘的问题
在多个视图中,如果有使用共用的样式代码,可以把它们移至CSS文件中去.今天Insus.NET就举例一个例子来说明.比如前2篇中<ASP.NET MVC图片管理(上传,预览与显示)>http ...
- java的各种类型转换汇总
java类型转换 Integer String Long Float Double Date 1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Intege ...