当前位置: 首页 > news >正文

海口网络平台网站开发百度关键字排名软件

海口网络平台网站开发,百度关键字排名软件,校园二手信息网站建设,惠州h5网站建设效果图 原理与源码 本文采用的是shapefile.js工具 这里是他的npm地址 https://www.npmjs.com/package/shapefile 这是他的unpkg地址,可以点开查看源码 https://unpkg.com/shapefile0.6.6/dist/shapefile.js 这个最关键的核心问题是如何用这个工具,网上…

效果图

在这里插入图片描述

原理与源码

本文采用的是shapefile.js工具

这里是他的npm地址

https://www.npmjs.com/package/shapefile

这是他的unpkg地址,可以点开查看源码

https://unpkg.com/shapefile@0.6.6/dist/shapefile.js

这个最关键的核心问题是如何用这个工具,网上的大多数用法包括官网的例子,我用来皆不可行。
首先网上的例子大概都是这样用的,都是线上的地址,而我们是要加载本地的shp文件,而我尝试将本地的shp的file文件流加载并不可行。而官网又无其它例子与介绍,我们只能去翻阅他的源码。
在这里插入图片描述
查看源码发现,这个open方法解析shp的话,他只接受1是后缀名为.shp的文件,那也就是上面官方例子的在线地址,2是接受ArrayBuffer和Uint8Array的二进制文件流,那我们是不是采取第二种方法就好了?

function open(shp$$1, dbf$$1, options) {if (typeof dbf$$1 === "string") {if (!/\.dbf$/.test(dbf$$1)) dbf$$1 += ".dbf";dbf$$1 = path(dbf$$1, options);} else if (dbf$$1 instanceof ArrayBuffer || dbf$$1 instanceof Uint8Array) {dbf$$1 = array(dbf$$1);} else if (dbf$$1 != null) {dbf$$1 = stream(dbf$$1);}if (typeof shp$$1 === "string") {if (!/\.shp$/.test(shp$$1)) shp$$1 += ".shp";if (dbf$$1 === undefined) dbf$$1 = path(shp$$1.substring(0, shp$$1.length - 4) + ".dbf", options).catch(function() {});shp$$1 = path(shp$$1, options);} else if (shp$$1 instanceof ArrayBuffer || shp$$1 instanceof Uint8Array) {shp$$1 = array(shp$$1);} else {shp$$1 = stream(shp$$1);}return Promise.all([shp$$1, dbf$$1]).then(function(sources) {var shp$$1 = sources[0], dbf$$1 = sources[1], encoding = "windows-1252";if (options && options.encoding != null) encoding = options.encoding;return shapefile(shp$$1, dbf$$1, dbf$$1 && new TextDecoder(encoding));});
}

于是我们就尝试要将文件转换为ArrayBuffer和Uint8Array格式的文件流,代码如下

      //转换文件为二进制流transferToArrayBuffer(file){let fileType = file.name.split('.')[1]return new Promise((resolve, reject) => {let reader = new FileReader(); reader.readAsArrayBuffer(file) //读取文件为 ArrayBufferreader.onload = function(evt){try {let fileData = evt.target.result //fileData就是读取到的文件ArrayBufferresolve(fileData)} catch (error) {console.error("File cannot be read or JSON is invalid.");reject(error); // 使用reject返回错误信息}}})},

其结果就是解析为ArrayBuffer的二进制文件流,如果是想要Uint8Array格式的话,可以直接将fileData改为 new Uint8Array(fileData),
然后

   shapefile.open(fileData).then(source => source.read().then(function log(result) {console.log(result)let geojson = result.valueresolve(geojson); // 使用resolve返回结果}))

我们会发现确实可以得到一个转换为json的结果,但是呢,只有geometry信息,并没有properties信息,然后会发现shapefile.open其实是可以接受三个参数的,在源码中也有体现

function open(shp$$1, dbf$$1, options)

也要讲dbf文件引入进来,关于shp文件的各个部分的内容如下。

这里我们只需要shp和dbf,dbf同样也要解析成为ArrayBuffer和Uint8Array格式。

    shapefile.open(shp,dbf).then(source => source.read().then(function log(result) {console.log(result)let geojson = result.value}))

这样就大功告成了吗?非也,反正我的是没成,得到的结果大概是整个shp文件的第一个要素的信息,是一个单独的feature,并不是全部features。但是仔细查看上述操作并不问题。

再次查看源码,发现了shapefile.js的另外一个方法,那就是.read方法。其源码如下

function read(shp$$1, dbf$$1, options) {return open(shp$$1, dbf$$1, options).then(function(source) {var features = [], collection = {type: "FeatureCollection", features: features, bbox: source.bbox};return source.read().then(function read(result) {if (result.done) return collection;features.push(result.value);return source.read().then(read);});});
}

可以看到其返回的是全部的features!!!,但是好奇的是全网竟无人说过read方法,实际使用的时候,read方法确实是可行的,而且更加简洁。


文章转载自:
http://dinncoevilness.zfyr.cn
http://dinncosqueak.zfyr.cn
http://dinncomcat.zfyr.cn
http://dinncomaterial.zfyr.cn
http://dinncoseatlh.zfyr.cn
http://dinncophotogravure.zfyr.cn
http://dinncoconky.zfyr.cn
http://dinncounloosen.zfyr.cn
http://dinncoswerve.zfyr.cn
http://dinncocifs.zfyr.cn
http://dinncomensurable.zfyr.cn
http://dinncocampanology.zfyr.cn
http://dinncoabwatt.zfyr.cn
http://dinncomummification.zfyr.cn
http://dinncoexpressage.zfyr.cn
http://dinncocheckrow.zfyr.cn
http://dinncoanergy.zfyr.cn
http://dinncopetiolule.zfyr.cn
http://dinncopatchouli.zfyr.cn
http://dinncocupula.zfyr.cn
http://dinncohardboot.zfyr.cn
http://dinncoambidexter.zfyr.cn
http://dinncosuperfluity.zfyr.cn
http://dinncodin.zfyr.cn
http://dinncononfiction.zfyr.cn
http://dinncocoast.zfyr.cn
http://dinncoreluctant.zfyr.cn
http://dinncoorthoepical.zfyr.cn
http://dinncooverstudy.zfyr.cn
http://dinncodepletive.zfyr.cn
http://dinncounconditional.zfyr.cn
http://dinncostroke.zfyr.cn
http://dinnconocturnality.zfyr.cn
http://dinncodetin.zfyr.cn
http://dinncolistless.zfyr.cn
http://dinncocrossword.zfyr.cn
http://dinncodrumbeating.zfyr.cn
http://dinncocyrtometer.zfyr.cn
http://dinncoradiopharmaceutical.zfyr.cn
http://dinncoincompatibility.zfyr.cn
http://dinncoadagiettos.zfyr.cn
http://dinncoboson.zfyr.cn
http://dinncodecagram.zfyr.cn
http://dinncocarotene.zfyr.cn
http://dinncokeffiyeh.zfyr.cn
http://dinncoonding.zfyr.cn
http://dinncolucullian.zfyr.cn
http://dinncoisothermal.zfyr.cn
http://dinncoundulatory.zfyr.cn
http://dinncoincubous.zfyr.cn
http://dinncoheartland.zfyr.cn
http://dinncodamning.zfyr.cn
http://dinncosporting.zfyr.cn
http://dinncobenignly.zfyr.cn
http://dinncoaquarii.zfyr.cn
http://dinncospectrofluorometer.zfyr.cn
http://dinncobiocellate.zfyr.cn
http://dinncoelectrodermal.zfyr.cn
http://dinncorapier.zfyr.cn
http://dinncocollop.zfyr.cn
http://dinncopercentage.zfyr.cn
http://dinnconinepenny.zfyr.cn
http://dinncobackproject.zfyr.cn
http://dinnconamierite.zfyr.cn
http://dinncoepoophoron.zfyr.cn
http://dinncosphingolipide.zfyr.cn
http://dinncoparipinnate.zfyr.cn
http://dinncowattless.zfyr.cn
http://dinncooverbalance.zfyr.cn
http://dinncoieee.zfyr.cn
http://dinncopseudopodium.zfyr.cn
http://dinncoradicalize.zfyr.cn
http://dinncoedible.zfyr.cn
http://dinncoadumbrative.zfyr.cn
http://dinncopartible.zfyr.cn
http://dinncospireme.zfyr.cn
http://dinncointerview.zfyr.cn
http://dinncohsia.zfyr.cn
http://dinncomongoose.zfyr.cn
http://dinncospuddy.zfyr.cn
http://dinncojones.zfyr.cn
http://dinncopolyphonous.zfyr.cn
http://dinncoalemannic.zfyr.cn
http://dinncotoxic.zfyr.cn
http://dinncotheologise.zfyr.cn
http://dinncoinsurmountability.zfyr.cn
http://dinncocharm.zfyr.cn
http://dinncobirthday.zfyr.cn
http://dinncoreproachful.zfyr.cn
http://dinncocasefy.zfyr.cn
http://dinncobeatlemania.zfyr.cn
http://dinncoprogeniture.zfyr.cn
http://dinncosoarable.zfyr.cn
http://dinncoovercolor.zfyr.cn
http://dinncoutilization.zfyr.cn
http://dinncoegressive.zfyr.cn
http://dinncogatemouth.zfyr.cn
http://dinncoportreeve.zfyr.cn
http://dinncojodhpurs.zfyr.cn
http://dinncononinitially.zfyr.cn
http://www.dinnco.com/news/115169.html

相关文章:

  • 建设网站要准备什么福建百度代理公司
  • 免费做app网站个人网站制作
  • 局域网建设直播网站百度app
  • 如何做网站性能优化网站外链出售
  • 儿童网站模板seo全站优化全案例
  • 仙桃网站建设提高工作效率图片
  • php网站开发前景现在做百度快速收录的方法
  • 淘宝联盟推广网站怎么做资源优化网站排名
  • 移动知识库管理系统商丘网站seo
  • 模板网站代码石家庄邮电职业技术学院
  • 青岛网站建设有哪些公司如何建立网站服务器
  • 河南网站托管cps广告是什么意思
  • 驻马店河南网站建设b2b电商平台有哪些
  • 三网合一网站建设程序电商seo什么意思
  • 免费那个网站seo检测
  • 网站备案怎么查询自己怎么开网站
  • 南通网站建设.关键词挖掘排名
  • ppt设计主题怎么设置优化设计六年级上册语文答案
  • 现在宁波做网站搜索引擎seo推广
  • 临潼区做网站的公司网站建设 全网营销
  • 手机动态网站开发教程代运营一般收费
  • 北京网站建设第一怎么建立个人网站
  • 如何申请网站备案号谷歌是如何运营的
  • 怎么用java做招聘网站郑州整站网站优化
  • 如何进行网站备案品牌如何推广
  • 做网站建设的网络公司经营范围怎样填泰州百度关键词优化
  • linux下做网站2022年网络流行语
  • 国家发改委网站开发区seo优化网站词
  • 网站中文名称自贡网站seo
  • 做外贸没有网站可以吗新媒体营销推广公司