Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
geometries.forEach(geometry => {
// Convert the polygon to turf.js/GeoJSON geometry while
// reprojecting them to the internal turf.js projection 'EPSG:4326'.
const turfPolygon = geoJsonFormat.writeGeometryObject(geometry);
const turfPolygonCoordinates = turfPolygon.coordinates;
// outer lines of the given polygon
const outer = lineString(turfPolygonCoordinates[0]);
// polygonized outer polygon
const outerPolygon = lineToPolygon(outer);
// holes in the polygon
const inners = [];
turfPolygonCoordinates.slice(1, turfPolygonCoordinates.length).forEach(function (coord) {
inners.push(lineString(coord));
});
// Polygonize the holes in the polygon
const innerPolygon = polygonize(featureCollection(inners));
// make a lineString from the spliting line and the outer of the polygon
let unionGeom = union(outer, turfLine);
// Polygonize the combined lines.
const polygonizedUnionGeom = polygonize(unionGeom);
// Array of the split polygons within the geometry
const splitedPolygons = [];
// Iterate over each feature in the combined feature and remove sections that are outside the initial polygon and
// remove the parts from the cutted polygons that are in polygon holes.
featureEach(polygonizedUnionGeom, cuttedSection => {
function matcher() {
const polyPoints = points.map((obj) => [obj.lon, obj.lat]);
const line = lineString(polyPoints);
const matcherPolygon = lineToPolygon(line);
// Nothing matches so return false
if (polygon == null) return () => false;
return geoMatcher(matcherPolygon);
}
export function makePolygon(points: GeoPoint[]) {
const polyPoints = points.map(makeCoordinatesFromGeoPoint);
const line = lineString(polyPoints);
return lineToPolygon(line);
}