Hi,
I’m struggling with getting some javascript code from turf.js to work in appfarm.
I’m trying to use the turf.booleanPointInPolygon function to identify if a map coordinate is inside or outside a polygon area.
When I’m trying to to run the code below in a run code action node I get this error: TypeError: turf.booleanPointInPolygon is not a function
I have a feeling that I’m missing something - any suggestions?
Setup:
Javascript code:
https://cdn.jsdelivr.net/npm/@turf/turf@6.5.0/turf.min.js
// Example GeoJSON polygon (replace this with your actual GeoJSON)
var geojsonPolygon = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-73.97, 40.77],
[-73.97, 40.78],
[-73.96, 40.78],
[-73.96, 40.77],
[-73.97, 40.77]
]
]
}
};
// Example latitude and longitude point
var point = [ -73.965, 40.775 ]; // [longitude, latitude]
// Check if the point is inside the polygon using turf.booleanPointInPolygon
var isInside = turf.booleanPointInPolygon(point, geojsonPolygon);
// Output the result
if (isInside) {
console.log("The point is inside the polygon.");
} else {
console.log("The point is outside the polygon.");
}