|
|
|
function calculateTotalArea(data) { |
|
let totalAreaSqMeters = 0; |
|
|
|
data.features.forEach(feature => { |
|
if (feature.geometry.type === "Polygon" || feature.geometry.type === "MultiPolygon") { |
|
totalAreaSqMeters += turf.area(feature); |
|
} |
|
}); |
|
|
|
return { |
|
areaSqMeters: totalAreaSqMeters, |
|
areaHectares: totalAreaSqMeters / 10000 |
|
}; |
|
} |
|
|
|
|
|
function calculateCentroid(data) { |
|
const polygonsOnly = { |
|
type: "FeatureCollection", |
|
features: data.features.filter(f => f.geometry.type === "Polygon" || f.geometry.type === "MultiPolygon") |
|
}; |
|
|
|
return turf.centroid(polygonsOnly); |
|
} |
|
|
|
|
|
function countGeometryTypes(data) { |
|
const geometryCounts = { Polygon: 0, Point: 0, LineString: 0, MultiPolygon: 0 }; |
|
|
|
data.features.forEach(feature => { |
|
const geomType = feature.geometry.type; |
|
if (geometryCounts[geomType] !== undefined) { |
|
geometryCounts[geomType]++; |
|
} |
|
}); |
|
|
|
return geometryCounts; |
|
} |
|
|
|
|
|
function getFeatureNames(data) { |
|
const featureNames = []; |
|
|
|
data.features.forEach(feature => { |
|
if (feature.properties && feature.properties.name) { |
|
featureNames.push(feature.properties.name); |
|
} |
|
}); |
|
|
|
return featureNames; |
|
} |
|
|