cesium 计算坡度分析原理:(官网设置的是全球globe的material)

1.计算地形的坡度,把地形分成若干个面,然后就可以把面看为一个点,然后计算面的坡度(面可以自己画)

2.根据坡度大小设置不同的颜色,然后设置方向

//绘制小矩形面 四个经纬度的点,z值高度可以忽略 如:113.xx  ,37.xx,0 ,113.xx,37.xx,0
function drawSlopePolygon(startx1, starty1, startz1, startx2, starty2, startz2, startx3, starty3, startz3, startx4, starty4, startz4) {//高度z全为0var count = 100;var slopelineposition = [];var hireacys = [];var hireacysdistance = []for (j = 0; j < 100; j++) {for (var i = 0; i < 100; i++) {var hireacy = [] ;//分割成小面,切分经纬度hireacy.push(new Cesium.Cartesian3(startx1 + (startx2 - startx1) / count * i + (startx4 + (startx3 - startx4) / count * (i) - startx1 - (startx2 - startx1) / count * i) / count * j,starty1 + (starty2 - starty1) / count * i + (starty4 + (starty3 - starty4) / count * (i) - starty1 - (starty2 - starty1) / count * i) / count * j,startz1 + (startz2 - startz1) / count * i + (startz4 + (startz3 - startz4) / count * (i) - startz1 - (startz2 - startz1) / count * i) / count * j))hireacy.push(new Cesium.Cartesian3(startx1 + (startx2 - startx1) / count * (i + 1) + (startx4 + (startx3 - startx4) / count * (i + 1) - startx1 - (startx2 - startx1) / count * (i + 1)) / count * j, starty1 + (starty2 - starty1) / count * (i + 1) + (starty4 + (starty3 - starty4) / count * (i + 1) - starty1 - (starty2 - starty1) / count * (i + 1)) / count * j,startz1 + (startz2 - startz1) / count * (i + 1) + (startz4 + (startz3 - startz4) / count * (i + 1) - startz1 - (startz2 - startz1) / count * (i + 1)) / count * j))hireacy.push(new Cesium.Cartesian3(startx4 + (startx3 - startx4) / count * (i + 1) - (startx4 + (startx3 - startx4) / count * (i + 1) - startx1 - (startx2 - startx1) / count * (i + 1)) / count * (count - 1 - j),starty4 + (starty3 - starty4) / count * (i + 1) - (starty4 + (starty3 - starty4) / count * (i + 1) - starty1 - (starty2 - starty1) / count * (i + 1)) / count * (count - 1 - j),startz4 + (startz3 - startz4) / count * (i + 1) - (startz4 + (startz3 - startz4) / count * (i + 1) - startz1 - (startz2 - startz1) / count * (i + 1)) / count * (count - 1 - j)))hireacy.push(new Cesium.Cartesian3(startx4 + (startx3 - startx4) / count * i - (startx4 + (startx3 - startx4) / count * (i) - startx1 - (startx2 - startx1) / count * i) / count * (count - 1 - j), starty4 + (starty3 - starty4) / count * i - (starty4 + (starty3 - starty4) / count * (i) - starty1 - (starty2 - starty1) / count * i) / count * (count - 1 - j),startz4 + (startz3 - startz4) / count * i - (startz4 + (startz3 - startz4) / count * (i) - startz1 - (startz2 - startz1) / count * i) / count * (count - 1 - j)))hireacys.push(hireacy);//取出面的8个点坐标,拿点坐标去求高度值slopelineposition.push(Cesium.Cartographic.fromDegrees(hireacy[0].x,hireacy[0].y));slopelineposition.push(Cesium.Cartographic.fromDegrees((hireacy[0].x+hireacy[1].x)/2,(hireacy[0].y+hireacy[1].y)/2));slopelineposition.push(Cesium.Cartographic.fromDegrees(hireacy[1].x,hireacy[1].y));slopelineposition.push(Cesium.Cartographic.fromDegrees((hireacy[1].x+hireacy[2].x)/2,(hireacy[1].y+hireacy[2].y)/2));slopelineposition.push(Cesium.Cartographic.fromDegrees(hireacy[2].x,hireacy[2].y));slopelineposition.push(Cesium.Cartographic.fromDegrees((hireacy[2].x+hireacy[3].x)/2,(hireacy[2].y+hireacy[3].y)/2));slopelineposition.push(Cesium.Cartographic.fromDegrees(hireacy[3].x,hireacy[3].y));slopelineposition.push(Cesium.Cartographic.fromDegrees((hireacy[3].x+hireacy[0].x)/2,(hireacy[3].y+hireacy[0].y)/2));}}var promise = Cesium.sampleTerrainMostDetailed(terrainProvider, slopelineposition);Cesium.when(promise,function(updatedPositions) {//拿到所有的高度数据var heighmm = [];var m = 0//计算坡度比的次数var countcolor1=0;var countcolor2=0;var countcolor3=0;var countcolor4=0;var countcolor5=0;var countcolor6=0;var countcolor7=0;for (var k = 0; k < updatedPositions.length / 8; k++) {//第一个点与第五个点的坡度var slope1=(updatedPositions[m].height-updatedPositions[m+4].height)/(Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(updatedPositions[m].latitude, updatedPositions[m].longitude,updatedPositions[m].height ),Cesium.Cartesian3.fromDegrees(updatedPositions[m+4].latitude, updatedPositions[m+4].longitude,updatedPositions[m+4].height)))//第二个点与第六个点的坡度var slope2=(updatedPositions[m+1].height-updatedPositions[m+5].height)/(Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(updatedPositions[m+1].latitude, updatedPositions[m+1].longitude, updatedPositions[m+1].height),Cesium.Cartesian3.fromDegrees(updatedPositions[m+5].latitude, updatedPositions[m+5].longitude, updatedPositions[m+5].height)))//第三个点与第七个点的坡度var slope3=(updatedPositions[m+2].height-updatedPositions[m+6].height)/(Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(updatedPositions[m+2].latitude, updatedPositions[m+2].longitude, updatedPositions[m+2].height),Cesium.Cartesian3.fromDegrees(updatedPositions[m+6].latitude, updatedPositions[m+6].longitude, updatedPositions[m+6].height)))//第四个点与第八个点的坡度var slope4=(updatedPositions[m+3].height-updatedPositions[m+7].height)/(Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(updatedPositions[m+3].latitude, updatedPositions[m+3].longitude, updatedPositions[m+3].height),Cesium.Cartesian3.fromDegrees(updatedPositions[m+7].latitude, updatedPositions[m+7].longitude, updatedPositions[m+7].height)))// console.log("slope1:"+slope1+";slope2:"+slope2+";slope3:"+slope3+";slope4:"+slope4);var arrposition=[Math.abs(slope1) ,Math.abs(slope2),Math.abs(slope3),Math.abs(slope4)];//取绝对值arrposition.sort();var slope= arrposition[3]; // 拿到最大的坡度值  var lineposition=[];//画方向线的坐标if(slope==Math.abs(slope1)){if(slope1>0){lineposition.push( Cesium.Math.toDegrees(updatedPositions[m].longitude),Cesium.Math.toDegrees(updatedPositions[m].latitude), Cesium.Math.toDegrees(updatedPositions[m+4].longitude),Cesium.Math.toDegrees(updatedPositions[m+4].latitude));}else{lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+4].longitude),Cesium.Math.toDegrees(updatedPositions[m+4].latitude),Cesium.Math.toDegrees(updatedPositions[m].longitude),Cesium.Math.toDegrees(updatedPositions[m].latitude));}}else if(slope==Math.abs(slope2)){if(slope2>0){lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+1].longitude),Cesium.Math.toDegrees(updatedPositions[m+1].latitude), Cesium.Math.toDegrees(updatedPositions[m+5].longitude),Cesium.Math.toDegrees(updatedPositions[m+5].latitude));}else{lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+5].longitude),Cesium.Math.toDegrees(updatedPositions[m+5].latitude),Cesium.Math.toDegrees(updatedPositions[m+1].longitude),Cesium.Math.toDegrees(updatedPositions[m+1].latitude));}}else if(slope==Math.abs(slope3)){if(slope3>0){lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+2].longitude),Cesium.Math.toDegrees(updatedPositions[m+2].latitude), Cesium.Math.toDegrees(updatedPositions[m+6].longitude),Cesium.Math.toDegrees(updatedPositions[m+6].latitude));}else{lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+6].longitude),Cesium.Math.toDegrees(updatedPositions[m+6].latitude),Cesium.Math.toDegrees(updatedPositions[m+2].longitude),Cesium.Math.toDegrees(updatedPositions[m+2].latitude));}}else if(slope==Math.abs(slope4)){if(slope4>0){lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+3].longitude),Cesium.Math.toDegrees(updatedPositions[m+3].latitude), Cesium.Math.toDegrees(updatedPositions[m+7].longitude),Cesium.Math.toDegrees(updatedPositions[m+7].latitude));}else{lineposition.push( Cesium.Math.toDegrees(updatedPositions[m+7].longitude),Cesium.Math.toDegrees(updatedPositions[m+7].latitude),Cesium.Math.toDegrees(updatedPositions[m+3].longitude),Cesium.Math.toDegrees(updatedPositions[m+3].latitude));}}slope=  (Math.abs(slope1) +Math.abs(slope2)+Math.abs(slope3)+Math.abs(slope4))/4; //四个坡度值大小有的差值特别大,这里取的平均值用来配置颜色// console.log(slope);if (0 <= slope && slope < 0.29) {slopecolor = '#ff9090'countcolor1++;} else if (0.29 <= slope && slope < 0.5) {slopecolor = '#ff8080'countcolor2++;} else if (0.5 <= slope && slope < Math.sqrt(2) / 2) {slopecolor = '#ff7070'countcolor3++;} else if (Math.sqrt(2) / 2 <= slope && slope < 0.87) {slopecolor = '#ff6060'countcolor4++;} else if (0.87 <= slope && slope < 0.91) {slopecolor = '#ff5050'countcolor5++;} else if (0.91 <= slope && slope < 0.95) {slopecolor = '#ff4040'countcolor6++;} else  {slopecolor = '#ff3030'countcolor7++;}viewer.entities.add({type:'drawSloperectange',rectangle: {coordinates:  Cesium.Rectangle.fromDegrees(Cesium.Math.toDegrees(updatedPositions[m].longitude), Cesium.Math.toDegrees(updatedPositions[m].latitude),Cesium.Math.toDegrees(updatedPositions[m+4].longitude),Cesium.Math.toDegrees(updatedPositions[m+4].latitude))  ,material:  Cesium.Color.fromCssColorString(slopecolor)},polyline: {clampToGround: true,positions:  Cesium.Cartesian3.fromDegreesArray(lineposition), material:new Cesium.PolylineArrowMaterialProperty(Cesium.Color.fromCssColorString("#ff9090")),// Cesium.Color.BLUE.withAlpha(0.5) ,width: 8,distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, updatedPositions[m+4].height+4500)},});m += 8;}var contents="<div class='slope_layer'><div> <div style='height:19px;background-color:#ff9090; width: 64px;float: left;'> </div><span >"+(countcolor1/(updatedPositions.length / 8)*100).toFixed(2)+"% (<0.29)</span></div>";contents+=" <div  style='clear: both;'><div style='height:19px;background-color:#ff8080 ; width: 64px;float: left;'></div><span >  "+(countcolor2/(updatedPositions.length / 8)*100).toFixed(2)+"%(<0.5)</span></div>";contents+="<div   style='clear: both;'><div  style='height:19px;background-color:#ff7070;width: 64px;float: left;'> </div><span >"+(countcolor3/(updatedPositions.length / 8)*100).toFixed(2)+"%(<0.7)</span></div>";contents+=" <div  style='clear: both;'><div style='height:19px;background-color:#ff6060;width: 64px;float: left;'> </div><span >"+(countcolor4/(updatedPositions.length / 8)*100).toFixed(2)+"%(<0.87)</span></div>";contents+=" <div  style='clear: both;'><div style='height:19px;background-color:#ff5050;width: 64px;float: left;'> </div><span > "+(countcolor5/(updatedPositions.length / 8)*100).toFixed(2)+"%(<0.91)</span></div>";contents+=" <div  style='clear: both;'><div style='height:19px;background-color:#ff4040;width: 64px;float: left;'> </div><span >"+(countcolor6/(updatedPositions.length / 8)*100).toFixed(2)+"%(<0.95)</span></div>";contents+=" <div  style='clear: both;'><div style='height:19px;background-color:#ff3030;width: 64px;float: left;'> </div><span > "+(countcolor7/(updatedPositions.length / 8)*100).toFixed(2)+"%(<1)</span></div></div>";layer.closeAll();layer.open({type: 1,offset: ["500px", "1200px"],area: ['260px', '179px'],title: "坡度分析信息",content:contents ,btnAlign: 'c' //按钮居中,shade: 0 //不显示遮罩,cancel: function(index) {layer.close(index);}});  })}

这里放两张图片效果

这个功能废了我好长时间,在此把代码贴上,如果帮助到你,可以

下个软件免费领取购物券(IOS 需要激活,网站有激活码):365淘券吧  http://www.365tqb.com

hahahahahahahahahaha

Cesium计算坡度坡向分析相关推荐

  1. GDAL使用DEM数据计算坡度坡向

    零.        前言 之前写过一个3×3的通用模板算子函数的博客<基于GDAL的一个通用的3×3模板函数>,网址:http://blog.csdn.net/liminlu0314/ar ...

  2. Google Earth Engine(GEE)最基础代码学习笔记6——计算坡度坡向

    1.Google Earth Engine 计算坡度 计算坡度坡向使用ee.Terrain包计算. // 加载 SRTM 影像. var srtm = ee.Image('CGIAR/SRTM90_V ...

  3. 如何进行坡度坡向分析教程

    ArcGIS教程之DEM(高程)的应用(坡度坡向.提等高线) 相关教程:           DEM水文分析(一)           Arcgis下DEM水文分析(二) DEM的应用包括:坡度:Sl ...

  4. cesium坡度坡向分析_综合分析地理空间,科学规划乡村区域

    党的十九大报告提出了实施乡村振兴战略,坚持农业农村优先发展,努力做到"产业兴旺.生态宜居.乡风文明.治理有效.生活富裕".这是我国很重要的一个战略选择.报告提出,要建立健全城乡融合 ...

  5. cesium坡度坡向分析_景观设计分析图制作技巧到底是什么?

    国外设计中,人们都开始用动态分析图啦 厉害的不要不要啊! 如果你也想做如此高逼格的分析图 记得往下看! 景观设计分析为:人文,背景,区位,现状,历史,功能,流线,景观格局,竖向,高程,节点,基地分析等 ...

  6. 基于DEM的坡度坡向分析

  7. python计算坡度_基于python实现利用DEM数据计算坡度、坡向

    1.Python的地形三维可视化--简介Matplotlib和gdal https://blog.csdn.net/allenlu2008/article/details/51880333 2.Pyc ...

  8. 基于python实现利用DEM数据计算坡度、坡向

    基本概念 DEM数据 DataMark:CNSDTF-DEM Version:1.0 Unit:M Alpha:0.000000 Compress:0.000000 X0:258000.000 Y0: ...

  9. 【GDAL】python读取DEM计算坡度与坡向

    利用GDAL读入DEM与Landsat影像,由于DEM是WG84坐标系,Landsat是WGS84坐标系UTM投影,因此处理在实际应用中需要将DEM进行投影转换. 大概分为以下几个步骤: 读取DEM, ...

最新文章

  1. 关于移动端rem适配
  2. 一些实用的注册表封装类
  3. python 权限控制 linux_16linux的acl的控制权限的介绍
  4. 输出超限怎么解决 oj_三菱PLC输出指示灯输出模块不亮怎么解决
  5. Hierarchy of Log-Cauchy
  6. mysql update锁_mysql中update语句的锁
  7. Android 调用相册 拍照 实现系统控件缩放 切割图片
  8. IE10 URL中多出一串字符,图片无法显示
  9. python plt 如何画不同的数据图
  10. 2022年版中国天然气制氢市场运营模式分析与投资战略规划报告
  11. 《信号与系统学习笔记》—信号与系统(三)
  12. WebRTC基本概念
  13. linux/unix系统编程手册下载,Linux/UNIX系统编程手册(pdf+epub+mobi+txt+azw3)
  14. 弯管机编程软件电脑版_聚编程电脑版
  15. VelocityTracker 使用
  16. Nim 博弈游戏详解
  17. Python利用数学方程式画4种不一样的心型图案
  18. 要嫁就嫁个37度男人
  19. openGL法线贴图和纹理贴图结合使用,以增强三维物体表面细节
  20. pandas | DataFrame基础运算以及空值填充

热门文章

  1. 害虫防治技术有哪些?
  2. IDEA中单元测试@Test使用
  3. 年产2万吨山楂酒工厂的设计-装瓶工段及车间的设计(lunwen+任务书+开题+选题表+cad图纸)
  4. 代理模式(Proxy Design Pattern)及代码实现
  5. C语言中的分支结构和循环结构有哪些,【单选题】下面哪种不是C语言中的基本结构______。 A. 顺序结构 B. 分支结构 C. 跳转结构 D. 循环结构...
  6. 分享!快速认证抖音企业蓝V的方案与常见问题
  7. 登录用户互挤 实现的思路
  8. 《数值分析(原书第2版)》—— 2.4 PA=LU分解
  9. ZOOM直播实时字幕(PC端使用谷歌浏览器)
  10. 2018 BACS Regional Programming Contest C. BACS, Scoundrel Shopkeeper and Contiguous Sequence (模拟)