From 687f463d3b76fe58df0324b635bc17542ca64ae4 Mon Sep 17 00:00:00 2001 From: Kris Date: Sat, 6 Jun 2026 14:16:30 +0000 Subject: [PATCH] Upload files to "/" --- README.md | 25 +++++ api.php | 65 +++++++++++++ connect.php | 16 +++ database.sql | 18 ++++ index.html | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 392 insertions(+) create mode 100644 README.md create mode 100644 api.php create mode 100644 connect.php create mode 100644 database.sql create mode 100644 index.html diff --git a/README.md b/README.md new file mode 100644 index 0000000..1427ddd --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Project 2 - WebGIS Manajemen Jalan dan Tanah + +Project ini khusus untuk mengelola data spasial berbentuk: + +- Polyline untuk jalan. +- Polygon untuk tanah/kavling. + +## Database + +Import file `database.sql` ke phpMyAdmin. Database yang dibuat adalah: + +`webgis_jalan_tanah_p2` + +Tabel utama: + +`data_spasial` + +## Cara Menjalankan + +1. Letakkan folder ini di `htdocs`. +2. Jalankan Apache dan MySQL. +3. Import `database.sql`. +4. Buka `http://localhost/webgis_pisah/project_02_webgis_jalan_tanah/`. +5. Gunakan tool polyline untuk menambah jalan. +6. Gunakan tool polygon untuk menambah tanah/kavling. diff --git a/api.php b/api.php new file mode 100644 index 0000000..55fa833 --- /dev/null +++ b/api.php @@ -0,0 +1,65 @@ +query($sql); + $data = []; + + while ($row = $result->fetch_assoc()) { + $data[] = $row; + } + + echo json_encode($data); +} +elseif ($action === 'simpan') { + $nama = trim($_POST['nama'] ?? ''); + $jenis_objek = $_POST['jenis_objek'] ?? ''; + $status = $_POST['status'] ?? ''; + $ukuran = floatval($_POST['ukuran'] ?? 0); + $geojson = $_POST['geojson'] ?? ''; + + if ($nama === '' || $jenis_objek === '' || $geojson === '') { + echo json_encode(["status" => "error", "message" => "Nama, jenis objek, dan geometri wajib diisi."]); + exit; + } + + $stmt = $conn->prepare("INSERT INTO data_spasial (nama, jenis_objek, status, ukuran, geojson) VALUES (?, ?, ?, ?, ?)"); + $stmt->bind_param("sssds", $nama, $jenis_objek, $status, $ukuran, $geojson); + + if ($stmt->execute()) { + echo json_encode(["status" => "success"]); + } else { + echo json_encode(["status" => "error", "message" => $stmt->error]); + } + + $stmt->close(); +} +elseif ($action === 'hapus') { + $id = intval($_POST['id'] ?? 0); + + if ($id <= 0) { + echo json_encode(["status" => "error", "message" => "ID tidak valid."]); + exit; + } + + $stmt = $conn->prepare("DELETE FROM data_spasial WHERE id = ?"); + $stmt->bind_param("i", $id); + + if ($stmt->execute()) { + echo json_encode(["status" => "success"]); + } else { + echo json_encode(["status" => "error", "message" => $stmt->error]); + } + + $stmt->close(); +} +else { + echo json_encode(["status" => "error", "message" => "Action tidak dikenali."]); +} + +$conn->close(); +?> diff --git a/connect.php b/connect.php new file mode 100644 index 0000000..ff692df --- /dev/null +++ b/connect.php @@ -0,0 +1,16 @@ +connect_error) { + http_response_code(500); + die(json_encode([ + "status" => "error", + "message" => "Koneksi database gagal: " . $conn->connect_error + ])); +} +?> diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..bc55b13 --- /dev/null +++ b/database.sql @@ -0,0 +1,18 @@ +CREATE DATABASE IF NOT EXISTS webgis_jalan_tanah_p2; +USE webgis_jalan_tanah_p2; + +DROP TABLE IF EXISTS data_spasial; +CREATE TABLE data_spasial ( + id INT AUTO_INCREMENT PRIMARY KEY, + nama VARCHAR(150) NOT NULL, + jenis_objek ENUM('Jalan', 'Tanah') NOT NULL, + status VARCHAR(100) NOT NULL, + ukuran DOUBLE NOT NULL DEFAULT 0, + geojson LONGTEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); + +INSERT INTO data_spasial (nama, jenis_objek, status, ukuran, geojson) VALUES +('Contoh Jalan Ahmad Yani', 'Jalan', 'Jalan Nasional', 1250.00, '{"type":"LineString","coordinates":[[109.334,-0.055],[109.342,-0.047],[109.351,-0.043]]}'), +('Contoh Tanah Kavling A', 'Tanah', 'SHM', 8500.00, '{"type":"Polygon","coordinates":[[[109.337,-0.032],[109.342,-0.032],[109.342,-0.028],[109.337,-0.028],[109.337,-0.032]]]}'); diff --git a/index.html b/index.html new file mode 100644 index 0000000..e0717c9 --- /dev/null +++ b/index.html @@ -0,0 +1,268 @@ + + + + + + Project 2 - WebGIS Jalan dan Tanah + + + + + +
+

Project 2 - Jalan dan Tanah

+

Gunakan polyline untuk jalan dan polygon untuk tanah/kavling.

+
+
+ + + + + +