import type { FeatureCollection , Feature , Position , MultiPolygon , Polygon } from 'geojson' ; import { ConvertCoordinates } from './multipolygon/convert.js' ; param features export function toFeatureCollection ( features ) { return { type : 'FeatureCollection' , features , } ; } export function toPolygon ( coordinates ) { return { type : 'Polygon' , coordinates , } ; } /** Create a feature polygon */ export function toFeaturePolygon ( coordinates , properties = { } ) { return { type : 'Feature' , geometry : toPolygon ( coordinates ) , properties , } ; } /**
 * Create a feature mult-polygon
 */ export function toFeatureMultiPolygon ( coordinates , properties = { } ) { return { type : 'Feature' , geometry : { type : 'MultiPolygon' , coordinates , } , properties , } ; } /**
 * Make a copy of point `p`
 */ export const copyPoint = ( p ) => [ p [ 0 ] , p [ 1 ] ] ; param features param removeHoles param transform export function featuresToMultiPolygon ( features , removeHoles = false , transform = copyPoint ) { const coordinates = [ ] ; for ( const { geometry } of features ) { if ( geometry . type === 'MultiPolygon' ) { for ( const coords of geometry . coordinates ) { if ( removeHoles ) { coordinates . push ( [ coords [ 0 ] . map ( transform ) ] ) ; } else { coordinates . push ( coords . map ( ( ring ) => ring . map ( transform ) ) ) ; } } } else if ( geometry . type === 'Polygon' ) { if ( removeHoles ) { coordinates . push ( [ geometry . coordinates [ 0 ] . map ( transform ) ] ) ; } else { coordinates . push ( geometry . coordinates . map ( ( ring ) => ring . map ( transform ) ) ) ; } } } return { type : 'MultiPolygon' , coordinates , } ; }