query($sql); $features = []; $total_warga = 0; while ($row = $stmt->fetch()) { $jumlah = (int) $row['jumlah_warga']; $total_warga += $jumlah; $features[] = [ 'type' => 'Feature', 'geometry' => json_decode($row['geojson']), 'properties' => [ 'id' => $row['id'], 'nama_pemilik' => $row['nama_pemilik'], 'luas' => $row['luas'], 'jumlah_warga' => $jumlah, 'total_tanggungan' => (int) $row['total_tanggungan'] ] ]; } $response = [ 'statistik' => [ 'total_kavling' => count($features), 'total_warga_terpetakan' => $total_warga ], 'geojson' => [ 'type' => 'FeatureCollection', 'features' => $features ] ]; sendSuccess($response, 'Data statistik spasial berhasil dihitung'); } catch (PDOException $e) { sendError('Gagal menghitung statistik spasial: ' . $e->getMessage(), 500); } } else { sendError('Method not allowed', 405); } ?>