geojson介绍和常用转换编辑工具
GeoJSON是一种基于JSON的地理空间数据交换格式,它定义了几种类型JSON对象以及它们组合在一起的方法,以表示有关地理要素、属性和它们的空间范围的数据。
2015年,互联网工程任务组(IETF)与原始规范作者组建了一个GeoJSON工作组,一起规范GeoJSON标准。在2016年8月,推出了最新的GeoJSON数据格式标准规范RFC 7946。
GeoJSON使用唯一地理坐标参考系统WGS1984和十进制度单位,一个GeoJSON对象可以是Geometry, Feature或者FeatureCollection。
其几何对象包括有点(表示地理位置)、线(表示街道、公路、边界)、多边形(表示国家、省、领土),以及由以上类型组合成的复合几何图形。
注意:leaflet的polygon坐标是[lat,lon],GEOJSON是[lon,lat],这2个是反的
点对象:
function g(feature, layer) { // does this feature have a property named popupContent? if (feature.properties && feature.properties.popupContent) { layer.bindPopup(feature.properties.popupContent); } } var geojsonFeature = { "type": "Feature", "properties": { "name": "Coors Field", "amenity": "Baseball Stadium", "popupContent": "This is where the Rockies play!" }, "geometry": { "type": "Point", "coordinates": [100, 31] } }; L.geoJSON(geojsonFeature, { onEachFeature: g }).addTo(map);
线要素:
var draw_line = { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [ [110, 11], [110, 49] ] }, "properties": { "popupContent": "This is a free bus line that will take you across downtown.", "underConstruction": true }, "id": 2 }; //绑定事件 function f(feature, layer) { layer.bindPopup(feature.properties.popupContent); } //增加到地图 var ss = L.geoJson(draw_line, { style: { "color": 'black', "weight": 1 }, onEachFeature: f }).addTo(map);
多边形(Polygon)
var states = [{ "type": "Feature", "properties": {"party": "Republican"}, "geometry": { "type": "Polygon", "coordinates": [[ [-104.05, 48.99], [-97.22, 48.98], [-96.58, 45.94], [-104.03, 45.94], [-104.05, 48.99] ]] } }, { "type": "Feature", "properties": {"party": "Democrat"}, "geometry": { "type": "Polygon", "coordinates": [[ [-109.05, 41.00], [-102.06, 40.99], [-102.03, 36.99], [-109.04, 36.99], [-109.05, 41.00] ]] } }]; L.geoJSON(states, { style: function(feature) { switch (feature.properties.party) { case 'Republican': return {color: "#ff0000"}; case 'Democrat': return {color: "#0000ff"}; } } }).addTo(map);
下面介绍几个geojson转换和处理工具:
1、格式转换处理工具:https://mapshaper.org/
2、geojson编辑工具(国内需要FQ):http://geojson.io/
3、省市边界下载:http://datav.aliyun.com/portal/school/atlas/area_selector
4、省市边界下载:https://hxkj.vip/demo/echartsMap/
5、json数据编辑器:http://www.bejson.com/jsoneditoronline/