Opened 15 years ago

Closed 15 years ago

#12036 closed (fixed)

GIS layermapping utility fails to import linestrings

Reported by: elpaso66 Owned by: nobody
Component: GIS Version: 1.1
Severity: Keywords: gis import
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems like there is an error in type comparison around line 288, objects gtype and ltype are tested for equality while probably their string values should be tested instead.

File: trunk/django/contrib/gis/utils/layermapping.py

The patch below should fix this issue and give a more complete error message.

@@ -288,9 +288,10 @@
                     raise LayerMapError('Invalid mapping for GeometryField "%s".' % field_name)

                 # Making sure that the OGR Layer's Geometry is compatible.
+
                 ltype = self.layer.geom_type
-                if not (gtype == ltype or self.make_multi(ltype, model_field)):
-                    raise LayerMapError('Invalid mapping geometry; model has %s, feature has %s.' % (fld_name, gtype))
+                if not (str(gtype) == str(ltype) or self.make_multi(ltype, model_field)):
+                    raise LayerMapError('Invalid mapping geometry; model has %s, feature has %s instead of %s.' % (fld_name, gtype,  ltype))

Change History (1)

comment:1 by jbronn, 15 years ago

Resolution: fixed
Status: newclosed

Because gtype is really an OGRGeomType instance, equality testing with strings works (e.g., OGRGeomType('POINT') == 'Point'). Regardless, for other reasons it was changed to a string comparison in r11742 when 3D support was added; I also clarified that exception to differentiate between the model field type and what was found on the layer, similar to what you put in the summary here.

While I agree there was a problem with the error message, the LayerMapping utility has always been able to import LineString geometries, it's done in the test suite in multiple places.

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