| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
- var _booleanpointonline = require('@turf/boolean-point-on-line');
- var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
- var _invariant = require('@turf/invariant');
- function booleanTouches(feature1, feature2) {
- var geom1 = _invariant.getGeom.call(void 0, feature1);
- var geom2 = _invariant.getGeom.call(void 0, feature2);
- var type1 = geom1.type;
- var type2 = geom2.type;
- switch (type1) {
- case "Point":
- switch (type2) {
- case "LineString":
- return isPointOnLineEnd(geom1, geom2);
- case "MultiLineString":
- var foundTouchingPoint = false;
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (isPointOnLineEnd(geom1, {
- type: "LineString",
- coordinates: geom2.coordinates[ii]
- }))
- foundTouchingPoint = true;
- }
- return foundTouchingPoint;
- case "Polygon":
- for (var i = 0; i < geom2.coordinates.length; i++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0, geom1, {
- type: "LineString",
- coordinates: geom2.coordinates[i]
- }))
- return true;
- }
- return false;
- case "MultiPolygon":
- for (var i = 0; i < geom2.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates[i].length; ii++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0, geom1, {
- type: "LineString",
- coordinates: geom2.coordinates[i][ii]
- }))
- return true;
- }
- }
- return false;
- default:
- throw new Error("feature2 " + type2 + " geometry not supported");
- }
- case "MultiPoint":
- switch (type2) {
- case "LineString":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (!foundTouchingPoint) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom1.coordinates[i] },
- geom2
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- geom2,
- { ignoreEndVertices: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "MultiLineString":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom1.coordinates[i] },
- { type: "LineString", coordinates: geom2.coordinates[ii] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- { type: "LineString", coordinates: geom2.coordinates[ii] },
- { ignoreEndVertices: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "Polygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- { type: "LineString", coordinates: geom2.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- geom2,
- { ignoreBoundary: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "MultiPolygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- {
- type: "LineString",
- coordinates: geom2.coordinates[ii][0]
- }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- { type: "Polygon", coordinates: geom2.coordinates[ii] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- default:
- throw new Error("feature2 " + type2 + " geometry not supported");
- }
- case "LineString":
- switch (type2) {
- case "Point":
- return isPointOnLineEnd(geom2, geom1);
- case "MultiPoint":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom2.coordinates.length; i++) {
- if (!foundTouchingPoint) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom2.coordinates[i] },
- geom1
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i] },
- geom1,
- { ignoreEndVertices: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "LineString":
- var endMatch = false;
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom1.coordinates[0] },
- geom2
- ))
- endMatch = true;
- if (isPointOnLineEnd(
- {
- type: "Point",
- coordinates: geom1.coordinates[geom1.coordinates.length - 1]
- },
- geom2
- ))
- endMatch = true;
- if (endMatch === false) return false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- geom2,
- { ignoreEndVertices: true }
- ))
- return false;
- }
- return endMatch;
- case "MultiLineString":
- var endMatch = false;
- for (var i = 0; i < geom2.coordinates.length; i++) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom1.coordinates[0] },
- { type: "LineString", coordinates: geom2.coordinates[i] }
- ))
- endMatch = true;
- if (isPointOnLineEnd(
- {
- type: "Point",
- coordinates: geom1.coordinates[geom1.coordinates.length - 1]
- },
- { type: "LineString", coordinates: geom2.coordinates[i] }
- ))
- endMatch = true;
- for (var ii = 0; ii < geom1.coordinates[i].length; ii++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[ii] },
- { type: "LineString", coordinates: geom2.coordinates[i] },
- { ignoreEndVertices: true }
- ))
- return false;
- }
- }
- return endMatch;
- case "Polygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- { type: "LineString", coordinates: geom2.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- geom2,
- { ignoreBoundary: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "MultiPolygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- {
- type: "LineString",
- coordinates: geom2.coordinates[ii][0]
- }
- ))
- foundTouchingPoint = true;
- }
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i] },
- geom2,
- { ignoreBoundary: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- default:
- throw new Error("feature2 " + type2 + " geometry not supported");
- }
- case "MultiLineString":
- switch (type2) {
- case "Point":
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (isPointOnLineEnd(geom2, {
- type: "LineString",
- coordinates: geom1.coordinates[i]
- }))
- return true;
- }
- return false;
- case "MultiPoint":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "LineString", coordinates: geom1.coordinates[ii] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "LineString", coordinates: geom1.coordinates[ii] },
- { ignoreEndVertices: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "LineString":
- var endMatch = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom1.coordinates[i][0] },
- geom2
- ))
- endMatch = true;
- if (isPointOnLineEnd(
- {
- type: "Point",
- coordinates: geom1.coordinates[i][geom1.coordinates[i].length - 1]
- },
- geom2
- ))
- endMatch = true;
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "LineString", coordinates: geom1.coordinates[i] },
- { ignoreEndVertices: true }
- ))
- return false;
- }
- }
- return endMatch;
- case "MultiLineString":
- var endMatch = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (isPointOnLineEnd(
- { type: "Point", coordinates: geom1.coordinates[i][0] },
- { type: "LineString", coordinates: geom2.coordinates[ii] }
- ))
- endMatch = true;
- if (isPointOnLineEnd(
- {
- type: "Point",
- coordinates: geom1.coordinates[i][geom1.coordinates[i].length - 1]
- },
- { type: "LineString", coordinates: geom2.coordinates[ii] }
- ))
- endMatch = true;
- for (var iii = 0; iii < geom1.coordinates[i].length; iii++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i][iii] },
- { type: "LineString", coordinates: geom2.coordinates[ii] },
- { ignoreEndVertices: true }
- ))
- return false;
- }
- }
- }
- return endMatch;
- case "Polygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom1.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i][ii] },
- { type: "LineString", coordinates: geom2.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[i][ii] },
- geom2,
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "MultiPolygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom2.coordinates[0].length; i++) {
- for (var ii = 0; ii < geom1.coordinates.length; ii++) {
- for (var iii = 0; iii < geom1.coordinates[ii].length; iii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- {
- type: "Point",
- coordinates: geom1.coordinates[ii][iii]
- },
- {
- type: "LineString",
- coordinates: geom2.coordinates[0][i]
- }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[ii][iii] },
- { type: "Polygon", coordinates: [geom2.coordinates[0][i]] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- }
- return foundTouchingPoint;
- default:
- throw new Error("feature2 " + type2 + " geometry not supported");
- }
- case "Polygon":
- switch (type2) {
- case "Point":
- for (var i = 0; i < geom1.coordinates.length; i++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0, geom2, {
- type: "LineString",
- coordinates: geom1.coordinates[i]
- }))
- return true;
- }
- return false;
- case "MultiPoint":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom2.coordinates.length; i++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i] },
- { type: "LineString", coordinates: geom1.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i] },
- geom1,
- { ignoreBoundary: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "LineString":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom2.coordinates.length; i++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i] },
- { type: "LineString", coordinates: geom1.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i] },
- geom1,
- { ignoreBoundary: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "MultiLineString":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom2.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates[i].length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i][ii] },
- { type: "LineString", coordinates: geom1.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[i][ii] },
- geom1,
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "Polygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates[0].length; i++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[0][i] },
- { type: "LineString", coordinates: geom2.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[0][i] },
- geom2,
- { ignoreBoundary: true }
- ))
- return false;
- }
- return foundTouchingPoint;
- case "MultiPolygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom2.coordinates[0].length; i++) {
- for (var ii = 0; ii < geom1.coordinates[0].length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[0][ii] },
- { type: "LineString", coordinates: geom2.coordinates[0][i] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[0][ii] },
- { type: "Polygon", coordinates: geom2.coordinates[0][i] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- default:
- throw new Error("feature2 " + type2 + " geometry not supported");
- }
- case "MultiPolygon":
- switch (type2) {
- case "Point":
- for (var i = 0; i < geom1.coordinates[0].length; i++) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0, geom2, {
- type: "LineString",
- coordinates: geom1.coordinates[0][i]
- }))
- return true;
- }
- return false;
- case "MultiPoint":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates[0].length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "LineString", coordinates: geom1.coordinates[0][i] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "Polygon", coordinates: geom1.coordinates[0][i] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "LineString":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates[0].length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "LineString", coordinates: geom1.coordinates[0][i] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii] },
- { type: "Polygon", coordinates: geom1.coordinates[0][i] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "MultiLineString":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates.length; i++) {
- for (var ii = 0; ii < geom2.coordinates.length; ii++) {
- for (var iii = 0; iii < geom2.coordinates[ii].length; iii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- {
- type: "Point",
- coordinates: geom2.coordinates[ii][iii]
- },
- {
- type: "LineString",
- coordinates: geom1.coordinates[i][0]
- }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom2.coordinates[ii][iii] },
- { type: "Polygon", coordinates: [geom1.coordinates[i][0]] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- }
- return foundTouchingPoint;
- case "Polygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates[0].length; i++) {
- for (var ii = 0; ii < geom1.coordinates[0][i].length; ii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[0][i][ii] },
- { type: "LineString", coordinates: geom2.coordinates[0] }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- { type: "Point", coordinates: geom1.coordinates[0][i][ii] },
- geom2,
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- return foundTouchingPoint;
- case "MultiPolygon":
- var foundTouchingPoint = false;
- for (var i = 0; i < geom1.coordinates[0].length; i++) {
- for (var ii = 0; ii < geom2.coordinates[0].length; ii++) {
- for (var iii = 0; iii < geom1.coordinates[0].length; iii++) {
- if (!foundTouchingPoint) {
- if (_booleanpointonline.booleanPointOnLine.call(void 0,
- {
- type: "Point",
- coordinates: geom1.coordinates[0][i][iii]
- },
- {
- type: "LineString",
- coordinates: geom2.coordinates[0][ii]
- }
- ))
- foundTouchingPoint = true;
- }
- if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0,
- {
- type: "Point",
- coordinates: geom1.coordinates[0][i][iii]
- },
- { type: "Polygon", coordinates: geom2.coordinates[0][ii] },
- { ignoreBoundary: true }
- ))
- return false;
- }
- }
- }
- return foundTouchingPoint;
- default:
- throw new Error("feature2 " + type2 + " geometry not supported");
- }
- default:
- throw new Error("feature1 " + type1 + " geometry not supported");
- }
- }
- function isPointOnLineEnd(point, line) {
- if (compareCoords(line.coordinates[0], point.coordinates)) return true;
- if (compareCoords(
- line.coordinates[line.coordinates.length - 1],
- point.coordinates
- ))
- return true;
- return false;
- }
- function compareCoords(pair1, pair2) {
- return pair1[0] === pair2[0] && pair1[1] === pair2[1];
- }
- var turf_boolean_touches_default = booleanTouches;
- exports.booleanTouches = booleanTouches; exports.default = turf_boolean_touches_default;
- //# sourceMappingURL=index.cjs.map
|