GeoDjango: Invalid spatial reference pointer returned from "OGR_L_GetSpatialRef"

72 views
Skip to first unread message

Joe

unread,
Dec 12, 2007, 9:19:09 PM12/12/07
to django...@googlegroups.com
I'm following along with the GeoDjango_Presentation.pdf at [1] from
the FOSS4G 2007 presentation at [2], using the shapefile
'st99_d00.shp' from [3]. When trying the example code listed on the
bottom slide of page 11 in the pdf , I get an error:

SRSException: Invalid spatial reference pointer returned from
"OGR_L_GetSpatialRef".

This occurs on both Debian Etch and OS X 10.4 (both are using GDAL
version 1.4.2 and python 2.4 with ctypes package installed). I'm just
starting out with GeoDjango so I'm not sure if it's an installation
problem or the code. I was able to successfully run the third-party
library installation tests at [4] and also the DataSource example at
[5], in case that helps to shed any light on the soundness of my
installation.

Should the example still work with the latest svn revision of
GeoDjango? The IPython session is pasted below.

Thanks,
Joe

[1] http://www.foss4g2007.org/presentations/viewattachment.php?attachment_id=78
[2] http://www.foss4g2007.org/presentations/view.php?abstract_id=222
[3] http://www.census.gov/geo/cob/bdy/st/st00shp/st99_d00_shp.zip
[4] http://code.djangoproject.com/wiki/GeoDjangoInstall#Third-PartyLibraryInstallationTests
[5] http://code.djangoproject.com/wiki/GeoDjangoExtras#DataSource


This IPython session is also pasted at http://dpaste.com/hold/27869/ :
==========================================================================

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

In [2]: ogrinfo('st99_d00.shp',num_features=1)
data source : st99_d00.shp
==== layer 0
shape type: Polygon
# features: 273
---------------------------------------------------------------------------
django.contrib.gis.gdal.error.SRSException
Traceback (most recent call last)

/home/joe/foss4g/<ipython console>

/usr/lib/python2.4/site-packages/django/contrib/gis/utils/ogrinfo.py
in ogrinfo(data_source, num_features)
27 print " shape type: %s" %
GEO_CLASSES[layer.geom_type.num].__name__
28 print " # features: %s" % len(layer)
---> 29 print " srs: %s" % layer.srs
30 extent_tup = layer.extent.tuple
31 print " extent: %s - %s" % (extent_tup[0:2],
extent_tup[2:4])

/usr/lib/python2.4/site-packages/django/contrib/gis/gdal/layer.py in srs(self)
100 def srs(self):
101 "Returns the Spatial Reference used in this Layer."
--> 102 ptr = get_layer_srs(self._ptr)
103 if ptr:
104 return SpatialReference(clone_srs(ptr))

/usr/lib/python2.4/site-packages/django/contrib/gis/gdal/prototypes/errcheck.py
in check_srs(result, func, cargs)
89 result = c_void_p(result)
90 if not result:
---> 91 raise SRSException('Invalid spatial reference pointer
returned from "%s".' % func.__name__)
92 return result
93

SRSException: Invalid spatial reference pointer returned from
"OGR_L_GetSpatialRef".

Justin Bronn

unread,
Dec 12, 2007, 10:12:04 PM12/12/07
to Django users
> Should the example still work with the latest svn revision of
> GeoDjango? The IPython session is pasted below.

Yes, it should work. You found a bug -- I just fixed it in r6916.

There have been some significant changes to GeoDjango since FOSS4G
(e.g., GEOS & GDAL refactors, distance queries, additional spatial
backends). However, substantively, everything should still work as
shown. This particular bug is an artifact of the GDAL library
refactoring: the census shapefiles do not explicitly give a spatial
reference, which is NAD83, and the `srs` property should be None
instead of raising an exception. One thing that has explicitly
changed is that `models.GeoMixin` is no longer required for geographic
models.

Thanks for the detailed report and traceback.

Best Regards,
-Justin

Joe

unread,
Dec 13, 2007, 11:22:35 AM12/13/07
to django...@googlegroups.com
On Dec 12, 2007 10:12 PM, Justin Bronn <jbr...@gmail.com> wrote:
>
> > Should the example still work with the latest svn revision of
> > GeoDjango? The IPython session is pasted below.
>
> Yes, it should work. You found a bug -- I just fixed it in r6916.

The example works perfectly now. Thanks very much!

> There have been some significant changes to GeoDjango since FOSS4G
> (e.g., GEOS & GDAL refactors, distance queries, additional spatial
> backends). However, substantively, everything should still work as
> shown. This particular bug is an artifact of the GDAL library
> refactoring: the census shapefiles do not explicitly give a spatial
> reference, which is NAD83, and the `srs` property should be None
> instead of raising an exception. One thing that has explicitly
> changed is that `models.GeoMixin` is no longer required for geographic
> models.

I appreciate your taking the time to explain the issue. It's very
helpful for someone just starting out with GeoDjango.

Thanks,
Joe

Reply all
Reply to author
Forward
0 new messages