cesium 洪水淹没分析代码实现
时间: 2023-07-31 14:09:35 浏览: 205
cesium淹没分析.zip
Cesium可以通过加载地形、影像和矢量数据,来构建一个真实的地球模型,并进行洪水淹没分析。以下是一些Cesium洪水淹没分析的代码实现示例:
1. 加载影像和地形数据
```javascript
var viewer = new Cesium.Viewer('cesiumContainer');
var imageryLayers = viewer.imageryLayers;
imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({
url: 'http://localhost:8080/geoserver/gwc/service/wmts',
layer: 'workspace:layer',
style: '',
format: 'image/png',
tileMatrixSetID: 'EPSG:4326',
maximumLevel: 20,
credit: new Cesium.Credit('Data © OpenStreetMap contributors, GeoServer')
}));
var terrainProvider = new Cesium.CesiumTerrainProvider({
url: 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
requestVertexNormals: true
});
viewer.terrainProvider = terrainProvider;
```
2. 加载矢量数据
```javascript
var dataSource = new Cesium.GeoJsonDataSource('flood');
viewer.dataSources.add(dataSource);
dataSource.load('http://localhost:8080/geoserver/workspace/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=workspace:layer&outputFormat=application%2Fjson', {
stroke: Cesium.Color.BLACK,
fill: Cesium.Color.BLUE.withAlpha(0.5),
strokeWidth: 3,
clampToGround: true
});
```
3. 洪水淹没分析
```javascript
var floodHeight = 20; // 洪水高度
var floodPolygon = dataSource.entities.getById('workspace:layer.1'); // 获取洪水区域
var floodPolygonPositions = floodPolygon.polygon.hierarchy.getValue().positions; // 获取洪水区域顶点坐标
var floodPolygonHeight = floodPolygonPositions[0].height; // 获取洪水区域高度
var terrainSamplePositions = Cesium.SampledPositionProperty.fromCartographicArray(terrainCartographicPositions, 50); // 获取地形高度采样点
var floodPolygonCartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(floodPolygonPositions); // 将洪水区域顶点坐标转换为地理坐标
// 计算洪水淹没面积
var floodPolygonArea = Cesium.PolygonGeometryLibrary.computeArea2D(floodPolygonCartographicPositions);
var floodHeightArray = new Array(floodPolygonPositions.length).fill(floodPolygonHeight + floodHeight); // 构造洪水高度数组
// 计算洪水淹没体积
var floodPolygonVolume = Cesium.PolygonGeometryLibrary.computeVolume(floodPolygonPositions, floodHeightArray, terrainSamplePositions);
console.log('Flood area: ' + (floodPolygonArea / 1000000).toFixed(2) + ' km²');
console.log('Flood volume: ' + (floodPolygonVolume / 1000000).toFixed(2) + ' million m³');
```
以上代码示例中,首先通过加载影像和地形数据,构建了一个真实的地球模型。然后通过加载矢量数据,获取了洪水淹没区域。最后,通过计算洪水淹没面积和体积,完成了洪水淹没分析。
阅读全文