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.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
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
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