summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2007-09-24 22:18:00 +0000
committerJustin Bronn <jbronn@gmail.com>2007-09-24 22:18:00 +0000
commit65b4cb2cca6e0ab9f6c4bb0c086e9adfa0301436 (patch)
treef9072ca86918d3eccf8f14c0886d1d1931e4740b
parent102532660224f962b142a178db9dc0fc3c59492e (diff)
gis: utils module now only imports LayerMapping when GDAL is installed; the `source_srs` keyword lf LayerMapping may now take integer and string parameters (for SRID and WKT spatial references, respectively).
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6414 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/utils/__init__.py10
-rw-r--r--django/contrib/gis/utils/layermapping.py14
2 files changed, 19 insertions, 5 deletions
diff --git a/django/contrib/gis/utils/__init__.py b/django/contrib/gis/utils/__init__.py
index bdc965556c..65a9987363 100644
--- a/django/contrib/gis/utils/__init__.py
+++ b/django/contrib/gis/utils/__init__.py
@@ -1,6 +1,14 @@
-from django.contrib.gis.utils.layermapping import LayerMapping
+"""
+ This module contains useful utilities for GeoDjango.
+"""
+
from django.contrib.gis.utils.inspect_data import sample
+# Importing LayerMapping (will not be done if GDAL is not installed)
+from django.contrib.gis.gdal import HAS_GDAL
+if HAS_GDAL:
+ from django.contrib.gis.utils.layermapping import LayerMapping
+
# Importing GeoIP
try:
from django.contrib.gis.utils.geoip import GeoIP
diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py
index facb4975b3..34092fda5a 100644
--- a/django/contrib/gis/utils/layermapping.py
+++ b/django/contrib/gis/utils/layermapping.py
@@ -30,10 +30,14 @@ Usage:
geometry type, e.g. 'POINT', 'LINESTRING', 'POLYGON'.
Keyword Args:
- layer -- The index of the layer to use from the Data Source (defaults to 0)
+ layer:
+ The index of the layer to use from the Data Source (defaults to 0)
- source_srs -- Use this to specify the source SRS manually (for example,
- some shapefiles don't come with a '.prj' file)
+ source_srs:
+ Use this to specify the source SRS manually (for example, some
+ shapefiles don't come with a '.prj' file). A SRID integer, a
+ WKT string, a SpatialReference, and a SpatialRefSys object are
+ all valid parameters here.
Example:
@@ -167,7 +171,7 @@ def check_feature(feat, model_fields, mapping):
else:
raise Exception, 'Given mapping field "%s" not in given Model fields!' % model_field
- ## Handling if we get a geometry in the Field ###
+ ### Handling if we get a geometry in the Field ###
if ogr_field in ogc_types:
# At this time, no more than one geographic field per model =(
if HAS_GEO:
@@ -218,6 +222,8 @@ def check_srs(layer, source_srs):
sr = source_srs
elif isinstance(source_srs, SpatialRefSys):
sr = source_srs.srs
+ elif isinstance(source_srs, (int, str)):
+ sr = SpatialReference(source_srs)
else:
sr = layer.srs
if not sr: