今天就跟大家聊聊有關(guān)如何進(jìn)行g(shù)eojson圖層批量坐標(biāo)轉(zhuǎn)換,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比垣曲網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式垣曲網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋垣曲地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
//引入fs和coordtransform庫(kù) const fs = require('fs'); const coordtransform = require('coordtransform'); //geojson矢量對(duì)象處理 function dataByfeaturetype(_feature) { this.datafeature = _feature; this.featuretype = _feature.geometry.type; this.coords = _feature.geometry.coordinates; this.newcoords = []; } //點(diǎn)、線、面中數(shù)據(jù)坐標(biāo)遍歷處理 dataByfeaturetype.prototype.handlePoint = function () { this.newcoords = coordtransform.wgs84togcj02(this.coords[0], this.coords[1]); } dataByfeaturetype.prototype.handleMultipointOrLinestring = function () { let _tempCoords = []; for (let _udx = 0; _udx < this.coords.length; _udx++) { //這個(gè)根據(jù)自己的需要,選擇坐標(biāo)的偏移處理函數(shù) _tempCoords.push(coordtransform.wgs84togcj02(this.coords[_udx][0], this.coords[_udx][1])); } this.newcoords = _tempCoords; } dataByfeaturetype.prototype.handleMultiLineStringOrPolygon = function () { let _tempCoords = []; for (let _udx = 0; _udx < this.coords.length; _udx++) { let _evCoords = []; for (let _ndx = 0; _ndx < this.coords[_udx].length; _ndx++) { //這個(gè)根據(jù)自己的需要,選擇坐標(biāo)的偏移處理函數(shù) _evCoords.push(coordtransform.wgs84togcj02(this.coords[_udx][_ndx][0], this.coords[_udx][_ndx][1])); } _tempCoords.push(_evCoords); } this.newcoords = _tempCoords; } dataByfeaturetype.prototype.handleMultiPolygon = function () { let _tempCoords = []; for (let _udx = 0; _udx < this.coords.length; _udx++) { let _polygons = []; for (let _ndx = 0; _ndx < this.coords[_udx].length; _ndx++) { let _polygon = []; for (let _tdx = 0; _tdx < this.coords[_udx][_ndx].length; _tdx++) { _polygon.push(coordtransform.wgs84togcj02(this.coords[_udx][_ndx][_tdx][0], this.coords[_udx][_ndx][_tdx][1])); } _polygons.push(_polygon); } _tempCoords.push(_polygons); } this.newcoords = _tempCoords; } //根據(jù)圖層的不同類型,選擇處理方法 dataByfeaturetype.prototype.handleByType = function () { switch (this.featuretype) { case "Point": this.handlePoint(); break; case "MultiPoint": case "LineString": this.handleMultipointOrLinestring(); break; case "MultiLineString": case "Polygon": this.handleMultiLineStringOrPolygon(); break; case "MultiPolygon": this.handleMultiPolygon(); break; } } //獲取數(shù)據(jù)處理結(jié)果 dataByfeaturetype.prototype.getResult = function () { this.datafeature.geometry.coordinates = this.newcoords; return this.datafeature; }; //輸入文件 fs.readFile('輸入geojson文件', { encoding: 'utf-8' }, (err, res) => { if (err) return; let _geojsondata = JSON.parse(res); let _newfeatures = []; let _features = _geojsondata.features; for (let _fdx = 0; _fdx < _features.length; _fdx++) { let _feature = _features[_fdx]; let _featurehandle = new dataByfeaturetype(_feature); _featurehandle.handleByType(); _newfeatures.push(_featurehandle.getResult()); } _geojsondata.features = _newfeatures; //輸出處理結(jié)果 fs.writeFile("輸出geojson", JSON.stringify(_geojsondata), (err) => { console.log(err); }); });
看完上述內(nèi)容,你們對(duì)如何進(jìn)行g(shù)eojson圖層批量坐標(biāo)轉(zhuǎn)換有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
文章標(biāo)題:如何進(jìn)行g(shù)eojson圖層批量坐標(biāo)轉(zhuǎn)換
當(dāng)前URL:http://muchs.cn/article22/ihehjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、手機(jī)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)