{"id":213,"date":"2024-08-16T07:13:33","date_gmt":"2024-08-16T07:13:33","guid":{"rendered":"https:\/\/research.binus.ac.id\/geoecoai\/?p=213"},"modified":"2024-08-21T16:17:50","modified_gmt":"2024-08-21T16:17:50","slug":"1-guide-to-backend-and-database-setup-for-geobee-dashboard-development","status":"publish","type":"post","link":"https:\/\/research.binus.ac.id\/geoecoai\/2024\/08\/16\/1-guide-to-backend-and-database-setup-for-geobee-dashboard-development\/","title":{"rendered":"1. Guide to Backend and Database Setup for GeoBee Dashboard Development"},"content":{"rendered":"<p>This article serves as a comprehensive guide for setting up the backend and database for the GeoBee Dashboard, which is focused on geospatial analysis for waste collection in Tangerang City. We\u2019ll cover how to install and configure PostGIS, set up the Python environment, and implement the workflow for uploading shapefiles and raster data.<\/p>\n<h2><strong>1. Setting Up and Installing PostGIS<\/strong><\/h2>\n<p>PostGIS is an essential extension for PostgreSQL that adds support for geographic objects, enabling us to store and query spatial data. Here\u2019s how to install and enable PostGIS and the PostGIS Raster extension:<\/p>\n<h3><strong>Step 1: Install PostgreSQL and PostGIS<\/strong><\/h3>\n<ol>\n<li><strong>Install PostgreSQL<\/strong>:\n<ul>\n<li>Depending on your operating system, follow the instructions to install PostgreSQL from the official <a href=\"https:\/\/www.postgresql.org\/download\/\" target=\"_new\" rel=\"noopener\">PostgreSQL website<\/a>.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Install PostGIS<\/strong>:\n<ul>\n<li>Once PostgreSQL is installed, you can install PostGIS from stack builder, guide in this video below:<a href=\"https:\/\/youtu.be\/yt17xL_Q8No?si=lmKlIbgtJBC85PPu\"> https:\/\/youtu.be\/yt17xL_Q8No?si=lmKlIbgtJBC85PPu<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><strong>Step 2: Enable PostGIS and PostGIS Raster Extension<\/strong><\/h3>\n<ol>\n<li><strong>Connect to PostgreSQL<\/strong>:\n<ul>\n<li>Access the PostgreSQL prompt:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">bash<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo -u postgres psql<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Create a new database<\/strong> (if not already created):\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> DATABASE your_db_name;<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<li><strong>Enable PostGIS in your database<\/strong>:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-sql\">\\c your_db_name<br \/>\n<span class=\"hljs-keyword\">CREATE<\/span> EXTENSION postgis;<br \/>\n<span class=\"hljs-keyword\">CREATE<\/span> EXTENSION postgis_raster;<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-sql\"><\/code><\/div>\n<\/div>\n<ul>\n<li>This will enable the spatial features and raster support in your database.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><strong>Step 3: Verify Installation<\/strong><\/h3>\n<ul>\n<li>Verify that the extensions are installed by running:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">sql<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-sql\">\\dx<br \/>\n<\/code><\/div>\n<\/div>\n<ul>\n<li>You should see <code>postgis<\/code> and <code>postgis_raster<\/code> listed.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><strong>2. Setting Up the Python Environment<\/strong><\/h2>\n<p>To get the backend running, we\u2019ll set up a Python environment that includes all the necessary dependencies for the GeoBee Dashboard.<\/p>\n<h3><strong>Step 1: Clone the Project Repository<\/strong><\/h3>\n<ol>\n<li><strong>Clone the GitHub Repository<\/strong>:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">\n<div class=\"flex items-center\"><\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">git <span class=\"hljs-built_in\">clone<\/span> https:\/\/github.com\/syauqiakm\/geobee-dashboard.git<br \/>\n<span class=\"hljs-built_in\">cd<\/span> geobee-dashboard\/Backend<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ol>\n<h3><strong>Step 2: Set Up a Python Virtual Environment<\/strong><\/h3>\n<ol>\n<li><strong>Create a Virtual Environment<\/strong>:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">python3 -m venv venv<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\"><\/code><\/div>\n<\/div>\n<\/li>\n<li><strong>Activate the Virtual Environment<\/strong>:\n<ul>\n<li>On <strong>Linux\/Mac<\/strong>:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\"><span class=\"hljs-built_in\">source<\/span> venv\/bin\/activate<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\"><\/code><\/div>\n<\/div>\n<\/li>\n<li>On <strong>Windows<\/strong>:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">.\\venv\\Scripts\\activate<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\"><\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><strong>Step 3: Install Dependencies<\/strong><\/h3>\n<ol>\n<li><strong>Install Required Packages<\/strong>:\n<ul>\n<li>Assuming the project has a <code>requirements.txt<\/code> file, install the dependencies:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">pip install -r requirements.txt<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\"><\/code><\/div>\n<\/div>\n<\/li>\n<li>If there\u2019s no <code>requirements.txt<\/code>, manually install the key packages:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">pip install fastapi uvicorn sqlalchemy psycopg2-binary geoalchemy2 shapely<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><strong>Step 4: Test the Environment Setup<\/strong><\/h3>\n<ol>\n<li><strong>Run the Application<\/strong>:\n<ul>\n<li>Start the FastAPI server to ensure everything is configured properly:\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">uvicorn main:app --reload<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\"><\/code><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Access the API<\/strong>:\n<ul>\n<li>Open your browser and navigate to <code>http:\/\/127.0.0.1:8000\/docs<\/code> to see the interactive API documentation.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>3. Shapefile and Raster Feature Workflow<\/strong><\/h2>\n<p>Understanding the workflow for handling shapefiles and raster data is crucial for smooth operation in the GeoBee Dashboard. The process involves multiple steps from the frontend to the backend and back to the frontend. Below is an illustration to help you visualize the workflow:<\/p>\n<h3><strong>Workflow Overview<\/strong><\/h3>\n<div><\/div>\n<p><em>[Placeholder Image &#8211; Insert actual image link]<\/em><\/p>\n<ol>\n<li><strong>Upload from Frontend<\/strong>:\n<ul>\n<li>Users upload shapefiles or raster data through the GeoBee Dashboard interface.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Backend Processing<\/strong>:\n<ul>\n<li>The backend receives the files, converts them into database-compatible formats, and stores the data in PostGIS.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Data Retrieval<\/strong>:\n<ul>\n<li>The frontend requests the processed data from the backend, which then queries the PostGIS database.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Display on Frontend<\/strong>:\n<ul>\n<li>The frontend renders the retrieved data, displaying maps, layers, or other geospatial visualizations.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>This simplified workflow helps users understand how geospatial data moves through the system, ensuring that each component works harmoniously.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>With PostGIS set up, the Python environment configured, and a clear understanding of the shapefile and raster workflow, your GeoBee Dashboard is well-prepared for effective geospatial analysis. This setup will enable efficient storage, processing, and visualization of spatial data, empowering decision-making for waste management in Tangerang City.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article serves as a comprehensive guide for setting up the backend and database for the GeoBee Dashboard, which is focused on geospatial analysis for waste collection in Tangerang City. We\u2019ll cover how to install and configure PostGIS, set up the Python environment, and implement the workflow for uploading shapefiles and raster data. 1. Setting [&hellip;]<\/p>\n","protected":false},"author":46,"featured_media":96,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backend-and-database"],"_links":{"self":[{"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":4,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":261,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/posts\/213\/revisions\/261"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/media\/96"}],"wp:attachment":[{"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/research.binus.ac.id\/geoecoai\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}