mysociety / mapit

A web service to map postcodes to administrative boundaries and more
Other
269 stars 88 forks source link

Empty features imported causes exception? #131

Closed mlandauer closed 10 years ago

mlandauer commented 10 years ago

This is as much a question as a bug report.

I'm trying to import some area data from shapefiles into mapit and I'm getting an exception thrown on importing a particular feature which I think might not have any geometry data. This is a shapefile provided by the Australian Bureau of Statistics so I would like to be able to import it as is rather than having to pre-process it in some way.

This is the exception I'm getting:

  looking at 'Warringah'.
  looking at 'Watson'.
  looking at 'Wentworth'.
  looking at 'Werriwa'.Traceback (most recent call last):

  looking at 'No usual address (NSW)'  File "/var/www/mapit/mapit/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 322, in handle
    label_output = self.handle_label(label, **options)
  File "/var/www/mapit/mapit/mapit/management/commands/mapit_import.py", line 233, in handle_label
    g = feat.geom.transform(settings.MAPIT_AREA_SRID, clone=True)
  File "/usr/lib/python2.7/dist-packages/django/contrib/gis/gdal/feature.py", line 88, in geom
    geom_ptr = capi.get_feat_geom_ref(self.ptr)
  File "/usr/lib/python2.7/dist-packages/django/contrib/gis/gdal/prototypes/errcheck.py", line 77, in check_geom
    raise OGRException('Invalid geometry pointer returned from "%s".' % func.__name__)
django.contrib.gis.gdal.error.OGRException: Invalid geometry pointer returned from "OGR_F_GetGeometryRef".

Is this expected behaviour? If this is happening because there is no geometry for the "No usual address (NSW)" feature how hard would it be to add support so that it spits out a warning but continues?

dracos commented 10 years ago

No, not expected behaviour :) Do you have a link to the shapefile so we can reproduce it here? Catching the error and continuing sounds straightforward, just never come across this before. It'd be good to know whether it was an empty geometry or something else.

mlandauer commented 10 years ago

Here's a link to a zip file which contains a shape file that was causing problems

dracos commented 10 years ago

Hi @mlandauer - I've pushed a hopeful fix for this on the issues/131-empty-feature-fix branch if you'd like to give that a try and let me know :)