1、概念
GeoJSON是⼀种基于JSON(JavaScript Object Notation)格式的地理空间数据交换格式,用于 表示地理空间数据。它将地理空间数据以及相关的⾮空间属性信息(如名称、描述等)进行编码, 并使用JSON格式进行存储和传输。
GeoJSON⽀持多种类型的空间数据对象,包括点、线、面等,还⽀持复合对象,例如⼏何集合 (GeometryCollection)和特征集合(FeatureCollection)等。GeoJSON使用经度和纬度(即坐
标)来表示空间位置,同时也⽀持投影坐标系和地理坐标系。
GeoJSON是⼀种简单、轻量级、易于理解和处理的数据格式,已被⼴泛用于Web GIS应用中,例 如在Leaflet、Mapbox和OpenLayers等地图库中,以及在各种地理信息系统(GIS)应用程序 中。
2、代码示例
{
type:"FeatureCollection",
features:[
{
type:"Feature",
geometry:{
type:"Point",
coordinates:[114.407, 30.4645] },
properties:{
name:"新中地"
}
}
]
}
3、Openlayer中geojson的API
3-1、加载本地数据
var source = new ol.source.Vector({
/* 将geojson数据设置给实例数据源 */
features: new ol.format.GeoJSON().readFeatures(data) })
3-2、网络数据
const source = new ol.source.Vector({
url: 'https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=420100', format: new ol.format.GeoJSON()
})
const layer = new ol.layer.Vector({
source
})
map.addLayer(layer)
免费领取GIS开发相关学习资料