A web application for visualizing and managing tree data on the De Anza campus. Built with Django and PostGIS, this application provides an interactive map interface to explore trees on campus.
- Features
- Tech Stack
- Project Structure
- Installation and Setup
- Importing Tree Data
- API Endpoints
- Development and Production Environments
- Custom User Model
- Environment Variables
- Troubleshooting
- Production Deployment Considerations
- Running Tests
- Contributing
- License
- Interactive map visualization of tree data
- Detailed tree information display
- REST API for accessing tree data
- Tree data import from CSV files
- User authentication and permission management
- Backend: Django 5.1.6
- Database: PostgreSQL + PostGIS (for spatial data)
- API: Django REST Framework
- Frontend: JavaScript, Leaflet.js (map library)
- Deployment: Docker, Docker Compose
- Dependency Management: Poetry
The project consists of the following main apps:
- trees: Models and views for tree data management
- users: Custom user account and profile management
- Install Docker and Docker Compose:
- For Mac: Docker Desktop for Mac
- For Windows: Docker Desktop for Windows
- For Linux: Docker Engine and Docker Compose
1-1. Install Poetry
bash pip install poetry
-
Clone the repository:
git clone [repository-url] cd [repository-folder] -
Create and configure the
.envfile (if needed):cp .env.example .env # Edit the .env file if neededThe
.envfile should contain the following variables:# Django settings DJANGO_SECRET_KEY=django-insecure-your-secret-key-here DEBUG=1 # Set to 0 for production # Database settings DB_NAME=datreemap DB_USER=datreemap DB_PASSWORD=datreemap DB_HOST=db DB_PORT=5432 # GDAL/GEOS settings GDAL_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/libgdal.so GEOS_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/libgeos_c.so # Other settings ALLOWED_HOSTS=localhost 127.0.0.1 IN_DOCKER=TrueKey considerations when editing the
.envfile:- For security, change the
DJANGO_SECRET_KEYto a unique, random string in production - Set
DEBUG=0in production environments - Database security:
- Use strong, unique passwords for database users
- Consider using environment-specific database credentials
- In production, create a database user with limited permissions
- Never use 'root' or default passwords in production
- Consider using database connection pooling for production
- Adjust database credentials as needed
- For different architectures, update the GDAL/GEOS paths:
- ARM64 (M1/M2 Mac): use
/usr/lib/aarch64-linux-gnu/libgdal.so - Intel/AMD64: use
/usr/lib/libgdal.so
- ARM64 (M1/M2 Mac): use
- Update
ALLOWED_HOSTSto include your domain in production
- For security, change the
-
Update Poetry dependencies:
poetry lock
-
Start services using Docker Compose:
docker-compose up --build
-
Initialize the database:
# In a new terminal docker-compose exec web python manage.py migrate docker-compose exec web python manage.py import_trees "Tree Dataset_De Anza College_Backup.csv" docker-compose exec web python manage.py createsuperuser
-
Access the application in your web browser:
http://localhost:8000Admin interface:
http://localhost:8000/admin
A custom management command is provided to import tree data from CSV files:
# For Docker setup
docker-compose exec web python manage.py import_trees "Tree Dataset_De Anza College_Backup.csv"
# For local setup
python manage.py import_trees "Tree Dataset_De Anza College_Backup.csv"You can also export and restore tree data using Django's dumpdata/loaddata commands:
# Export tree data
docker-compose exec web python manage.py dumpdata trees.Tree > trees_backup.json
# Restore tree data
docker-compose exec web python manage.py loaddata trees_backup.json- Tree list:
/trees/api/rest/trees/ - Tree detail:
/trees/api/rest/trees/<tag_number>/ - Map tree data:
/trees/api/trees/ - Tree detail data:
/trees/api/trees/<tag_number>/
The Docker setup supports both development and production environments:
- Uses the
developmenttarget in Dockerfile - Mounts code as volume for live reloading
- Uses Django's development server (
runserver) - Set via
docker-compose.yml
- Uses the
productiontarget in Dockerfile - Uses Gunicorn as the WSGI server
- Collects static files automatically
- Set via
docker-compose.prod.yml
# For production deployment
docker-compose -f docker-compose.prod.yml up --build -dThe project implements a custom user model with fields for:
- Profile picture
- Name
- Contributor status
- Gender
- Language preferences
Key environment variables:
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,DB_PORT: Database connection detailsDEBUG: Enable/disable debug mode (1 or 0)SECRET_KEY: Django secret keyALLOWED_HOSTS: Allowed host domainsGDAL_LIBRARY_PATH,GEOS_LIBRARY_PATH: Paths to GDAL/GEOS librariesIN_DOCKER: Flag to determine Docker environment (for library path settings)
If you encounter GDAL library errors:
OSError: /usr/lib/libgdal.so: cannot open shared object file: No such file or directory
Ensure the correct library paths are set in your environment:
# Check library locations
docker-compose exec web find / -name "libgdal.so*" 2>/dev/null
# Check GDAL version
docker-compose exec web gdal-config --versionARM64 architecture (M1/M2 Mac) users should use:
GDAL_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/libgdal.so
GEOS_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/libgeos_c.so
If you encounter Poetry dependency errors:
# Update lock file
poetry lock
# Within Docker environment
docker run --rm -v $(pwd):/app -w /app python:3.12-slim bash -c "pip install poetry && poetry lock"If the web service can't connect to the database:
-
Ensure the database service is healthy:
docker-compose logs db
-
Make sure the
DB_HOSTis set todb(the service name) in Docker environment -
Check database connection manually:
docker-compose exec db psql -U datreemap -d datreemap -c "\l"
For production deployment:
- Set
DEBUG=0in.env - Configure a secure
SECRET_KEY - Use HTTPS
- Set up proper static file serving
- Apply security settings (HSTS, XSS protection, etc.)
- Use the production Docker Compose file:
docker-compose -f docker-compose.prod.yml up --build -d
# For Docker setup
docker-compose exec web python manage.py test
# For local setup
python manage.py testTwo ways to contribute to this project:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Check if the issue/feature has already been reported
- Create a new issue with a descriptive title and detailed description
- Include steps to reproduce (for bugs) or specific use cases (for features)
- Add relevant labels and screenshots if applicable
MIT License
Copyright (c) 2025 [Environmental Monitoring Society]
This project is a web application utilizing Geographic Information Systems to visualize and manage tree data across the De Anza campus.
For detailed Docker setup guide, see DOCKER_SETUP.md.