Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (fieldData: JoinGeoShape) => {
let polygon: any;
if (isGeoShapePoint(fieldData)) {
return equal(searchPoint, tPoint(fieldData.coordinates));
}
if (isGeoShapeMultiPolygon(fieldData)) {
polygon = multiPolygon(fieldData.coordinates);
}
if (isGeoShapePolygon(fieldData)) {
polygon = tPolygon(fieldData.coordinates);
}
// Nothing matches so return false
if (!polygon) return false;
return pointInPolygon(searchPoint, polygon);
};
}
const testGeoPolygon = (polygon: any) => (fieldData: string) => {
const point = parseGeoPoint(fieldData, false);
if (!point) return false;
return pointInPolygon([point.lon, point.lat], polygon);
};
function determineParents() {
var featuresWithoutParent = [];
for (var i = 0; i < output.features.length; i++) {
if (output.features[i].properties.parent == -1) featuresWithoutParent.push(i);
}
if (featuresWithoutParent.length > 1) {
for (var i = 0; i < featuresWithoutParent.length; i++) {
var parent = -1;
var parentArea = Infinity;
for (var j = 0; j < output.features.length; j++) {
if (featuresWithoutParent[i] == j) continue;
if (booleanPointInPolygon(output.features[featuresWithoutParent[i]].geometry.coordinates[0][0], output.features[j], {ignoreBoundary: true})) {
if (area(output.features[j]) < parentArea) {
parent = j;
}
}
}
output.features[featuresWithoutParent[i]].properties.parent = parent;
}
}
}
function isLineInPoly(polygon: Polygon, lineString: LineString) {
for (const coord of lineString.coordinates) {
if (booleanPointInPolygon(coord, polygon)) {
return true;
}
}
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
if (doLinesIntersect.features.length > 0) {
return true;
}
return false;
}
function isLineInPoly(linestring, polygon) {
var polyBbox = calcBbox(polygon);
var lineBbox = calcBbox(linestring);
if (!doBBoxOverlap(polyBbox, lineBbox)) {
return false;
}
var foundInsidePoint = false;
for (var i = 0; i < linestring.coordinates.length - 1; i++) {
if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
return false;
}
if (!foundInsidePoint) {
foundInsidePoint = booleanPointInPolygon(linestring.coordinates[i], polygon, {ignoreBoundary: true});
}
if (!foundInsidePoint) {
var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {ignoreBoundary: true});
}
}
return foundInsidePoint;
}
function doesMultiPointCrossPoly(multiPoint, polygon) {
var foundIntPoint = false;
var foundExtPoint = false;
var pointLength = multiPoint.coordinates[0].length;
var i = 0;
while (i < pointLength && foundIntPoint && foundExtPoint) {
if (booleanPointInPolygon(point(multiPoint.coordinates[0][i]), polygon)) {
foundIntPoint = true;
} else {
foundExtPoint = true;
}
i++;
}
return foundExtPoint && foundExtPoint;
}
function booleanWithin(feature1: Feature | Geometry, feature2: Feature | Geometry): boolean {
var geom1 = getGeom(feature1);
var geom2 = getGeom(feature2);
var type1 = geom1.type;
var type2 = geom2.type;
switch (type1) {
case 'Point':
switch (type2) {
case 'MultiPoint':
return isPointInMultiPoint(geom1, geom2);
case 'LineString':
return booleanPointOnLine(geom1, geom2, {ignoreEndVertices: true});
case 'Polygon':
case 'MultiPolygon':
return booleanPointInPolygon(geom1, geom2, {ignoreBoundary: true});
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'MultiPoint':
switch (type2) {
case 'MultiPoint':
return isMultiPointInMultiPoint(geom1, geom2);
case 'LineString':
return isMultiPointOnLine(geom1, geom2);
case 'Polygon':
case 'MultiPolygon':
return isMultiPointInPoly(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'LineString':
function isLineInPoly(linestring, polygon) {
var polyBbox = calcBbox(polygon);
var lineBbox = calcBbox(linestring);
if (!doBBoxOverlap(polyBbox, lineBbox)) {
return false;
}
var foundInsidePoint = false;
for (var i = 0; i < linestring.coordinates.length - 1; i++) {
if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
return false;
}
if (!foundInsidePoint) {
foundInsidePoint = booleanPointInPolygon(linestring.coordinates[i], polygon, {ignoreBoundary: true});
}
if (!foundInsidePoint) {
var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {ignoreBoundary: true});
}
}
return foundInsidePoint;
}
return (fieldData: GeoPointInput) => {
const point = parseGeoPoint(fieldData, false);
if (!point) return false;
return pointInPolygon(makeCoordinatesFromGeoPoint(point), polygon);
};
}