Code

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#8881 closed (fixed)

LayerMapping Error with more than two fields geometry

Reported by: woakas@… Owned by: jbronn
Component: GIS Version: 1.0-beta
Severity: Keywords: gis layermapping
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jbronn)

If my models have two or more geometry fields:

class Lugares(models.Model) :
    nombre = models.CharField(max_length=80)
    punto = models.MultiPointField(null=True, blank=True, srid=4326)
    poligono = models.MultiPolygonField(null=True, blank=True, srid=4326)
    objects =models.GeoManager()


lm=LayerMapping(Lugares,'/home/woakas/nuevo.shp', mapping,unique={'poligono':'POLYGON','tipolugar':'Ciudad'})

LayerMapError                             Traceback (most recent call last)

/home/woakas/mig/Migtrace/trunk/src/<ipython console> in <module>()

/usr/lib/python2.5/site-packages/django/contrib/gis/utils/layermapping.py in __init__(self, model, data, mapping, layer, source_srs, encoding, transaction_mode, transform, unique)
    186         # geometry column).
    187         self.model = model
--> 188         self.geo_col = self.geometry_column()
    189 
    190         # Checking the source spatial reference system, and getting

/usr/lib/python2.5/site-packages/django/contrib/gis/utils/layermapping.py in geometry_column(self)
    516             return GeometryColumns.objects.get(**gc_kwargs)
    517         except Exception, msg:
--> 518             raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)
    519 
    520     def make_multi(self, geom_type, model_field):

LayerMapError: Geometry column does not exist for model. (did you run syncdb?):
 get() returned more than one GeometryColumns -- it returned 2! Lookup parameters were {'f_table_name': 'migtrace_lugares'}

Attachments (0)

Change History (5)

comment:1 follow-up: Changed 6 years ago by woakas@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

posible fixed

@@ -513,7 +513,7 @@

try:

db_table = self.model._meta.db_table
if SpatialBackend.name == 'oracle': db_table = db_table.upper()

  • gc_kwargs = {GeometryColumns.table_name_col() : db_table}

+ gc_kwargs = {GeometryColumns.table_name_col() : db_table, 'f_geometry_columnin':self.mapping}

return GeometryColumns.objects.get(gc_kwargs)

except Exception, msg:

raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)

comment:2 in reply to: ↑ 1 Changed 6 years ago by anonymous

Replying to woakas@gmail.com:

posible fixed

--- django/contrib/gis/utils/layermapping.py	(revisión: 8965)
+++ django/contrib/gis/utils/layermapping.py	(copia de trabajo)
@@ -513,7 +513,7 @@
         try:
             db_table = self.model._meta.db_table
             if SpatialBackend.name == 'oracle': db_table = db_table.upper()
-            gc_kwargs = {GeometryColumns.table_name_col() : db_table}
+            gc_kwargs = {GeometryColumns.table_name_col() : db_table, 'f_geometry_column__in':self.mapping}
             return GeometryColumns.objects.get(**gc_kwargs)
         except Exception, msg:
             raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)

comment:3 Changed 6 years ago by jbronn

  • Description modified (diff)
  • Keywords gis layermapping added
  • Owner changed from nobody to jbronn

comment:4 Changed 6 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r8994. Dunno why trac didn't catch it in the commit message.

comment:5 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

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.