Can anyone explain how to extract polygon shapes that are stored in a PostGIS database and display it in the browser?

I am using geodjango framework in python. I would like a step by step guide on how to achieve this.

1 Answer 1


There's an excellent tutorial within the Django documentation I recommend you check out. Here is the highlight reel...

Create your database; set up your Django project.

$ createdb -T template_postgis my_new_db
$ django-admin.py startproject my_new_project
$ cd my_new_project
$ python manage.py startapp my_new_app

Next, define the geographic model for your Polygon data.

from django.contrib.gis.db import models

class MyPolygon(models.Model):
    an_attribute = models.CharField(max_length=255)
    another_attribute = models.DateField()

    # Only these are required:
    geom = models.PolygonField(srid=4326)
    objects = models.GeoManager()

If you already have data in your PostGIS database and you want your GeoDjango model to match it, then simply indicate so in the model's Meta class.

class MyPolygon(models.Model):
    class Meta:
        managed = False # If you don't want Django to manage this table
        db_table = "name_of_existing_table"

If you don't already have a table full of spatial data, you'll next want to create your table with syncdb and then use the Django API to create model instances (instances of your Polygon geometry) and save them to the database.

$ python manage.py syncdb
  • Thank you,. but I think the tutorial in django is more on administrative interface,. I want to develop web mapping application that on a public page. :) Feb 14, 2014 at 0:48
  • Your question may be too broad. There are many, many different ways this might be done, depending on what kind of API you want to deploy, what tools you want to use to handle API requests, and what client side framework(s) you choose to use. My personal preference is to use e.g. django-piston for a REST interface, responding to requests for GeoJSON documents.
    – Arthur
    Feb 14, 2014 at 13:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.