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": "市辖区"
      }
    }
  ]
}
相关推荐
y1su7 分钟前
Leetcode 动态规划 模板
java·数据结构·算法·leetcode·动态规划
Wang's Blog21 分钟前
Java 项目实战: 交友项目 - JWT 概述:为什么要用 Token 换掉 Session
java·ui·交友
SL_staff1 小时前
低代码选型避坑指南:为什么‘能拖拽’不等于‘能交付’?——基于JVS八大引擎的四维交付能力评估框架
java·低代码·spring cloud
李福春1 小时前
技术思考问题6:技术演讲该晒成功架构,还是交代失败与取舍?
java·开发语言·架构·computer use·深圳同盟·腾讯云架构师技术同盟·反演思维
用户7771298509122 小时前
equals和==的区别
java
旋律4142 小时前
对封装、继承、多态三个概念理解
java
code2cat2 小时前
【随笔】LLM裁判如何打分:先写评分标准,再用人工案例校准
java·人工智能·llm·agent·评估·langsmith
SL_staff2 小时前
计息规则不再等IT:JVS-Rules函数计算器在金融计息场景的技术实践
java·git·全栈