Opened 17 years ago

Closed 17 years ago

#6246 closed (fixed)

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

Reported by: jos3ph Owned by: jbronn
Component: GIS Version: gis
Severity: Keywords: gis ogrinspect gdal
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (1)

ogrinspect.py.diff (932 bytes ) - added by jos3ph 17 years ago.

Download all attachments as: .zip

Change History (3)

by jos3ph, 17 years ago

Attachment: ogrinspect.py.diff added

comment:1 by jbronn, 17 years ago

Keywords: gdal added
Owner: changed from nobody to jbronn
Triage Stage: UnreviewedAccepted

comment:2 by jbronn, 17 years ago

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.
Back to Top