[GeoDjango] 02 - Geodjango Series Tutorials
GeoDjango intends to be a world-class geographic Web framework. Its goal is to make it as easy as possible to build GIS Web applications and harness the power of spatially enabled data.
问题来了,其数据库是怎样设计的?
Geodjango Series 1,主要关注其数据相关部分。

1.Introduction to Django projects https://youtu.be/L3YoX9wrGDc
2.Spatial data and Geo-databases https://youtu.be/jQlvPAiSCjk
3.Configure Leaflet in Django Admin https://youtu.be/XahUfrU4qk8
4.Generate GIS Model from Geospatial data https://youtu.be/Gtb3QHS2y3g
5.The Frontend (Urls, Views, Templates) https://youtu.be/vWcasu07R7Q
6.Popups in Geodjango https://youtu.be/8InvtB9Vqvs
7.Custom Layer Styles https://youtu.be/d4c-TjxsMNo
8.Layers Control https://youtu.be/Xt7a31qz-38
9.Routing in Leaflet https://youtu.be/Ci_4r4NcFAk
10.Spatial data editing with QGIS https://youtu.be/1-7KUHLTqjs
11.Geodjango Tutorial Series Summary https://youtu.be/pxX6gI48eh4
代码
The entire application can be found at https://github.com/wanjohikibui/Geodj...
Download the guide at http://www.lifeingis.com/downloads/
一、更换数据库
- settings.py
DATABASES = { 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'agricom', 'USER': 'postgres', 'HOST': 'localhost', 'PASSWORD': '123456', 'PORT': '5432', } }
- 安装postgresql
Ref: https://www.postgresql.org/
sudo apt-get install postgresql
测试一下,看看数据库中的表 有没有?需要创建对应的 database: agricom。
(django2) jeff@ThinkPad-T490:django_project$ sudo su postgres postgres@ThinkPad-T490:/home/jeff/Desktop/django_project$ psql psql (10.16 (Ubuntu 10.16-0ubuntu0.18.04.1)) Type "help" for help. postgres=# /database postgres-# /d
- 安装Psycopg
Ref: https://pypi.org/project/psycopg2/
Psycopg is the most popular PostgreSQL database adapter for the Python programming language.
pip install psycopg2
- 安装PostGIS
其实安装的是插件:postgresql-10-postgis-2.4
sudo apt-get install postgis
- 扩展插件
二、增强 models
出现此错误,因为需要migration。
AttributeError: module 'django.db.models' has no attribute 'PointField'
正确使用方法如下,然后 migration即 可。
from django.db import models from django.contrib.gis.db import models as gis_models from django.contrib.gis.geos import Point # GeoDjango takes lat and lng values in Point object. class Scanner(models.Model): user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) name = models.CharField(max_length=100, null=False, blank=False) description = models.TextField(default='default description.')
location = gis_models.PointField(srid=4326, default=Point(0.0, 0.0)) objects = gis_models.Manager()
三、增强 map
继承Leaflet,构成一个新类,再注册到Scanner内。
from django.contrib import admin from .models import Scanner, Label from leaflet.admin import LeafletGeoAdmin class ScannerAdmin(LeafletGeoAdmin): pass admin.site.register(Scanner, ScannerAdmin) admin.site.register(Label)
/* continue...*/
Candidates
How to integrate Geodjango with Google Maps API 3?
Build a simple GIS web application using GeoDjango and Google Maps
分类:
Coding-Python
, Project-Mobilar
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律