File size: 1,540 Bytes
5262418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Function to calculate total area in square meters for polygons and multipolygons
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 // Convert to hectares
    };
}

// Function to calculate the centroid of all polygons and multipolygons
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 to count different geometry types
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 to retrieve feature names if available
function getFeatureNames(data) {
    const featureNames = [];

    data.features.forEach(feature => {
        if (feature.properties && feature.properties.name) {
            featureNames.push(feature.properties.name);
        }
    });

    return featureNames;
}