Cesium解析txt,dex,geojson,shpfile-zip

本文介绍如何使用Cesium加载多种格式的地理空间数据文件,包括TXT、DXF、SHPFILE及ZIP压缩包内的文件。针对不同格式,文章提供了具体的解析方法和示例代码,如借助第三方库将DXF转换为GeoJSON格式,并直接加载到Cesium中。
cesium解析txt,dxf,shpfile的zip,geojson文件

geojson的文件,读取后直接就是geojson格式,cesium有相对应的示例可以直接加载,所以没有过多要说的.

dxf文件是借助一个js库读取的,返回的也是geojson格式.同样用来直接加载即可

shpfile解析同dxf文件的解析步骤

txt文件由于参数过于特殊,而且并没有找到一些相对应的工具库,所以自己去解析的,对于格式有很大的局限性,目前支持一种格式,稍微我会把格式分享出来,仅供参考
话不多说,上代码 ✅

  const axios = require('axios');
        let fileType = params.fileUrl
          .split('.')
          .pop()
          .toLowerCase();
        let FormParams = {
   
   
          url: `/getFile${
     
     params.fileUrl}`,
          method: 'get',
          headers: {
   
   
            needToken: true
          }
        };
        if (fileType == 'zip') FormParams.responseType = 'arraybuffer';
        axios(FormParams).then(res => {
   
   
          switch (fileType) {
   
   
            case 'dxf':
              let blob = new Blob([res.data], {
   
   
                type: 'application/octet-stream'
              }); 
              let files = new window.File([blob], 'admin.dfx', {
   
   
                type: 'application/octet-stream'
              });
              this.setDXF(files);
              break;
            case 'geojson':
              if (res.status == 200) {
   
   
                // console.log(res.data);
                let sourceData = Cesium.GeoJsonDataSource.load(res.data);
                this.viewer.dataSources.add(sourceData);
                this.viewer.flyTo(sourceData);
              }
              break;
            case 'txt':
              this.setTxt('', res.data);
              break;
            case 'zip':
              let ziPblob = new Blob([res.data], {
   
   });
              let zipFile = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值