GeoJSON简介

GeoJSON是一种用JSON格式表示地理空间数据的标准(RFC 7946),前端地图(如Leaflet、Mapbox)经常用它传递点、线、面等几何信息。


名词解释:

**RFC 7946:**GeoJSON 地理数据格式的官方国际标准,2016年发布,取代了08年发布的旧标准。

Leaflet: 是一个开源并且对移动端友好的交互式地图 JavaScript 库。 它大小仅仅只有 42 KB of JS, 并且拥有绝大部分开发者所需要的所有地图特性 ,官网:Leaflet - 一个交互式地图 JavaScript 库 (leafletjs.cn)

Mapbox: 是全球领先的地图技术服务平台‌,提供定制化地图、导航、搜索及位置数据解决方案,官网在这,有兴趣的自己看:www.mapbox.com


数据类型:

GeoJSON的基本结构如下:

java 复制代码
{
  "type": "几何类型",
  "coordinates": [坐标数据]
}

其中type有七种类型,分别是Point(点)、MultiPoint(多点)、LineString(线串)、MultiLineString(多线串)、Polygon(多边形)、MultiPolygon(多多边形)、GeometryCollection(几何集合)


数据示例:

1. Point(点)

java 复制代码
{
	"type": "Point",
	"coordinates": [113.324568, 23.106682]
}

2. MultiPoint(多点)

javascript 复制代码
{
	"type": "MultiPoint",
	"coordinates": [
		[113.32, 23.10],
		[113.33, 23.11],
		[113.34, 23.12]
	]
}

3. LineString(线串)

javascript 复制代码
{
	"type": "LineString",
	"coordinates": [
		[113.1, 23.0],
		[113.2, 23.1],
		[113.3, 23.2]
	]
}

4. MultiLineString(多线串)

java 复制代码
{
  "type": "MultiLineString",
  "coordinates": [
    [[113.1,23.0], [113.2,23.1]],
    [[113.3,23.2], [113.4,23.3]]
  ]
}
// 多条独立的路线

5. Polygon(多边形)

java 复制代码
{
	"type": "Polygon",
	"coordinates": [
		[
			[113.2, 23.0],
			[113.4, 23.0],
			[113.4, 23.2],
			[113.2, 23.2],
			[113.2, 23.0]
		]
	]
}
// 第一个数组是外环,后面的数组是内环(洞),首尾坐标必须相同

6. MultiPolygon(多多边形)

java 复制代码
{
	"type": "MultiPolygon",
	"coordinates": [
		[
			[
				[113.2, 23.0],
				[113.3, 23.0],
				[113.3, 23.1],
				[113.2, 23.1],
				[113.2, 23.0]
			]
		],
		[
			[
				[113.4, 23.2],
				[113.5, 23.2],
				[113.5, 23.3],
				[113.4, 23.3],
				[113.4, 23.2]
			]
		]
	]
}
// 多个不相连的面,如广东省各市分开的行政区划

7. GeometryCollection(几何集合)

java 复制代码
{
	"type": "GeometryCollection",
	"geometries": [{
			"type": "Point",
			"coordinates": [113.32, 23.10]
		},
		{
			"type": "LineString",
			"coordinates": [
				[113.1, 23.0],
				[113.2, 23.1]
			]
		}
	]
}
// 混合不同类型,注意这里用 "geometries" 而不是 "coordinates"

注意type 除了上述 7 种几何类型,还有两种顶层类型用于包裹:

java 复制代码
// Feature:一个几何 + 它的属性
{
	"type": "Feature",
	"geometry": { ...
	},
	"properties": {
		"name": "广州塔"
	}
}

// FeatureCollection:多个 Feature 的集合(最常见的前端传参格式)
{
	"type": "FeatureCollection",
	"features": [{ ...
	}, { ...
	}]
}

//示例数据:
//Feature(要素)
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [113.324568, 23.106682]
  },
  "properties": {
    "name": "广州塔",
    "height": 600,
    "buildYear": 2010,
    "category": "地标"
  }
}
//geometry 里放任意几何类型,properties 里放业务属性,可以自定义任意字段。

//FeatureCollection(要素集合)
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [113.324568, 23.106682]
      },
      "properties": {
        "id": "BRIDGE_001",
        "name": "珠江大桥",
        "bridgeType": "梁桥",
        "length": 1200,
        "检测等级": "A"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [113.100, 23.000],
          [113.150, 23.050],
          [113.200, 23.100]
        ]
      },
      "properties": {
        "id": "ROAD_001",
        "name": "G107国道广州段",
        "roadClass": "国道",
        "totalLength": 15000
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [113.20, 23.00],
          [113.40, 23.00],
          [113.40, 23.20],
          [113.20, 23.20],
          [113.20, 23.00]
        ]]
      },
      "properties": {
        "id": "AREA_001",
        "name": "广州市区范围",
        "adminLevel": "市辖区"
      }
    }
  ]
}
相关推荐
西安邮电大学12 分钟前
贪心算法详细讲解
java·后端·其他·算法·面试
慧都小妮子24 分钟前
不想频繁改 PLC?用 DeviceXPlorer Lua 脚本把产线业务逻辑放到 OPC Server 层
java·junit·lua·takebishi·dxpserver·设备数据采集软件·opc server
迦蓝叶35 分钟前
【开源自荐】JAiRouter:一个轻量级 AI 模型服务网关的开源实践
java·人工智能·spring·开源·llm-gateway·mass
swordbob1 小时前
缓存延迟双删的两种策略
java·缓存
凡人叶枫1 小时前
Effective C++ 条款08:别让异常逃离析构函数
java·linux·数据库·c++·嵌入式开发
云烟成雨TD1 小时前
Agent Scope Java 2.x 系列【4】模型层
java·人工智能·agent
云烟成雨TD1 小时前
Agent Scope Java 2.x 系列【5】智能体抽象层
java·人工智能·agent
丷丩1 小时前
MapLibre GL JS第46课:用Markers添加自定义图标
gis·可视化·mapbox·maplibre gl js
阿伟AI说1 小时前
Codex 桌面版接入国产模型系列二:Codex++
java·开源软件·ai编程·腾讯云ai代码助手