Code

Opened 5 years ago

Closed 4 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: UI/UX:

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))

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by jbronn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.