| | 1 | GeoDjango has some great documentation, but there are still some areas that are missing, especially some simple examples for Django noobs. |
|---|
| | 2 | |
|---|
| | 3 | First, check which branch you're using. As of 2/24/08, The gis branch in the main django svn lags a bit behind some of the work being done on the gis-newforms branch, available at select mercurial repositories near you (find out which to use by asking the developers on #geodjango). This example is for use with the latest gis-newforms. |
|---|
| | 4 | |
|---|
| | 5 | Next, follow the excellent [http://code.djangoproject.com/wiki/GeoDjangoInstall official install instructions]. If you already have a box with all the software described [UbuntuBaseStackSource here], you just need to softlink your site-packages/django to the gis-newforms/django that you downloaded. Now, you should have GeoDjango available (see their install instructions page above to test this), and so we can start building a basic site. |
|---|
| | 6 | |
|---|
| | 7 | The example site we'll build will be an app with Counties (which we will import from a shapefile), and Locations, which will reside within a county. When we add a location, it should automatically get assigned an appropriate County. We will create a basic kml view of the locations for display in Google Earth, and an OpenLayer based map view. |
|---|
| | 8 | |
|---|
| | 9 | create the site and app |
|---|
| | 10 | {{{ |
|---|
| | 11 | django-admin.py startproject geosite |
|---|
| | 12 | cd geosite |
|---|
| | 13 | python manage.py createapp geoapp |
|---|
| | 14 | }}} |
|---|
| | 15 | |
|---|
| | 16 | next, let's get us some URL's, by modifying urls.py: |
|---|
| | 17 | {{{ |
|---|
| | 18 | #urls.py |
|---|
| | 19 | |
|---|
| | 20 | |
|---|
| | 21 | |
|---|
| | 22 | }}} |
|---|
| | 23 | |
|---|
| | 24 | and make some models: |
|---|
| | 25 | {{{ |
|---|
| | 26 | #geoapp/models.py |
|---|
| | 27 | |
|---|
| | 28 | }}} |
|---|
| | 29 | |
|---|
| | 30 | and, some views: |
|---|
| | 31 | #geoapp/views.py |
|---|
| | 32 | {{{ |
|---|
| | 33 | |
|---|
| | 34 | |
|---|
| | 35 | }}} |
|---|
| | 36 | finally, the templates: |
|---|
| | 37 | {{{ |
|---|
| | 38 | #geoapp/templates/placemarks.kml |
|---|
| | 39 | |
|---|
| | 40 | |
|---|
| | 41 | }}} |
|---|
| | 42 | and |
|---|
| | 43 | {{{ |
|---|
| | 44 | #geoapp/templates/base.kml |
|---|
| | 45 | |
|---|
| | 46 | |
|---|
| | 47 | }}} |