getCoord
函数可以从Turf GeoJSON的几何对象中获取坐标。支持点(Point)类型、多点(MultiPoint)类型、线(LineString)类型、多线(MultiLineString)类型、多边形(Polygon)类型和多多边形(MultiPolygon)类型几何对象。
getCoord(geojson)
geojson
(Feature<Point>|Feature<MultiPoint>|Feature<LineString>|Feature<MultiLineString>|Feature<Polygon>|Feature<MultiPolygon>|Point|MultiPoint|LineString|MultiLineString|Polygon|MultiPolygon) - 输入的Turf GeoJSON几何对象。[number, number]
- 返回该几何对象的一个坐标。如果该几何对象是一个多要素类型,则只返回第一个要素的第一个点的坐标。import { getCoord, point } from '@turf/turf'
const pt = point([10, 20])
const coord = getCoord(pt) // [10, 20]
import { getCoord, polygon } from '@turf/turf'
const poly = polygon([[[0,0], [0,10], [10,10], [10,0], [0,0]]])
const coord = getCoord(poly) // [0, 0]
import { getCoord, multiLineString } from '@turf/turf'
const mls = multiLineString([[[1,1], [10,10]], [[-1,-1], [-10,-10]]])
const coord = getCoord(mls) // [1, 1]
import { getCoord, featureCollection, point, polygon } from '@turf/turf'
const fc = featureCollection([point([1,1]), polygon([[[0,0], [0,10], [10,10], [10,0], [0,0]]])])
const coord = getCoord(fc) // [1, 1]