在数据可视化中,需要做地图信息可视化时,必须用到geoJSON。目前支持地图数据可视化的JS库比较丰富,现以Highcharts与Echarts两个图表库为例,对比下geoJSON的区别!
geoJSON是什么?
geojson是用json的语法表达和存储地理数据,可以说是json的子集,其格式如下:
{ "type": "FeatureCollection", "features": [ {"type":"Feature", "properties":{}, "geometry":{ "type":"Point", "coordinates":[105.380859375,31.57853542647338] } } ] }
Highcharts与Echarts地图geoJSON区别
在实际的使用过程中,
1.Echarts地图geoJSON代码结构如下格式,没有更多的属性和字段,不能直接应用于Highcharts的Highmaps中;
2.Highmaps的geoJSON代码结构更复杂,内容信息更丰富,但是可以直接应用于Echarts中。
Highcharts地图数据属性
- 国内地图格式:
"features": [ { "type": "Feature", "properties": { "adcode": 440100, "name": "广州", "center": [ 113.280637, 23.125178 ], "childrenNum": 11, "level": "city", "subFeatureIndex": 0, "fullname": "广州市", "filename": "guangzhou", "parent": "广东省", "areacode": 440100, "longitude": 113.280637, "latitude": 23.125178, "cp": [ 6177, 2558 ], "drilldown": "guangdong/guangzhou" },
- 国外地图格式:
Echarts格式基本与国内相同,Highcharts的geoJSON更复杂。
"features": [ { "type": "Feature", "id": "AU.NT", "properties": { "hc-group": "admin1", "hc-middle-x": 0.48, "hc-middle-y": 0.58, "hc-key": "au-nt", "hc-a2": "NT", "labelrank": "2", "hasc": "AU.NT", "alt-name": null, "woe-id": "2344701", "subregion": null, "fips": "AS03", "postal-code": "NT", "name": "Northern Territory", "country": "Australia", "type-en": "Territory", "region": null, "longitude": "133.78", "woe-name": "Northern Territory", "latitude": "-20.1026", "woe-label": "Northern Territory, AU, Australia", "type": "Territory" },
geojson.io的支持
Highcharts 导入后,不能正常显示区域;
Echarts 可正常显示。
如何获取geoJSON
Echarts的国、省、市、区县,网络资源丰富,CSDN下载中心也有;乡镇边界基本是需要付费购买的,直接手绘的精确度不够,也费时费力。
Highcharts国内geojson,省市文件可以直接调用,县级数据需要购买。
Done!