常见gis几何格式(wkt、geojson、arcgis json)的转换方法

1.相关链接

https://github.com/terraformer-js/terraformer

2.arcgis geometry json与geojson互转

Convert ArcGIS JSON geometries to GeoJSON geometries and vice versa.

npm install @terraformer/arcgis

(1)arcgis geometry json转换成geojson格式

import { arcgisToGeoJSON } from "@terraformer/arcgis"

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

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

(2)geojson转换成arcgis geometry json

import { geojsonToArcGIS } from "@terraformer/arcgis"

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

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

3.wkt与geojson格式互转

Tools to convert WKT geometries to GeoJSON geometries and vice versa.

(1)wkt转成geojson

import { wktToGeoJSON } from "@terraformer/wkt"

wktToGeoJSON("POINT (-122.6764 45.5165)");

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

(2)geojson转成wkt

import { geojsonToWKT } from "@terraformer/wkt"

const geojsonPoint = {
  "type": "Point",
  "coordinates": [-122.6764, 45.5165]
}

geojsonToWKT(geojsonPoint)

>> "POINT (-122.6764 45.5165)"