Project UAS Sistem Informasi Geografis (SIG)

This commit is contained in:
2026-06-08 20:24:54 +07:00
commit c6087ed7dd
33 changed files with 4549 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
<?php
$conn = new mysqli("localhost", "root", "bobbyandreanjapri", "webgis_spbu");
if ($conn->connect_error) {
die(json_encode(["error" => "Koneksi gagal: " . $conn->connect_error]));
}
$conn->set_charset("utf8");
?>
+33
View File
@@ -0,0 +1,33 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$id = intval($_GET['id'] ?? 0);
$type = $_GET['type'] ?? '';
if ($id == 0 || $type == '') {
echo json_encode(["message" => "Parameter tidak valid"]);
exit;
}
$table = '';
if ($type == 'point') $table = 'spbu';
if ($type == 'line') $table = 'jalan';
if ($type == 'polygon') $table = 'parsil';
if ($type == 'masjid') $table = 'masjid';
if ($type == 'penduduk') $table = 'penduduk_miskin';
if ($table == '') {
echo json_encode(["message" => "Type tidak dikenali"]);
exit;
}
$stmt = $conn->prepare("DELETE FROM $table WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo json_encode(["message" => "Data berhasil dihapus"]);
} else {
echo json_encode(["message" => "Gagal hapus", "error" => $stmt->error]);
}
?>
+31
View File
@@ -0,0 +1,31 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data tidak diterima"]);
exit;
}
$nama = $data['nama'] ?? '';
$no = $data['no'] ?? '';
$status = $data['status'] ?? '';
$lat = $data['lat'] ?? '';
$lng = $data['lng'] ?? '';
if ($nama == '' || $no == '' || $lat == '' || $lng == '') {
echo json_encode(["message" => "Field tidak lengkap"]);
exit;
}
$stmt = $conn->prepare("INSERT INTO spbu (nama, no_spbu, status, latitude, longitude) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssdd", $nama, $no, $status, $lat, $lng);
if ($stmt->execute()) {
echo json_encode(["message" => "Data berhasil disimpan", "id" => $stmt->insert_id]);
} else {
echo json_encode(["message" => "Gagal simpan", "error" => $stmt->error]);
}
?>
+39
View File
@@ -0,0 +1,39 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data kosong"]);
exit;
}
$nama = $data['nama'] ?? '';
$status = $data['status'] ?? '';
$panjang = $data['panjang'] ?? 0;
$geom = $data['geom'] ?? ''; // ✅ sudah string JSON dari JS, JANGAN json_encode lagi
if ($nama === '' || $geom === '') {
echo json_encode(["message" => "Field tidak lengkap"]);
exit;
}
$stmt = $conn->prepare("INSERT INTO jalan (nama, status, panjang, geom) VALUES (?, ?, ?, ?)");
if (!$stmt) {
echo json_encode(["message" => "Prepare gagal", "error" => $conn->error]);
exit;
}
$stmt->bind_param("ssds", $nama, $status, $panjang, $geom);
if ($stmt->execute()) {
echo json_encode(["message" => "Berhasil", "id" => $stmt->insert_id]);
} else {
echo json_encode(["message" => "Gagal", "error" => $stmt->error]);
}
$stmt->close();
$conn->close();
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) { echo json_encode(["message"=>"Data kosong"]); exit; }
$nama = $data['nama'] ?? '';
$pic = $data['pic'] ?? '';
$radius = $data['radius'] ?? 500;
$lat = $data['lat'] ?? 0;
$lng = $data['lng'] ?? 0;
if ($nama==='' || $pic==='') { echo json_encode(["message"=>"Field tidak lengkap"]); exit; }
$stmt = $conn->prepare("INSERT INTO masjid (nama, pic, radius, latitude, longitude, radius_layanan) VALUES (?,?,?,?,?,?)");
$stmt->bind_param("ssdddd", $nama, $pic, $radius, $lat, $lng, $radius);
if ($stmt->execute()) {
echo json_encode(["message"=>"Berhasil", "id"=>$stmt->insert_id]);
} else {
echo json_encode(["message"=>"Gagal", "error"=>$stmt->error]);
}
$stmt->close(); $conn->close();
?>
+51
View File
@@ -0,0 +1,51 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) { echo json_encode(["message"=>"Data kosong"]); exit; }
$nama_kk = $data['nama_kk'] ?? '';
$jumlah_anggota = $data['jumlah_anggota'] ?? 1;
$alamat = $data['alamat'] ?? '';
$lat = $data['lat'] ?? 0;
$lng = $data['lng'] ?? 0;
// Parameter baru
$penghasilan = $data['penghasilan'] ?? '< 500rb';
$kondisi_rumah = $data['kondisi_rumah'] ?? 'Kayu';
$sumber_air = $data['sumber_air'] ?? 'Sumur';
if ($nama_kk==='' || $alamat==='') { echo json_encode(["message"=>"Field tidak lengkap"]); exit; }
// Kalkulasi Bobot
$penghasilan_opsi = ['< 500rb' => 100, '500rb - 1jt' => 50, '> 1jt' => 10];
$rumah_opsi = ['Bambu/Tepas' => 100, 'Kayu' => 50, 'Tembok' => 10];
$air_opsi = ['Sungai' => 100, 'Sumur' => 50, 'PDAM' => 10];
$val_p = $penghasilan_opsi[$penghasilan] ?? 50;
$val_r = $rumah_opsi[$kondisi_rumah] ?? 50;
$val_a = $air_opsi[$sumber_air] ?? 50;
// Rumus: Penghasilan 50%, Rumah 30%, Air 20%
$skor_kerentanan = ($val_p * 0.50) + ($val_r * 0.30) + ($val_a * 0.20);
// Rekomendasi jenis bantuan berdasarkan indikator terburuk
$skor_per_jenis = [
'BLT / Modal Usaha' => $val_p,
'Bedah Rumah' => $val_r,
'Air Bersih / PDAM' => $val_a,
];
arsort($skor_per_jenis);
$jenis_bantuan = array_key_first($skor_per_jenis);
$stmt = $conn->prepare("INSERT INTO penduduk_miskin (nama_kk, jumlah_anggota, alamat, latitude, longitude, penghasilan, kondisi_rumah, sumber_air, skor_kerentanan, jenis_bantuan) VALUES (?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("sisddsssds", $nama_kk, $jumlah_anggota, $alamat, $lat, $lng, $penghasilan, $kondisi_rumah, $sumber_air, $skor_kerentanan, $jenis_bantuan);
if ($stmt->execute()) {
echo json_encode(["message"=>"Berhasil", "id"=>$stmt->insert_id, "skor"=>$skor_kerentanan]);
} else {
echo json_encode(["message"=>"Gagal", "error"=>$stmt->error]);
}
$stmt->close(); $conn->close();
?>
+39
View File
@@ -0,0 +1,39 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data kosong / tidak valid"]);
exit;
}
$nama = $data['nama'] ?? '';
$status = $data['status'] ?? '';
$luas = $data['luas'] ?? 0;
$geom = $data['geom'] ?? ''; // ✅ sudah string JSON dari JS, JANGAN json_encode lagi
if ($nama === '' || $status === '' || $geom === '') {
echo json_encode(["message" => "Field tidak lengkap", "data" => $data]);
exit;
}
$stmt = $conn->prepare("INSERT INTO parsil (nama, status, luas, geom) VALUES (?, ?, ?, ?)");
if (!$stmt) {
echo json_encode(["message" => "Prepare gagal", "error" => $conn->error]);
exit;
}
$stmt->bind_param("ssds", $nama, $status, $luas, $geom);
if ($stmt->execute()) {
echo json_encode(["message" => "Berhasil", "id" => $stmt->insert_id]);
} else {
echo json_encode(["message" => "Gagal", "error" => $stmt->error]);
}
$stmt->close();
$conn->close();
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = [];
/* POINT — SPBU */
$res = $conn->query("SELECT * FROM spbu");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='point'; $data[]=$r; }
}
/* LINE — Jalan */
$res = $conn->query("SELECT * FROM jalan");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='line'; $data[]=$r; }
}
/* POLYGON — Parsil */
$res = $conn->query("SELECT * FROM parsil");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='polygon'; $data[]=$r; }
}
/* MASJID */
$res = $conn->query("SELECT * FROM masjid");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='masjid'; $data[]=$r; }
}
/* PENDUDUK MISKIN */
$res = $conn->query("SELECT * FROM penduduk_miskin");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='penduduk'; $data[]=$r; }
}
echo json_encode($data);
?>
+35
View File
@@ -0,0 +1,35 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = [];
/* POINT */
$res = $conn->query("SELECT * FROM spbu");
if ($res) {
while ($r = $res->fetch_assoc()) {
$r['type'] = 'point';
$data[] = $r;
}
}
/* POLYLINE */
$res = $conn->query("SELECT * FROM jalan");
if ($res) {
while ($r = $res->fetch_assoc()) {
$r['type'] = 'line';
$data[] = $r;
}
}
/* POLYGON */
$res = $conn->query("SELECT * FROM parsil");
if ($res) {
while ($r = $res->fetch_assoc()) {
$r['type'] = 'polygon';
$data[] = $r;
}
}
echo json_encode($data);
?>
+20
View File
@@ -0,0 +1,20 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = [];
/* MASJID */
$res = $conn->query("SELECT * FROM masjid");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='masjid'; $data[]=$r; }
}
/* PENDUDUK MISKIN */
$res = $conn->query("SELECT * FROM penduduk_miskin");
if ($res) {
while ($r = $res->fetch_assoc()) { $r['type']='penduduk'; $data[]=$r; }
}
echo json_encode($data);
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = [];
$res = $conn->query("SELECT * FROM spbu");
if ($res) {
while ($r = $res->fetch_assoc()) {
$r['type'] = 'point';
$data[] = $r;
}
}
echo json_encode($data);
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data kosong"]);
exit;
}
$id = intval($data['id'] ?? 0);
$geom = $data['geom'] ?? '';
$panjang = $data['panjang'] ?? 0;
$stmt = $conn->prepare("UPDATE jalan SET geom = ?, panjang = ? WHERE id = ?");
$stmt->bind_param("sdi", $geom, $panjang, $id);
if ($stmt->execute()) {
echo json_encode(["message" => "Berhasil diupdate"]);
} else {
echo json_encode(["message" => "Gagal update", "error" => $stmt->error]);
}
?>
+41
View File
@@ -0,0 +1,41 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data kosong"]);
exit;
}
$id = intval($data['id'] ?? 0);
$radius = floatval($data['radius'] ?? 0);
if ($id <= 0 || $radius <= 0) {
echo json_encode(["message" => "Parameter tidak valid"]);
exit;
}
// Sesuaikan dengan batas slider di draw_sosial.js.
if ($radius < 100 || $radius > 5000) {
echo json_encode(["message" => "Radius harus berada di antara 100 sampai 5000 meter"]);
exit;
}
$stmt = $conn->prepare("UPDATE masjid SET radius = ?, radius_layanan = ? WHERE id = ?");
if (!$stmt) {
echo json_encode(["message" => "Gagal menyiapkan query", "error" => $conn->error]);
exit;
}
$stmt->bind_param("ddi", $radius, $radius, $id);
if ($stmt->execute()) {
echo json_encode(["message" => "Berhasil", "radius" => $radius]);
} else {
echo json_encode(["message" => "Gagal", "error" => $stmt->error]);
}
$stmt->close();
$conn->close();
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) { echo json_encode(["message"=>"Data kosong"]); exit; }
$id = intval($data['id'] ?? 0);
$jenis_bantuan = $data['jenis_bantuan'] ?? '';
if ($id === 0 || $jenis_bantuan === '') {
echo json_encode(["message"=>"Parameter tidak valid"]);
exit;
}
$stmt = $conn->prepare("UPDATE penduduk_miskin SET jenis_bantuan=? WHERE id=?");
$stmt->bind_param("si", $jenis_bantuan, $id);
if ($stmt->execute()) {
echo json_encode(["message"=>"Berhasil"]);
} else {
echo json_encode(["message"=>"Gagal", "error"=>$stmt->error]);
}
$stmt->close(); $conn->close();
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data kosong"]);
exit;
}
$id = intval($data['id'] ?? 0);
$geom = $data['geom'] ?? '';
$luas = $data['luas'] ?? 0;
$stmt = $conn->prepare("UPDATE parsil SET geom = ?, luas = ? WHERE id = ?");
$stmt->bind_param("sdi", $geom, $luas, $id);
if ($stmt->execute()) {
echo json_encode(["message" => "Berhasil diupdate"]);
} else {
echo json_encode(["message" => "Gagal update", "error" => $stmt->error]);
}
?>