Opened 7 years ago

Last modified 3 years ago

#21021 new Cleanup/optimization

Default geom_type attribute for GeometryWidget should be "Geometry", not "Unknown"

Reported by: Mathieu Leplatre Owned by:
Component: GIS Version: 1.6-beta-1
Severity: Normal Keywords: minor
Cc: Claude Paroz, olivier.tabone@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The default value for geom_type is "Unknown" whereas we expect it to be "Geometry".

Indeed, by default we rely on GDAL to set the geom_type attribute, and it returns an unexpected value :

>>> from django.contrib.gis import gdal
>>> str(gdal.OGRGeomType('GEOMETRY'))

In fields, we override explicitly his value, so the problem is hidden.

But IMHO the widget should behave nicely with default values, for example instantiated like this :

class BigMapWidget(BaseGeometryWidget):
    map_height = 1200

class GeomForm(forms.Form):

    def __init__(self, *args, **kwargs):
         super(GeomForm, self).__init__(*args, **kwargs)
         self.fields['geom'].widget = BigMapWidget()

Of course, this problem only applies to generic Geometry field types, and those are commonly used.

Change History (8)

comment:1 Changed 7 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by EricBoersma

Owner: changed from nobody to EricBoersma
Status: newassigned

comment:3 Changed 7 years ago by Tim Graham

Has patch: set
Triage Stage: AcceptedReady for checkin

Eric, don't forget to link to your PR from the ticket and check "Has patch" so it's picked up for review.

Here's Eric's PR. It looks good to me but I'll let Claude or something more familiar with GeoDjango do a final review.

comment:4 Changed 7 years ago by Claude Paroz

Triage Stage: Ready for checkinAccepted

Eric, can you explain where the 102 number comes from in your patch? I'm not sure changing the OGR semantic is a good idea. I think we'd rather solve this in the forms/widgets layer. But I'm open to any other argument.

comment:5 Changed 6 years ago by Tim Graham

Patch needs improvement: set

comment:6 Changed 4 years ago by Olivier Tabone

Cc: olivier.tabone@… added
Owner: changed from EricBoersma to Olivier Tabone

claim the ticket, working on it during duth sprint.

comment:7 Changed 4 years ago by Olivier Tabone

Has patch: unset
Patch needs improvement: unset

Looking at GDAL documentation, there is no OGR type matching 'POLYGON'. enum OGRwkbGeometryType

Hence the '102' magic number in the patch does not match OGR specification.

I agree with Claude we should not change OGR semantics. returning wkbUnknown for an empty geometry seems correct according to GDAL.

removed 'has patch' flag because the pull request has been closed quite a long time ago by tim.

comment:8 Changed 3 years ago by Olivier Tabone

Owner: Olivier Tabone deleted
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top