Opened 13 years ago

Last modified 10 years ago

#17107 closed Bug

Geodjango Tutorial: SRID problem when loading data from shapefile to PostGIS — at Version 3

Reported by: pauline.emery@… Owned by: nobody
Component: GIS Version: 1.3
Severity: Normal Keywords: SRID
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Aymeric Augustin)

I'm having a problem doing the section "LayerMapping" of the GeoDjango
official Tutorial [1].

After creating load.py in the world directory. Leaving as specified:
"the transform keyword set to False because the data in the shapefile
does not need to be converted -- it's already in WGS84 (SRID=4326)"

I execute as indicate the following commands:

$ python manage.py shell
>>> from world import load
>>> load.run()

And obtain the following error:

Failed to save the feature (id: 0) into the model with the keyword arguments:
{'iso2': u'AG', 'pop2005': 83039, 'area': 44, 'region': 19, 'lon':
-61.783000000000001, 'iso3': u'ATG', 'subregion': 29, 'fips': u'AC',
'lat': 17.077999999999999, 'un': 28, 'mpoly': 'MULTIPOLYGON
(((-61.729171999999949 17.608608000000004,-61.731116999999983
17.54722200000009,-61.732779999999991 17.541111,-61.738891999999964
17.5405540000001,-61.751944999999921
...
17.644722000000115,-61.731673999999941
17.624996000000067,-61.729171999999949 17.608608000000004)))', 'name':
u'Antigua and Barbuda'}
[... stack trace]
IntegrityError: new row for relation "world_worldborder" violates
check constraint "enforce_srid_mpoly"

Postgres enforcing the check constraint for SRID=4326. I don't know to
say to Django to insert explicitely the SRID into the MULTIPOLYGON
command. Inserting the line by hand on Postgres work fine using
ST_Geomfromtext( 'MULTIPOLYGON(((...) (...)),4326).

The same problem occurs with other tutorials:
GeoDjango Database API with the Zipcode model [2]
GeographicAdminQuickStart [3]

I'm working with Python 2.6 / Django 1.3 with GeoDjango / GDAL 1.7.2
/ PostgreSQL 8.4.8 / PostGIS 1.5 / Pyscopg2 2.4

Thank you for your time and your help

Change History (4)

by takinbo@…, 13 years ago

Attachment: adapter.py.patch added

patch to fix the SRID problem when using PostGIS with Django

comment:1 by takinbo@…, 13 years ago

Has patch: set

I created a patch that specifies the SRID when creating features using Django and the PostGIS backend. This patch needs to be applied to the contrib/gis/db/backends/postgis/adapter.py file.

comment:2 by pauline.emery@…, 13 years ago

Thank you for the patch takingbo! It solved the SRID problem. I really appreciate the help! All the best!

comment:3 by Aymeric Augustin, 13 years ago

Description: modified (diff)

Fixed formatting.

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