Some months ago, I was requested to develop a written guide on web-mapping system development using GeoDjango as published on the playlist on My Channel. After great efforts, I have released a complete GeoDjango guide that serves as a written replica of the YouTube Playlist. The guide illustrates the possibilities of developing a fully-fledged web-GIS system using Python and Django. It helps readers and developers identify the key issues, tips and tricks around developing these kind of systems. Using the guide, you will develop a sample project that one can advance to feature their objectives. It has code snippets and explanations to each of the snippets.

Author:Gardalar Fenrigul
Language:English (Spanish)
Published (Last):16 April 2005
PDF File Size:20.65 Mb
ePub File Size:2.16 Mb
Price:Free* [*Free Regsitration Required]

GeoDjango is an included contrib module for Django that turns it into a world-class geographic Web framework. GeoDjango strives to make it as simple as possible to create geographic Web applications, like location-based services.

Its features include:. GeoDjango has additional requirements beyond what Django requires — please consult the installation documentation for more details. This tutorial will guide you through the creation of a geographic web application for viewing the world borders.

Typically no special setup is required, so you can create a database as you would for any other project. We provide some tips for selected databases:. Use the standard django-admin script to create a project called geodjango :. This will initialize a new project. Now, create a world Django application within the geodjango project:. Edit the database connection settings to match your setup:. The world borders data is available in this zip file.

Create a data directory in the world application, download the world borders data, and unzip. When unzipped, the world borders dataset includes files with the following extensions:.

The GDAL ogrinfo utility allows examining the metadata of shapefiles or other vector data sources:. Similarly, LON: Real 8. Note that the models module is imported from django. The default spatial reference system for geometry fields is WGS84 meaning the SRID is — in other words, the field coordinates are in longitude, latitude pairs in units of degrees.

To use a different coordinate system, set the SRID of the geometry field with the srid argument. After defining your model, you need to sync it with the database. First, create a database migration:. If this looks correct, run migrate to create this table in the database:. This section will show you how to import the world borders shapefile into the database via GeoDjango models using the LayerMapping data import utility.

There are many different ways to import data into a spatial database — besides the tools included within GeoDjango, you may also use the following:. Earlier, you used ogrinfo to examine the contents of the world borders shapefile. Data source objects can have different layers of geospatial features; however, shapefiles are only allowed to have one layer:. Unfortunately, the shapefile data format does not allow for greater specificity with regards to geometry types.

This shapefile, like many others, actually includes MultiPolygon geometries, not Polygons. The Layer may also have a spatial reference system associated with it. If it does, the srs attribute will return a SpatialReference object:. This shapefile is in the popular WGS84 spatial reference system — in other words, the data uses longitude, latitude pairs in units of degrees.

In addition, shapefiles also support attribute fields that may contain additional data. Here are the fields on the World Borders layer:. The following code will let you examine the OGR types e. Layer objects may be sliced:. To import the data, use a LayerMapping in a Python script. Create a file called load.

Afterwards, invoke the Django shell from the geodjango project directory:. Next, import the load module, call the run routine, and watch LayerMapping do the work:. The ogrinspect command introspects a GDAL-supported vector data source e. Command-line options may be used to further define how the model is generated.

For example, the following command nearly reproduces the WorldBorder model and mapping dictionary created above, automatically:. The command produces the following output, which may be copied directly into the models. For example, you can find the country in the WorldBorder table that contains a particular point.

First, fire up the management shell:. Here, you retrieved a QuerySet with only one model: the border of the United States exactly what you would expect. Similarly, you may also use a GEOS geometry object. Here, you can combine the intersects spatial lookup with the get method to retrieve only the WorldBorder instance for San Marino instead of a queryset:.

The contains and intersects lookups are just a subset of the available queries — the GeoDjango Database API documentation has more.

This is not absolutely required by PostGIS, but generally you should only use raw queries when you know exactly what you are doing. GeoDjango loads geometries in a standardized textual representation. GeoDjango also offers a set of geographic annotations to compute distances and several other operations intersection, difference, etc.

See the Geographic Database Functions documentation. GeoDjango also supplements the Django admin by allowing users to create and modify geometries on a JavaScript slippy map powered by OpenLayers. Create a file called admin.

Next, edit your urls. Browse to any of the WorldBorder entries — the borders may be edited by clicking on a polygon and dragging the vertexes to the desired position. Django 1. Its features include: Django model fields for OGC geometries and raster data. Loosely-coupled, high-level Python interfaces for GIS geometry and raster operations and data manipulation in different formats.

Editing geometry fields from the admin. Note GeoDjango has additional requirements beyond what Django requires — please consult the installation documentation for more details. Note Proceed through the tutorial sections sequentially for step-by-step instructions. Configure settings. Model : Regular Django fields corresponding to the attributes in the world borders shapefile. MultiPolygonField Returns the string representation of the model.

Applying world. Note Unfortunately, the shapefile data format does not allow for greater specificity with regards to geometry types. This is an auto-generated Django model module created by ogrinspect. The PROJ. This point is the University of Houston Law Center.

Open Geospatial Consortium, Inc.


GeoDjango Tutorial Guide

The Django Software Foundation deeply values the diversity of our developers, users, and community. We are distraught by the suffering, oppression, and systemic racism the Black community faces every day. We can no longer remain silent. In silence, we are complicit. To eradicate racism, xenophobia, and all other forms of inequality, we must take action. It is our responsibility and our honour to use our platform to amplify the voices of the oppressed and marginalised. We ask today—and always—that the Django community comes together in support of the Black community.


Create Smart Maps With GeoDjango and Visualize Geographical Data

Everything is becoming smarter: we have smartphones, vacuums that remember our house layouts, smart homes that let us transform manual tasks into automatic ones, smart maps, etc. GeoDjango is a module of Django, a popular Python framework. It helps developers create location-based applications for instance, Tinder. The latter concept refers to a map that presents information. If you are using a different operating system, you can run Linux alongside it. Another option is that you can download a virtual machine such as Vmware Player or Virtual Box.

Related Articles