turf.js로 좌표가 영역 내에 있는지 확인 — GeoJSON 좌표는 [경도, 위도] 순이고, 폴리곤 고리는 첫 점으로 닫는다.1

const turf = require('@turf/turf')

const polygon = turf.polygon([
  [
    [-73.981, 40.768],
    [-73.981, 40.764],
    [-73.975, 40.764],
    [-73.975, 40.768],
    [-73.981, 40.768], // 닫기
  ],
])

const point = turf.point([-73.978, 40.766])

turf.booleanPointInPolygon(point, polygon) // true/false

npm install @turf/turf


Footnotes

  1. RFC 7946 — GeoJSON: “The first two elements are longitude and latitude, or easting and northing, precisely in that order” / §3.1.6: “The first and last positions are equivalent, and they MUST contain identical values” ↩

`#530`