布尔判断 - Boolean

约 164 字小于 1 分钟

点是否在线上

import * as turf from "@turf/turf"

const point = turf.point([108.230308, 32.159298])

const line = turf.lineString([
                [99.441245, 32.604636],
                [117.195151, 24.429603]
              ])

const isPointOnLine = turf.booleanPointOnLine(point, line) // false

点是否在面上

import * as turf from "@turf/turf"

const point = turf.point([108.230308, 32.159298])

const line = turf.polygon([[
              [93.11312, 38.739052],
              [92.937339, 24.589545],
              [119.128745, 24.269458],
              [121.062339, 44.136851],
              [93.11312, 38.739052],
            ]])

const isPointOnPolygon = turf.booleanPointInPolygon(point, line) // true

是否交叉

import * as turf from "@turf/turf"

const line1 = turf.lineString([[-2, 2], [4, 2]])
const line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]])

const cross = turf.booleanCrosses(line1, line2) // true

是否包含

import * as turf from "@turf/turf"

const line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]])
const point = turf.point([1, 2])

turf.booleanContains(line, point) // true

其他判断

更多判断请看 这里open in new window

上次编辑于: