Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

gis: utils module now only imports LayerMapping when GDAL is installe…

…d; 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
  • Loading branch information...
commit 65b4cb2cca6e0ab9f6c4bb0c086e9adfa0301436 1 parent 1025326
@jbronn jbronn authored
View
10 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
View
14 django/contrib/gis/utils/layermapping.py
@@ -30,10 +30,14 @@
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:
Please sign in to comment.
Something went wrong with that request. Please try again.