Opened 2 years ago

Closed 2 years ago

#33694 closed Cleanup/optimization (invalid)

GeoDjango tutorial documentation error.

Reported by: Maxim Danilov Owned by: nobody
Component: GIS Version: 4.0
Severity: Normal Keywords: geodjango, django.contrib.gis
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I try to follow GeoDjango tutorial.

World Borders step.
https://docs.djangoproject.com/en/4.0/ref/contrib/gis/tutorial/#worldborders

from this sentence:
The world borders data is available in this zip file. Create a data directory in the world application, download the world borders data, and unzip.

i download zip, https://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip

On the step Defining a Geographic Model:

I create class:

class WorldBorder(models.Model):

    # GeoDjango-specific: a geometry field (MultiPolygonField)
    mpoly = models.MultiPolygonField()

i think this is wrong in documentation.

Why i think so:

on the step gdal-interface
https://docs.djangoproject.com/en/4.0/ref/contrib/gis/tutorial/#gdal-interface

we don't have any field/attribute in layer object, but we have attribute "geom"


on the step layermapping
https://docs.djangoproject.com/en/4.0/ref/contrib/gis/tutorial/#layermapping

we have:

world_mapping = {
    ...
    'mpoly' : 'MULTIPOLYGON',
}

i think this is wrong in documentation.

Why i think so:
at the same step, on the

    layermapping.save(strict=True, verbose=verbose)

We resieve the error:

An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block. Failed to save {... 'geom': 'MULTIPOLYGON(....)'}

And at the end:
on the step Try ogrinspect
https://docs.djangoproject.com/en/4.0/ref/contrib/gis/tutorial/#try-ogrinspect

we reсeive a normal model with mapping:

class WorldBorder(models.Model):
    ...
    geom = models.MultiPolygonField(srid=4326)


worldborders_mapping = {
    ...
    'geom' : 'MULTIPOLYGON',
}

That's why i think, those parts of GeoDjango tutorial documentation is wrong:

step layermapping,
step Defining a Geographic Model

and, the same error we have also on the page LayerMapping data import utility.
https://docs.djangoproject.com/en/4.0/ref/contrib/gis/layermapping/

there we defined:

class TestGeo(models.Model):
    ...
    poly = models.PolygonField(srid=4269) # we want our model in a different SRID

    mapping = {'name' : 'str', # The 'name' model field maps to the 'str' layer field.
                         'poly' : 'POLYGON', # For geometry fields use OGC name.
               } # The mapping is a dictionary

if i use the same TM_WORLD_BORDERS-0.3.shp as a test_poly.shp
it is not works on the:

layermapping.save(verbose=True) # Save the layermap, imports the data.

with the same error.

From the 'Spatial queries' step, the author of the tutorial again uses the 'mpoly' field.

I think the field name "mpoly" was wrong to begin with, but it doesn't matter to Django what I think, does it?

Change History (2)

comment:1 by Maxim Danilov, 2 years ago

Keywords: django.contrib.gis added; django.contrib.geo removed

comment:2 by Mariusz Felisiak, 2 years ago

Easy pickings: unset
Resolution: invalid
Status: newclosed

Thanks for this report, however GeoDjango Tutorial works perfectly fine for me, a field name is not important because we defined world_mapping. Closing per TicketClosingReasons/UseSupportChannels

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