"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."Since my goal is to become a free software GIS application developer, and since Python and Django are two of the core technologies I hope to utilize, GeoDjango seems like a no-brainer as something I should learn.
In this post I'm going to document the beginning process of setting up a GeoDjango server on a local VirtualBox VM. In a later post, I'll look into installing it on the WebFaction application hosting service. Throughout this process, I'm going to modify the steps described in the tutorial to facility creating a github repo and migrating the app to WebFaction.
Since GeoDjango comes with Django, I'm going to start by creating a virtualenv on the same virtual machine I used to setup a django CMS virtualenv, the process for which I described in a previous post, Installing Django CMS on Ubuntu 14.04. I'll install this new virtualenv right alongside the other one. I'll be following the installation instructions from the GeoDjango Installation page, together with blog posts I've made previously documenting specific steps to install in my Ubuntu 14.04 VM. Installing GeoDjango requires installation of:
- Django
- Spatial database
Installing Django
$ mkdir geodjango
$ cd geodjango
$ virtualenv env
$ source env/bin/activate
(env)$ pip install django
(env)$ django-admin --version
1.8.3
(env)$ deactivate
Installing a Spatial Database
According to the documentation, "PostGIS is recommended, because it is the most mature and feature-rich open source spatial database." It also recommends that Ubuntu installation use packages. Since I'm new to this, I'll follow the recommendation.
$ sudo aptitude install postgresql-9.3 postgresql-9.3-postgis-2.1 postgresql-server-dev-9.3 python3-psycopg2Next setup a database user who can create databases:
$ sudo su - postgresNow follow the tutorial to see if it works (note: the command in red has been modified from tutorial with the aim of keeping the virtual environment directory (env) inside the project directory):
$ createuser --createdb [user]
$ exit
$ cd geodjangoChange the DATABASES section to match the following:
$ source env/bin/activate
(env)$ django-admin startproject geodjango .
(env)$ python manage.py startapp world
(env)$ vi geodjango/settings.py
DATABASES = {Also add the last two items to INSTALLED_APPS so that it looks like this:
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geodjango',
'USER': '[user]',
}
}
INSTALLED_APPS = (For the next step, we will need some gdal packages (and I'll grab unzip while I'm at it:
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'world',
)
(env)$ sudo aptitude install gdal-bin python3-gdal unzipThe tutorial includes another ogrinfo example command that provides more detail about the world borders shape file, which I'll skip in the interest of space. I will include the excellent short description of each of the component files in the shapefile:
(env)$ mkdir world/data
(env)$ cd world/data
(env)$ wget http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip
(env)$ unzip TM_WORLD_BORDERS-0.3.zip
(env)$ cd ../..
(env)$ ogrinfo world/data/TM_WORLD_BORDERS-0.3.shp
INFO: Open of `world/data/TM_WORLD_BORDERS-0.3.shp'
using driver `ESRI Shapefile' successful.
1: TM_WORLD_BORDERS-0.3 (Polygon)
(env)$
- .shp:
- Holds the vector data for the world borders geometries.
- .shx:
- Spatial index file for geometries stored in the .shp.
- .dbf:
- Database file for holding non-geometric attribute data (e.g., integer and character fields).
- .prj:
- Contains the spatial reference information for the geographic data stored in the shapefile.
The default spatial reference system is WGS84. New to me from the documentation is the existence of Open Geospatial Consortium (OGC) Spatial Reference System Identifier (SRID), which in the case of WGS84 is 4326.
from django.contrib.gis.db import models
class WorldBorder(models.Model):
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
mpoly = models.MultiPolygonField()
objects = models.GeoManager()
def __str__(self): # __unicode__ on Python 2
return self.name
The next step in the instructions were to run:
(env)$ python manage.py makemigrations
This didn't work for me, giving me the following error:ImportError: No module named 'psycopg2'I fixed this with:
(env)$ pip install psycopg2But when I ran the next command:
(env)$ python manage.py makemigrations
Migrations for 'world':
0001_initial.py:
- Create model WorldBorder
(env)$
(env)$ python manage.py sqlmigrate world 0001I got a database error:
psycopg2.OperationalError: FATAL: database "geodjango" does not existAnticipating that I might need knowledge of PostgreSQL databased administration, I began looking into that in an earlier post. I better look into that further before returning to the present task.
kayseriescortu.com - alacam.org - xescortun.com
ReplyDelete3 bhk flat in ajmer
ReplyDeletepalazzo kurti set online under 500
kurta sets and suit for women
azure data lake
azure databricks
azure sentinel
azure security center
azure bastion
Mmorpg Oyunlar
ReplyDeleteİnstagram Takipci Satın Al
Tiktok jeton hilesi
Tiktok jeton hilesi
Sac Ekim Antalya
Referans Kimliği Nedir
İNSTAGRAM TAKİPÇİ SATIN AL
metin2 pvp serverlar
ınstagram takipci satin al
lisans satın al
ReplyDeleteyurtdışı kargo
en son çıkan perde modelleri
uc satın al
en son çıkan perde modelleri
minecraft premium
nft nasıl alınır
özel ambulans
A Cloud Server is a pooled, centralized server resource that is hosted and delivered over a network—typically the Internet—and accessed on demand by multiple users.
ReplyDelete