Author: jbronn
Date: 2007-09-25 01:14:01 -0500 (Tue, 25 Sep 2007)
New Revision: 6423

Added:
   django/branches/gis/django/contrib/gis/utils/ogrinfo.py
Removed:
   django/branches/gis/django/contrib/gis/utils/inspect_data.py
Modified:
   django/branches/gis/django/contrib/gis/utils/__init__.py
Log:
gis: renamed inspect_data and sample() to ogrinfo, and now displays the extent 
and field type information.


Modified: django/branches/gis/django/contrib/gis/utils/__init__.py
===================================================================
--- django/branches/gis/django/contrib/gis/utils/__init__.py    2007-09-25 
04:25:04 UTC (rev 6422)
+++ django/branches/gis/django/contrib/gis/utils/__init__.py    2007-09-25 
06:14:01 UTC (rev 6423)
@@ -2,11 +2,11 @@
  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)
+# Importing LayerMapping and ogrinfo (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.ogrinfo import ogrinfo, sample
     from django.contrib.gis.utils.layermapping import LayerMapping
 
 # Importing GeoIP

Deleted: django/branches/gis/django/contrib/gis/utils/inspect_data.py
===================================================================
--- django/branches/gis/django/contrib/gis/utils/inspect_data.py        
2007-09-25 04:25:04 UTC (rev 6422)
+++ django/branches/gis/django/contrib/gis/utils/inspect_data.py        
2007-09-25 06:14:01 UTC (rev 6423)
@@ -1,27 +0,0 @@
-"""
-This module includes some utility functions for inspecting the layout
-of a gdal.DataSource.
-"""
-
-from django.contrib.gis.gdal.geometries import GEO_CLASSES
-
-def sample(data_source, num_features=10, gcs_file=None):
-    """
-    Walks the available layers in the supplied ``data_source``, displaying
-    the fields for the first ``num_features`` features.
-    """
-
-    for i, layer in enumerate(data_source):
-        print "data source : %s" % data_source.name
-        print "==== layer %s" % i
-        print "  shape type: %s" % GEO_CLASSES[layer.geom_type.num].__name__
-        print "  # features: %s" % len(layer)
-        print "         srs: %s" % layer.srs
-        print "Showing first %s features ========" % num_features
-
-        width = max(*map(len,layer.fields))
-        fmt = " %%%ss:%%s" % width
-        for i, feature in enumerate(layer[:num_features]):
-            print "======== Feature %s" % i
-            for field in layer.fields:
-                print fmt % (field, feature.get(field))

Copied: django/branches/gis/django/contrib/gis/utils/ogrinfo.py (from rev 6411, 
django/branches/gis/django/contrib/gis/utils/inspect_data.py)
===================================================================
--- django/branches/gis/django/contrib/gis/utils/ogrinfo.py                     
        (rev 0)
+++ django/branches/gis/django/contrib/gis/utils/ogrinfo.py     2007-09-25 
06:14:01 UTC (rev 6423)
@@ -0,0 +1,53 @@
+"""
+This module includes some utility functions for inspecting the layout
+of a GDAL data source -- the functionality is analogous to the output
+produced by the `ogrinfo` utility.
+"""
+
+from django.contrib.gis.gdal import DataSource
+from django.contrib.gis.gdal.geometries import GEO_CLASSES
+
+def ogrinfo(data_source, num_features=10):
+    """
+    Walks the available layers in the supplied `data_source`, displaying
+    the fields for the first `num_features` features.
+    """
+
+    # Checking the parameters.
+    if isinstance(data_source, str):
+        data_source = DataSource(data_source)
+    elif isinstance(data_source, DataSource):
+        pass
+    else:
+        raise Exception, 'Data source parameter must be a string or a 
DataSource object.'
+
+    for i, layer in enumerate(data_source):
+        print "data source : %s" % data_source.name
+        print "==== layer %s" % i
+        print "  shape type: %s" % GEO_CLASSES[layer.geom_type.num].__name__
+        print "  # features: %s" % len(layer)
+        print "         srs: %s" % layer.srs
+        extent_tup = layer.extent.tuple
+        print "      extent: %s - %s" % (extent_tup[0:2], extent_tup[2:4])
+        print "Displaying the first %s features ====" % num_features
+
+        width = max(*map(len,layer.fields))
+        fmt = " %%%ss: %%s" % width
+        for i, feature in enumerate(layer[:num_features]):
+            print "=== Feature %s" % i
+            for field in layer.fields:
+                fld_typ = feature[field].__class__.__name__.replace('OFT', '')
+                output = fmt % (field, fld_typ)
+                val = feature.get(field)
+                if val:
+                    if isinstance(val, str):
+                        val_fmt = ' ("%s")'
+                    else:
+                        val_fmt = ' (%s)'
+                    output += val_fmt % val
+                else:
+                    output += ' (None)'
+                print output
+
+# For backwards compatibility.
+sample = ogrinfo


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to