【WebGIS初学到入职】(14)GeoJSON与EsriJSON的对比与转换

介绍

GeoJSON是一种对各种地理数据结构进行编码的格式,基于JSON的地理空间信息数据交换格式。GeoJSON对象可以表示几何、特征或者特征集合。
GeoJSON支持下面几何类型:点、线、面、多点、多线、多面和几何集合。GeoJSON里的特征包含一个几何对象和其他属性,特征集合表示一系列特征。

Esri JSON是由Esri公司定义的一种GeoJSON格式的扩展,用于表示地理空间要素及其属性信息。与标准的GeoJSON相比,Esri JSON增加了一些属性和元素,以支持Esri ArcGIS产品族的规范。


转换

terraformer/README.md at main · terraformer-js/terraformer · GitHub

npm install @terraformer/arcgis

EsriJSON转GeoJSON

import {
    
     arcgisToGeoJSON } from "@terraformer/arcgis"

arcgisToGeoJSON({
    
    
  "x":-122.6764,
  "y":45.5165,
  "spatialReference": {
    
    
    "wkid": 4326
  }
});

>> {
    
     "type": "Point", "coordinates": [ -122.6764, 45.5165 ] }

GeoJSON转EsriJSON

import {
    
     geojsonToArcGIS } from "@terraformer/arcgis"

geojsonToArcGIS({
    
    
  "type": "Point",
  "coordinates": [45.5165, -122.6764]
})

>> {
    
     "x":-122.6764, "y":45.5165, "spatialReference": {
    
     "wkid": 4326 } }

对比

GeoJSON规范文档:RFC 7946: The GeoJSON Format (rfc-editor.org)
Esri JSON规范文档:Geometry objects—Common Data Types | ArcGIS Developers

要素(Feature)

// GeoJSON
{
    
    
  "type": "Feature",
  "geometry": {
    
    
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    
    
    "name": "Dinagat Islands"
  }
}

// EsriJSON
{
    
    
  "attributes": {
    
    
    "OBJECTID": 1,
    "Name": "Sample",
    "Type": "Building"
  },
  "geometry": {
    
    
    "rings": [[[0,0],[0,10],[10,10],[10,0],[0,0]]],
    "spatialReference": {
    
     "wkid": 4326 }
  }
}

Point(点)

// GeoJSON
"geometry":{
    
    
	"type":"Point",
	"coordinates":[105.380859375,31.57853542647338]
}

// EsriJSON
{
    
    
  "x": -122.690899,
  "y": 45.512296
}

MultiPoint(多点)

// GeoJSON
"geometry":{
    
    
	"type":"MultiPoint",
	"coordinates":[
		[105.380859375,31.57853542647338],
		[105.580859375,31.52853542647338]
	]
}

// EsriJSON
{
    
    
  "points": [[-122.68,45.50],[-122.70,45.52],[-122.68,45.53]],
  "spatialReference": {
    
     "wkid": 4326 }
}

LineString(线)

// GeoJSON - 依次连接点 
"geometry":{
    
    
	"type":"LineString",
	"coordinates":[
		[105.6005859375,30.65681556429287],
		[107.9516601562,31.98944183792288],
		[109.3798828125,30.03105542654020],
		[107.7978515625,29.93589521337244]
	]
}

// EsriJSON
{
    
    
  "paths": [
	  [[0,0],[5,5],[10,10]]
  ],
  "spatialReference": {
    
     "wkid": 4326 }
}

MultiLineString(多线)

// GeoJSON
"geometry":{
    
    
	"type":"MultiLineString",
	"coordinates":
	[
		[
			[105.6005859375,30.65681556429287],
			[107.9516601569,31.98944183792288],
			[109.3798828125,30.03105542654020],
			[107.7978515625,29.93589521332444]
		],
		[
			[109.3798828125,30.03105542654020],
			[107.1978515625,31.23589521337244]
		]
	]
}

// EsriJSON
{
    
    
  "paths": [
	  [[0,0],[5,5],[10,10]],
	  [[15,15],[20,25],[30,30]]
  ],
  "spatialReference": {
    
     "wkid": 4326 }
}

Polygon(面)

// GeoJSON
"geometry":{
    
     
	"type": "Polygon",
	"coordinates": 
	[
		[ 
			[100.0, 0.0], 
			[101.0, 0.0], 
			[101.0, 1.0], 
			[100.0, 1.0], 
			[100.0, 0.0] 
		]
	]
}

// EsriJSON
{
    
    
  "rings": [
	  [[0,0],[0,10],[10,10],[10,0],[0,0]]
  ],
  "spatialReference": {
    
     "wkid": 4326 }
}

MultiPolygon(多面)

// GeoJSON
"geometry": {
    
    
	"type": "MultiPolygon",
	"coordinates":
	[ 
		[
			[
				[109.2041015625,30.088107753367257],
				[115.02685546875,30.088107753367257],
				[115.02685546875,32.7872745269555],
				[109.2041015625,32.7872745269555],
				[109.2041015625,30.088107753367257]
			] 
		],
		[
			[
				[112.9833984375,26.82407078047018],
				[116.69677734375,26.82407078047018],
				[116.69677734375,29.036960648558267],
				[112.9833984375,29.036960648558267],
				[112.9833984375,26.82407078047018]
			]
		]
	]
}


// EsriJSON
(待补充...

参考

  1. 2022-04-18 了解 GeoJSON 格式_不爱吃奶昔的博客-CSDN博客_geojson
  2. GeoJSON详解(带图)PzLu的博客-CSDN博客_geojson
  3. GeoJSON详解_青青子衿~的博客-CSDN博客_geojson
  4. GEOJSON标准格式学习 - 简书 (jianshu.com)

Supongo que te gusta

Origin blog.csdn.net/ReBeX/article/details/130707156
Recomendado
Clasificación