Django

Code

Ticket #6246 (closed: fixed)

Opened 10 months ago

Last modified 10 months ago

gis: ogrinspect: AttributeError when the spatial reference system is undefined in the data source

Reported by: jos3ph Assigned to: jbronn
Milestone: Component: GIS
Version: gis Keywords: gis ogrinspect gdal
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Calling ogrinspect() without an explicit srid and with a data source that does not have a spatial reference system defined causes an AttributeError exception.

If the srid is explicitly given, no error occurs. However, since the code gives srid_str a value if srid is None, I'm assuming that an AttributeError should be caught and the srid_str given the same value as if srid were None.

I think this is may be similar to a previous issue I asked about on the django-user mailing list:

http://groups.google.com/group/django-users/browse_thread/thread/82f7c9b286285ea8/7188dc71222bc80b

which jbronn fixed in [6916].

The following IPython session, which is also pasted at http://dpaste.com/hold/28583/, is using the shapefile from http://www.census.gov/geo/cob/bdy/st/st00shp/st99_d00_shp.zip. Note that [2] works with an explicit srid, while [3] fails:

In [1]: from django.contrib.gis.utils.ogrinspect import *

In [2]: print ogrinspect('st99_d00.shp', 'State', srid='-1')
# This is an auto-generated Django model module created by ogrinspect.
from django.contrib.gis.db import models

class State(models.Model):
    area = models.DecimalField(max_digits=20, decimal_places=5)
    perimeter = models.DecimalField(max_digits=20, decimal_places=5)
    st99_d00_field = models.IntegerField()
    st99_d00_i = models.IntegerField()
    state = models.CharField(max_length=2)
    name = models.CharField(max_length=90)
    lsad = models.CharField(max_length=2)
    region = models.CharField(max_length=1)
    division = models.CharField(max_length=1)
    lsad_trans = models.CharField(max_length=50)
    geom = models.PolygonField(srid=-1)
    objects = models.GeoManager()

In [3]: ogrinspect('st99_d00.shp', 'State')
---------------------------------------------------------------------------
exceptions.AttributeError                            Traceback (most recent call last)

/home/joe/foss4g/<ipython console> 

/usr/lib/python2.4/site-packages/django/contrib/gis/utils/ogrinspect.py in ogrinspect(*args, **kwargs)
     60     Note: This routine calls the _ogrinspect() helper to do the heavy lifting.
     61     """
---> 62     return '\n'.join(s for s in _ogrinspect(*args, **kwargs))
     63 
     64 def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=None):

/usr/lib/python2.4/site-packages/django/contrib/gis/utils/ogrinspect.py in <generator expression>([outmost-iterable])
     60     Note: This routine calls the _ogrinspect() helper to do the heavy lifting.
     61     """
---> 62     return '\n'.join(s for s in _ogrinspect(*args, **kwargs))
     63 
     64 def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=None):

/usr/lib/python2.4/site-packages/django/contrib/gis/utils/ogrinspect.py in _ogrinspect(data_source, model_name, geom_name, layer_key, srid)
    111     # Setting up the SRID parameter string.
    112     if srid is None:
--> 113         srid = layer.srs.srid
    114         if srid is None:
    115             srid_str = 'srid=-1'

AttributeError: 'NoneType' object has no attribute 'srid'

Attachments

ogrinspect.py.diff (0.9 kB) - added by jos3ph on 12/19/07 16:11:48.

Change History

12/19/07 16:11:48 changed by jos3ph

  • attachment ogrinspect.py.diff added.

12/20/07 12:21:26 changed by jbronn

  • needs_better_patch changed.
  • needs_tests changed.
  • owner changed from nobody to jbronn.
  • keywords changed from gis ogrinspect to gis ogrinspect gdal.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.

12/21/07 15:36:54 changed by jbronn

  • status changed from new to closed.
  • resolution set to fixed.

(In [6966]) gis: Fixed #6246 (Thanks jos3ph); removed unnecessary commented debugging code.


Add/Change #6246 (gis: ogrinspect: AttributeError when the spatial reference system is undefined in the data source)




Change Properties
Action