運用shapefile.js解析Shp文件


<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<script src="shapefile.js"></script>
<script>
 
shapefile.open("http://localhost:8181/shp/zd.shp")
  .then(source => source.read()
    .then(function log(result) {
      if (result.done) return;
      console.log(result.value);
      return source.read().then(log);
    }))
  .catch(error => console.error(error.stack));
 
</script>
</head>
</html>

  遇到的問題及解決方案(以下以IIS部署為例)

1、

 

解決方案:open打開的一定是一個帶有http或者https的網絡地址

2、HTML頁面跨域訪問shp文件,shp文件在IIS中無法訪問

 解決方案:dbf無法訪問需要添加MIME類型shp無法訪問需要添加MIME類型

 

 

 

 

3、成功解析數據但數據出現中文亂碼

 

解決方案:下載Shapefile.js源文件:https://unpkg.com/shapefile@0.6 下載完成后修改源文件中的數據編碼類型

 

 修改為gb2312

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM