@turf/boolean-contains
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -23,8 +23,8 @@ import calcBbox from "@turf/bbox"; | ||
export default function booleanContains(feature1, feature2) { | ||
var geom1 = getGeom(feature1); | ||
var geom2 = getGeom(feature2); | ||
var type1 = geom1.type; | ||
var type2 = geom2.type; | ||
var coords1 = geom1.coordinates; | ||
var coords2 = geom2.coordinates; | ||
const geom1 = getGeom(feature1); | ||
const geom2 = getGeom(feature2); | ||
const type1 = geom1.type; | ||
const type2 = geom2.type; | ||
const coords1 = geom1.coordinates; | ||
const coords2 = geom2.coordinates; | ||
switch (type1) { | ||
@@ -71,2 +71,9 @@ case "Point": | ||
} | ||
case "MultiPolygon": | ||
switch (type2) { | ||
case "Polygon": | ||
return isPolygonInMultiPolygon(geom1, geom2); | ||
default: | ||
throw new Error("feature2 " + type2 + " geometry not supported"); | ||
} | ||
default: | ||
@@ -76,5 +83,8 @@ throw new Error("feature1 " + type1 + " geometry not supported"); | ||
} | ||
export function isPolygonInMultiPolygon(multiPolygon, polygon) { | ||
return multiPolygon.coordinates.some((coords) => isPolyInPoly({ type: "Polygon", coordinates: coords }, polygon)); | ||
} | ||
export function isPointInMultiPoint(multiPoint, pt) { | ||
var i; | ||
var output = false; | ||
let i; | ||
let output = false; | ||
for (i = 0; i < multiPoint.coordinates.length; i++) { | ||
@@ -89,7 +99,5 @@ if (compareCoords(multiPoint.coordinates[i], pt.coordinates)) { | ||
export function isMultiPointInMultiPoint(multiPoint1, multiPoint2) { | ||
for (var _i = 0, _a = multiPoint2.coordinates; _i < _a.length; _i++) { | ||
var coord2 = _a[_i]; | ||
var matchFound = false; | ||
for (var _b = 0, _c = multiPoint1.coordinates; _b < _c.length; _b++) { | ||
var coord1 = _c[_b]; | ||
for (const coord2 of multiPoint2.coordinates) { | ||
let matchFound = false; | ||
for (const coord1 of multiPoint1.coordinates) { | ||
if (compareCoords(coord2, coord1)) { | ||
@@ -107,5 +115,4 @@ matchFound = true; | ||
export function isMultiPointOnLine(lineString, multiPoint) { | ||
var haveFoundInteriorPoint = false; | ||
for (var _i = 0, _a = multiPoint.coordinates; _i < _a.length; _i++) { | ||
var coord = _a[_i]; | ||
let haveFoundInteriorPoint = false; | ||
for (const coord of multiPoint.coordinates) { | ||
if (isPointOnLine(coord, lineString, { ignoreEndVertices: true })) { | ||
@@ -124,4 +131,3 @@ haveFoundInteriorPoint = true; | ||
export function isMultiPointInPoly(polygon, multiPoint) { | ||
for (var _i = 0, _a = multiPoint.coordinates; _i < _a.length; _i++) { | ||
var coord = _a[_i]; | ||
for (const coord of multiPoint.coordinates) { | ||
if (!booleanPointInPolygon(coord, polygon, { ignoreBoundary: true })) { | ||
@@ -134,5 +140,4 @@ return false; | ||
export function isLineOnLine(lineString1, lineString2) { | ||
var haveFoundInteriorPoint = false; | ||
for (var _i = 0, _a = lineString2.coordinates; _i < _a.length; _i++) { | ||
var coords = _a[_i]; | ||
let haveFoundInteriorPoint = false; | ||
for (const coords of lineString2.coordinates) { | ||
if (isPointOnLine({ type: "Point", coordinates: coords }, lineString1, { | ||
@@ -152,6 +157,6 @@ ignoreEndVertices: true, | ||
export function isLineInPoly(polygon, linestring) { | ||
var output = false; | ||
var i = 0; | ||
var polyBbox = calcBbox(polygon); | ||
var lineBbox = calcBbox(linestring); | ||
let output = false; | ||
let i = 0; | ||
const polyBbox = calcBbox(polygon); | ||
const lineBbox = calcBbox(linestring); | ||
if (!doBBoxOverlap(polyBbox, lineBbox)) { | ||
@@ -161,3 +166,3 @@ return false; | ||
for (i; i < linestring.coordinates.length - 1; i++) { | ||
var midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]); | ||
const midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]); | ||
if (booleanPointInPolygon({ type: "Point", coordinates: midPoint }, polygon, { | ||
@@ -189,12 +194,10 @@ ignoreBoundary: true, | ||
} | ||
var poly1Bbox = calcBbox(feature1); | ||
var poly2Bbox = calcBbox(feature2); | ||
const poly1Bbox = calcBbox(feature1); | ||
const poly2Bbox = calcBbox(feature2); | ||
if (!doBBoxOverlap(poly1Bbox, poly2Bbox)) { | ||
return false; | ||
} | ||
var coords = getGeom(feature2).coordinates; | ||
for (var _i = 0, coords_1 = coords; _i < coords_1.length; _i++) { | ||
var ring = coords_1[_i]; | ||
for (var _a = 0, ring_1 = ring; _a < ring_1.length; _a++) { | ||
var coord = ring_1[_a]; | ||
const coords = getGeom(feature2).coordinates; | ||
for (const ring of coords) { | ||
for (const coord of ring) { | ||
if (!booleanPointInPolygon(coord, feature1)) { | ||
@@ -201,0 +204,0 @@ return false; |
@@ -1,2 +0,2 @@ | ||
import { BBox, Feature, Geometry, LineString, MultiPoint, Point, Polygon } from "@turf/helpers"; | ||
import { BBox, Feature, Geometry, LineString, MultiPoint, MultiPolygon, Point, Polygon } from "geojson"; | ||
/** | ||
@@ -20,2 +20,3 @@ * Boolean-contains returns True if the second geometry is completely contained by the first geometry. | ||
export default function booleanContains(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean; | ||
export declare function isPolygonInMultiPolygon(multiPolygon: MultiPolygon, polygon: Polygon): boolean; | ||
export declare function isPointInMultiPoint(multiPoint: MultiPoint, pt: Point): boolean; | ||
@@ -22,0 +23,0 @@ export declare function isMultiPointInMultiPoint(multiPoint1: MultiPoint, multiPoint2: MultiPoint): boolean; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var bbox_1 = __importDefault(require("@turf/bbox")); | ||
var boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon")); | ||
var boolean_point_on_line_1 = __importDefault(require("@turf/boolean-point-on-line")); | ||
var invariant_1 = require("@turf/invariant"); | ||
const tslib_1 = require("tslib"); | ||
const bbox_1 = tslib_1.__importDefault(require("@turf/bbox")); | ||
const boolean_point_in_polygon_1 = tslib_1.__importDefault(require("@turf/boolean-point-in-polygon")); | ||
const boolean_point_on_line_1 = tslib_1.__importDefault(require("@turf/boolean-point-on-line")); | ||
const invariant_1 = require("@turf/invariant"); | ||
/** | ||
@@ -28,8 +26,8 @@ * Boolean-contains returns True if the second geometry is completely contained by the first geometry. | ||
function booleanContains(feature1, feature2) { | ||
var geom1 = invariant_1.getGeom(feature1); | ||
var geom2 = invariant_1.getGeom(feature2); | ||
var type1 = geom1.type; | ||
var type2 = geom2.type; | ||
var coords1 = geom1.coordinates; | ||
var coords2 = geom2.coordinates; | ||
const geom1 = invariant_1.getGeom(feature1); | ||
const geom2 = invariant_1.getGeom(feature2); | ||
const type1 = geom1.type; | ||
const type2 = geom2.type; | ||
const coords1 = geom1.coordinates; | ||
const coords2 = geom2.coordinates; | ||
switch (type1) { | ||
@@ -76,2 +74,9 @@ case "Point": | ||
} | ||
case "MultiPolygon": | ||
switch (type2) { | ||
case "Polygon": | ||
return isPolygonInMultiPolygon(geom1, geom2); | ||
default: | ||
throw new Error("feature2 " + type2 + " geometry not supported"); | ||
} | ||
default: | ||
@@ -82,5 +87,9 @@ throw new Error("feature1 " + type1 + " geometry not supported"); | ||
exports.default = booleanContains; | ||
function isPolygonInMultiPolygon(multiPolygon, polygon) { | ||
return multiPolygon.coordinates.some((coords) => isPolyInPoly({ type: "Polygon", coordinates: coords }, polygon)); | ||
} | ||
exports.isPolygonInMultiPolygon = isPolygonInMultiPolygon; | ||
function isPointInMultiPoint(multiPoint, pt) { | ||
var i; | ||
var output = false; | ||
let i; | ||
let output = false; | ||
for (i = 0; i < multiPoint.coordinates.length; i++) { | ||
@@ -96,7 +105,5 @@ if (compareCoords(multiPoint.coordinates[i], pt.coordinates)) { | ||
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) { | ||
for (var _i = 0, _a = multiPoint2.coordinates; _i < _a.length; _i++) { | ||
var coord2 = _a[_i]; | ||
var matchFound = false; | ||
for (var _b = 0, _c = multiPoint1.coordinates; _b < _c.length; _b++) { | ||
var coord1 = _c[_b]; | ||
for (const coord2 of multiPoint2.coordinates) { | ||
let matchFound = false; | ||
for (const coord1 of multiPoint1.coordinates) { | ||
if (compareCoords(coord2, coord1)) { | ||
@@ -115,5 +122,4 @@ matchFound = true; | ||
function isMultiPointOnLine(lineString, multiPoint) { | ||
var haveFoundInteriorPoint = false; | ||
for (var _i = 0, _a = multiPoint.coordinates; _i < _a.length; _i++) { | ||
var coord = _a[_i]; | ||
let haveFoundInteriorPoint = false; | ||
for (const coord of multiPoint.coordinates) { | ||
if (boolean_point_on_line_1.default(coord, lineString, { ignoreEndVertices: true })) { | ||
@@ -133,4 +139,3 @@ haveFoundInteriorPoint = true; | ||
function isMultiPointInPoly(polygon, multiPoint) { | ||
for (var _i = 0, _a = multiPoint.coordinates; _i < _a.length; _i++) { | ||
var coord = _a[_i]; | ||
for (const coord of multiPoint.coordinates) { | ||
if (!boolean_point_in_polygon_1.default(coord, polygon, { ignoreBoundary: true })) { | ||
@@ -144,5 +149,4 @@ return false; | ||
function isLineOnLine(lineString1, lineString2) { | ||
var haveFoundInteriorPoint = false; | ||
for (var _i = 0, _a = lineString2.coordinates; _i < _a.length; _i++) { | ||
var coords = _a[_i]; | ||
let haveFoundInteriorPoint = false; | ||
for (const coords of lineString2.coordinates) { | ||
if (boolean_point_on_line_1.default({ type: "Point", coordinates: coords }, lineString1, { | ||
@@ -163,6 +167,6 @@ ignoreEndVertices: true, | ||
function isLineInPoly(polygon, linestring) { | ||
var output = false; | ||
var i = 0; | ||
var polyBbox = bbox_1.default(polygon); | ||
var lineBbox = bbox_1.default(linestring); | ||
let output = false; | ||
let i = 0; | ||
const polyBbox = bbox_1.default(polygon); | ||
const lineBbox = bbox_1.default(linestring); | ||
if (!doBBoxOverlap(polyBbox, lineBbox)) { | ||
@@ -172,3 +176,3 @@ return false; | ||
for (i; i < linestring.coordinates.length - 1; i++) { | ||
var midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]); | ||
const midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]); | ||
if (boolean_point_in_polygon_1.default({ type: "Point", coordinates: midPoint }, polygon, { | ||
@@ -201,12 +205,10 @@ ignoreBoundary: true, | ||
} | ||
var poly1Bbox = bbox_1.default(feature1); | ||
var poly2Bbox = bbox_1.default(feature2); | ||
const poly1Bbox = bbox_1.default(feature1); | ||
const poly2Bbox = bbox_1.default(feature2); | ||
if (!doBBoxOverlap(poly1Bbox, poly2Bbox)) { | ||
return false; | ||
} | ||
var coords = invariant_1.getGeom(feature2).coordinates; | ||
for (var _i = 0, coords_1 = coords; _i < coords_1.length; _i++) { | ||
var ring = coords_1[_i]; | ||
for (var _a = 0, ring_1 = ring; _a < ring_1.length; _a++) { | ||
var coord = ring_1[_a]; | ||
const coords = invariant_1.getGeom(feature2).coordinates; | ||
for (const ring of coords) { | ||
for (const coord of ring) { | ||
if (!boolean_point_in_polygon_1.default(coord, feature1)) { | ||
@@ -213,0 +215,0 @@ return false; |
{ | ||
"name": "@turf/boolean-contains", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf boolean-contains module", | ||
@@ -66,9 +66,10 @@ "author": "Turf Authors", | ||
"dependencies": { | ||
"@turf/bbox": "^6.5.0", | ||
"@turf/boolean-point-in-polygon": "^6.5.0", | ||
"@turf/boolean-point-on-line": "^6.5.0", | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/invariant": "^6.5.0" | ||
"@turf/bbox": "^7.0.0-alpha.0", | ||
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.0", | ||
"@turf/boolean-point-on-line": "^7.0.0-alpha.0", | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/invariant": "^7.0.0-alpha.0", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -12,8 +12,8 @@ # @turf/boolean-contains | ||
**Parameters** | ||
### Parameters | ||
- `feature1` **([Geometry][1] \| [Feature][2]<any>)** GeoJSON Feature or Geometry | ||
- `feature2` **([Geometry][1] \| [Feature][2]<any>)** GeoJSON Feature or Geometry | ||
* `feature1` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry | ||
* `feature2` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry | ||
**Examples** | ||
### Examples | ||
@@ -20,0 +20,0 @@ ```javascript |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23496
518
6
1
+ Addedtslib@^2.3.0
+ Added@turf/bbox@7.1.0(transitive)
+ Added@turf/boolean-point-in-polygon@7.1.0(transitive)
+ Added@turf/boolean-point-on-line@7.1.0(transitive)
+ Added@turf/helpers@7.1.0(transitive)
+ Added@turf/invariant@7.1.0(transitive)
+ Added@turf/meta@7.1.0(transitive)
+ Added@types/geojson@7946.0.14(transitive)
+ Addedpoint-in-polygon-hao@1.1.0(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/bbox@6.5.0(transitive)
- Removed@turf/boolean-point-in-polygon@6.5.0(transitive)
- Removed@turf/boolean-point-on-line@6.5.0(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
- Removed@turf/meta@6.5.0(transitive)
Updated@turf/bbox@^7.0.0-alpha.0
Updated@turf/helpers@^7.0.0-alpha.0