由于工作业务中遇到需要将OSGB倾斜数据转换成B3DM格式,由cesiumLabWeb加载并显示到浏览器。
1.OSGB数据格式
目录存在Data文件夹以及metadata.xml文件(多说一句Data文件夹下有多个Tile_+001_+0等文件夹构成,这些是相应的瓦片目录结构),xml格式内容主要说明:
<?xml version="1.0" encoding="utf-8"?>
<ModelMetadata version="1">
<!--Spatial Reference System-->
<SRS>EPSG:4521</SRS>
<!--Origin in Spatial Reference System-->
<SRSOrigin>33XXXXX2,26XXXXXX,0</SRSOrigin>
<Texture>
<ColorSource>Visible</ColorSource>
</Texture>
</ModelMetadata>
<!--SRS 表示坐标系 这里采用EPSG:4521 EPSG具体代码可以去百科查询-->
<!--SRSOrigin 表示该倾斜模型的中心点坐标-->
找到自己想要转换的倾斜模型数据目录后,接下来我们开始转换吧!
2. 3Dtiles转换工具
3Dtiles是目前接触到的OSGB转换工具,github简介里称3Dtiles为世界上最快的转换工具。
CesiumGS项目下的3Dtiles,这里简单贴一下链接,大家有兴趣的可以去跟着编译编译,这里我就给大家提供编译好的版本节省大家时间
3Dtiles格式说明
3dtile.exe -f osgb -i E:\Data\hgc -o E:\Data\hgc_test
-f :需要转换的数据格式
-i: 需要转换的数据目录
-o 结果输出数据(如果文件夹不存在会自动帮你创建)
3 java驱动cmd命令执行
/**
*sourceDataPath 数据源目录
*outputDir 输出文件目录 转换后的目录
*/
public boolean osgbTo3dtilesHandler(String sourceDataPath, String outputDir) {
//toolRootPath 是文件夹解压的目录 根据实际情况替换
String toolRootPath = "D:\wisdom\plugins\3dtile";
// 文件夹解压后存在3dtile.exe 可执行程序
String command = toolRootPath + File.separator + "3dtile.exe";
//构建参数 -f 要转换的数据格式 -i 数据源目录 -o 输出文件目录
String[] arguments = {"-f","osgb","-i", sourceDataPath, "-o", outputDir};
Map<String, String> envs = new HashMap<>();
//设置GDAL 环境
envs.put("GDAL_DATA", toolRootPath + File.separator + "gdal_data");
int exitValue = -1;
try {
//执行命令
Process process = CommandUtil.executeCommand(command, arguments, envs);
//等待命令执行完成
exitValue = process.waitFor(); // exit code: 0=success, 1=error
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return exitValue == 0;
}
4 转化后的数据查看,
这里转换的话一般比较耗时,博主70个G的倾斜数据转换大概需要2个多小时