Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating GeoDjango into existing Django project

I have a Django project with multiple apps. They all share a db with engine = django.db.backends.postgresql_psycopg2. Now I want some functionality of GeoDjango and decided I want to integrate it into my existing project. I read through the tutorial, and it looks like I have to create a separate spartial database for GeoDjango. I wonder if there is anyway around. I tried to add this into one of my apps' models.py without changing my db settings :

from django.contrib.gis.db.models import PointField

class Location(models.Model):
        location = PointField()

But when I run syncdb, I got this error.

File "/home/virtual/virtual-env/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 200, in db_type
    return connection.ops.geo_db_type(self)
like image 986
user815661 Avatar asked Jun 25 '11 22:06

user815661


People also ask

How do I connect to an existing database in Django?

Give Django your database parameters You'll need to tell Django what your database connection parameters are, and what the name of the database is. Do that by editing the DATABASES setting and assigning values to the following keys for the 'default' connection: NAME. ENGINE.

How do I install GeoDjango?

First, download the OSGeo4W installer (64bit), and run it. Select Express Web-GIS Install and click next. In the 'Select Packages' list, ensure that GDAL is selected; MapServer is also enabled by default, but is not required by GeoDjango and may be unchecked safely.

Why use GeoDjango?

GeoDjango is a very powerful framework for storing and working with geographic data using the Django ORM. It provides an easy-to-use API to find the distances between two points on a map, areas of polygons, the points within a polygon, and so on.


1 Answers

Actually, as i recall, django.contrib.gis.db.backends.postgis is extension of postgresql_psycopg2 so you could change db driver in settings, create new db with spatial template and then migrate data to new db (South is great for this). By itself geodjango is highly dependent on DB inner methods thus, unfortunately, you couldn't use it with regular db.

Other way - you could make use of django's multi-db ability, and create extra db for geodjango models.

like image 139
Pill Avatar answered Sep 18 '22 14:09

Pill