In this paper, based on the Supermap platform, the two-dimensional vector data of 84 to Mars is realized.
Steps:
- Converting data into the geographic coordinate system of wgs84 in iDesktop
- In iDesktop, convert the data to geojson.
Note that the format should be utf-8, otherwise the Chinese field will be garbled.
- Under nodejs, we use projzh package to convert wgs84 coordinates to Mars coordinates.
//index.js file
var projzh = require('projzh'); const fs = require('fs'); function ll2gcj(input) { return projzh.datum.gcj02.fromWGS84(input); } var testpath = './region.txt'; var res = JSON.parse(fs.readFileSync(testpath).toString()); if(res){ for(var i = 0;i<res.features.length;i++){ let feature = res.features[i]; if(feature.geometry.type === 'Polygon'){ for(var j=0;j<feature.geometry.coordinates.length;j++){ for(var k=0;k<feature.geometry.coordinates[j].length;k++){ let lng = feature.geometry.coordinates[j][k][0]; let lat = feature.geometry.coordinates[j][k][1]; var obj = ll2gcj([lng,lat]); feature.geometry.coordinates[j][k][0] = obj[0]; feature.geometry.coordinates[j][k][1] = obj[1]; console.log('i:'+i+';j:'+j+";k:"+k); } } }else if(feature.geometry.type === 'MultiPolygon'){ for(var j=0;j<feature.geometry.coordinates.length;j++){ for(var k=0;k<feature.geometry.coordinates[j].length;k++){ for(var m=0;m<feature.geometry.coordinates[j][k].length;m++){ let lng = feature.geometry.coordinates[j][k][m][0]; let lat = feature.geometry.coordinates[j][k][m][1]; var obj = ll2gcj([lng,lat]); feature.geometry.coordinates[j][k][m][0] = obj[0]; feature.geometry.coordinates[j][k][m][1] = obj[1]; console.log('i:'+i+';j:'+j+";k:"+k+';m:'+m); } } } }else if(feature.geometry.type === 'LineString'){ for(var j=0;j<feature.geometry.coordinates.length;j++){ let lng = feature.geometry.coordinates[j][0]; let lat = feature.geometry.coordinates[j][1]; var obj = ll2gcj([lng,lat]); feature.geometry.coordinates[j][0] = obj[0]; feature.geometry.coordinates[j][1] = obj[1]; console.log('i:'+i+';j:'+j+";k:"+k); } } } // for(var i =0;i<resData.length;i++){ // var item= resData[i]; // var obj = ll2gcj([item.lng,item.lat]); // item.lng = obj[0]; // item.lat = obj[1]; // } console.log('end'); var testpath2 = './regionPolygonGCJ.txt'; fs.writeFileSync(testpath2, JSON.stringify(res)); }First install the node JS environment and run node index.js in the folder where the geojson file is located. (region.txt is the source file, regionPolygonGCJ.txt is the converted file, and currently supports Polygon, MultiPolygon, LineString)
- In iDesktop, import geo JSON format Mars geographic coordinate data.
- In iDesktop, convert the data to the format you want, such as 3857.