Code


Version 2 (modified by jbronn, 7 years ago) (diff)

--

GeoDjango Extras

TOC()? This documentation is only a stub, and will become more complete as it's written.

Built-in Models

The PostGIS spatial_ref_sys and geometry_columns tables may be accessed through the SpatialRefSys and GeometryColumns models, respectively.

SpatialRefSys

>>> from django.contrib.gis.models import SpatialRefSys
>>> wgs84 = SpatialRefSys.objects.get(srid=4326)
>>> print wgs84
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
>>> print wgs84.proj4text # PROJ.4 representation 
+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs

GeometryColumns

LayerMapping

Convenient utility for importing spatial data into geographic models from GDAL-supported data sources (e.g., SHP Files). See the [browser:django/branches/gis/django/contrib/gis/utils/LayerMapping.py source code] docstring for more details.

from django.contrib.gis.utils import LayerMapping

Measure

Robert Coup's [browser:django/branches/gis/django/contrib/gis/measure.py measure] module allows for convenient representation of distance units.

Distance

>>> from django.contrib.gis.measure import Distance
>>> d = Distance(mi=5) # 5 miles
>>> print d
5.0 mi
>>> print d.nm # What's that in nautical miles?
4.3448812095
>>> d += Distance(yd=100) - Distance(ft=5) # Adding 295 feet
>>> print d
5.05587121212 mi

Area