1、shp转换成json格式
此处整理了两种shp转为json格式的方式:一是使用工具;二是使用ArcGIS进行转换。
1.1、ArcGIS转换
1、使用ArcGIS将shp文件的地理坐标设置为WGS_198484并导出为shp数据。
(1)打开ArcGIS的Toolbox工具箱,选择“定义投影”:

(2)选择要转换的shp格式文件并选择地理坐标为 WGS_1984,单击确认。

(3)将shp(WGS1984坐标系)数据导出。

(4)打开ArcGIS的Toolbox工具,选择转换工具中的要素转JSON,并选择前面设置过地理坐标的shp文件。


1.2、使用mapshaper工具转换
(1)打开网站 http://www.mapshaper.org/

(2)点击select按钮,选择目标shp图层

(3)确认,inport导入。

(4)点击右上角的export,选择GeoJson ,输入encoding=utf8,点击export。

2、Cesium添加GeoJson数据
将前面转换得到的json格式世界数据叠加到Cesium的底图上。
//添加geojson格式地理数据(由shp格式文件转换得来)
Cesium.Math.setRandomNumberSeed(0);
var promise =Cesium.GeoJsonDataSource.load('Output_bou2_4p.json');
promise.then(function (dataSource) {
viewer.dataSources.add(dataSource);
var entities =dataSource.entities.values;
var colorHash = {};
for (var i = 0; i < entities.length;i++) {
var entity = entities[i];
var name = entity.name;
var color = colorHash[name];
if (!color) {
color =Cesium.Color.fromRandom({
alpha: 1.0
});
colorHash[name] = color;
}
entity.polygon.material = color;
entity.polygon.outline = false;
entity.polygon.extrudedHeight =5000.0;
}
});
viewer.flyTo(promise);
延伸:如果shp格式文件中有包含各个面的面积或者周长的话,通过一下代码使得加载出来的json数据呈立体形状
entity.polygon.extrudedHeight= entity.properties.Shape_Area / 100000.0;

网友评论