拍卖网站怎么做,网络营销方式变化背后的逻辑与趋势,郑州定制网站开发,小猫济南网站建设公司概述
在浏览百度地图开放平台的时候#xff0c;发现有个资源下载页面#xff0c;里面有个城市中心点位和百度地图行政区划adcode映射表数据#xff0c;这是一个经常使用到的数据#xff0c;本文实现将这个数据转换为geojson#xff0c;并借助QGIS转换为经纬度坐标或火星坐…概述
在浏览百度地图开放平台的时候发现有个资源下载页面里面有个城市中心点位和百度地图行政区划adcode映射表数据这是一个经常使用到的数据本文实现将这个数据转换为geojson并借助QGIS转换为经纬度坐标或火星坐标。
下载并转换
下载下来的数据如下图所示。
将文件后缀改为js文件并添加代码var data 如下图所示。
在html中引入修改后的文件并写转换代码转换代码可如下
script src./data.js/scriptscriptfunction getCenter(str) {const [c, z] str.split(|);return {zoom: parseInt(z),center: c.split(,).map(Number)}}class Geojson {constructor(features [], metaData {}) {this.type FeatureCollectionthis.metadata metaDatathis.features features}}class Geometry {constructor(type, coordinates) {this.type typethis.coordinates coordinates}}const GEOMETRY_TYPE {POINT: Point,LINESTRING: LineString,MULTILINESTRING: MultiLineString,POLYGON: Polygon,MULTIPOLYGON: MultiPolygon}class Feature {constructor(geomType, properties, geometry) {this.type Featurethis.properties propertiesthis.geometry Array.isArray(geometry) ? new Geometry(geomType, geometry) : geometry}}const bb Object.values(data)let res []bb.forEach(b {b.forEach(_b {res.push({ name: _b.n, ...getCenter(_b.g) });const cities _b.cities || [];cities.forEach(c {res.push({ name: c.n, ...getCenter(c.g) })})})});res res.map(({ name, zoom, center }) {return new Feature(GEOMETRY_TYPE.POINT, { name, zoom }, new Geometry(GEOMETRY_TYPE.POINT, center))})console.log(JSON.stringify(new Geojson(res)))
/script控制台输出的即为转换后的geojson如下图。
将数据复制为json文件并在qgis中打开打开后设置标注效果如下
坐标转换
转换后的数据位百度的坐标借助扩展中的geohe工具箱将坐标转换为火星坐标系操作图下图。
转换后的比较结果如下图。