How to use @turf/boolean-point-in-polygon - 10 common examples

To help you get started, we’ve selected a few @turf/boolean-point-in-polygon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terascope / teraslice / packages / xlucene-evaluator / src / parser / functions / geo / helpers.ts View on Github external
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);
    };
}
github evansiroky / node-geo-tz / lib / find.js View on Github external
// analyze result of current depth
    if (!curTzData) {
      // no timezone in this quad, therefore must be timezone at sea
      return getTimezoneAtSea(originalLon)
    } else if (curTzData === 'f') {
      // get exact boundaries
      var geoJson = featureCache.get(quadPos)
      if (!geoJson) {
        geoJson = loadFeatures(quadPos)
        featureCache.put(quadPos, geoJson)
      }

      var timezonesContainingPoint = []

      for (var i = 0; i < geoJson.features.length; i++) {
        if (inside(pt, geoJson.features[i])) {
          timezonesContainingPoint.push(geoJson.features[i].properties.tzid)
        }
      }

      // if at least one timezone contained the point, return those timezones,
      // otherwise must be timezone at sea
      return timezonesContainingPoint.length > 0
        ? timezonesContainingPoint
        : getTimezoneAtSea(originalLon)
    } else if (curTzData.length > 0) {
      // exact match found
      return curTzData.map(idx => tzData.timezones[idx])
    } else if (typeof curTzData !== 'object') {
      // not another nested quad index, throw error
      err = new Error('Unexpected data type')
      throw err
github ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'LineString') {
          var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
            if (distance < closestDistance) {
              closest = row;
              closestDistance = distance;
            }
          }
        }
      }
      closest.values.name.should.be.equal('point');
      foundFeatures.should.be.deep.equal(['box1', 'box2', 'line', 'point']);
github ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'LineString') {
          var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
            if (distance < closestDistance) {
              closest = row;
              closestDistance = distance;
            }
          }
        }
      }
      closest.properties.Name.should.be.equal('Rio Grande');
    });
github noncomputable / AgentMaps / src / agents.js View on Github external
return;
	}
	
	let goal_layer = this.agentmap.units.getLayer(goal_place.id) || this.agentmap.streets.getLayer(goal_place.id);
	
	//If the goal isn't unanchored, see if it's a street or a unit and schedule the agent appropriately.
	if (goal_layer) {
		let goal_coords = L.A.pointToCoordinateArray(goal_lat_lng);
		
		//Buffering so that points on the perimeter, like the door, are captured. 
		//Also expands street lines into thin polygons (booleanPointInPolygon requires polys).
		//Might be more efficient to generate the door so that it's slightly inside the area.
		let goal_polygon = buffer(goal_layer.toGeoJSON(), .001);
		
		if (booleanPointInPolygon(goal_coords, goal_polygon)) {
			if (start_place.type === "unit" && goal_place.type === "unit" && start_place.id === goal_place.id) {
				this.setTravelInUnit(goal_lat_lng, goal_place, speed);
				return;
			}
			//Move to the street if it's starting at a unit and its goal is elsewhere.
			else if (start_place.type === "unit") {
				let start_unit_door = this.agentmap.getUnitDoor(start_place.id);
				start_unit_door.new_place = start_place,
				start_unit_door.speed = speed;
				this.trip.path.push(start_unit_door);	
				
				let start_unit_street_id = this.agentmap.units.getLayer(start_place.id).street_id,
				start_unit_street_point = this.agentmap.getStreetNearDoor(start_place.id);
				start_unit_street_point.new_place = { type: "street", id: start_unit_street_id },
				start_unit_street_point.speed = speed;
				this.trip.path.push(start_unit_street_point);
github terascope / teraslice / packages / xlucene-evaluator / src / document-matcher / logic-builder / geo.ts View on Github external
const testGeoPolygon = (polygon: any) => (fieldData: string) => {
    const point = parseGeoPoint(fieldData, false);
    if (!point) return false;
    return pointInPolygon([point.lon, point.lat], polygon);
};
github Turfjs / turf / packages / turf-unkink-polygon / lib / simplepolygon.js View on Github external
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;
            }
        }
    }
github Turfjs / turf / packages / turf-boolean-disjoint / index.ts View on Github external
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;
}
github Turfjs / turf / packages / turf-boolean-within / index.ts View on Github external
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;
}
github Turfjs / turf / packages / turf-boolean-crosses / index.ts View on Github external
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;
}

@turf/boolean-point-in-polygon

turf boolean-point-in-polygon module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/boolean-point-in-polygon functions