MCPcopy
hub / github.com/django/django / feature_kwargs

Method feature_kwargs

django/contrib/gis/utils/layermapping.py:345–376  ·  view source on GitHub ↗

Given an OGR Feature, return a dictionary of keyword arguments for constructing the mapped model.

(self, feat)

Source from the content-addressed store, hash-verified

343
344 # Keyword argument retrieval routines.
345 def feature_kwargs(self, feat):
346 """
347 Given an OGR Feature, return a dictionary of keyword arguments for
348 constructing the mapped model.
349 """
350 # The keyword arguments for model construction.
351 kwargs = {}
352
353 # Incrementing through each model field and OGR field in the
354 # dictionary mapping.
355 for field_name, ogr_name in self.mapping.items():
356 model_field = self.fields[field_name]
357
358 if isinstance(model_field, GeometryField):
359 # Verify OGR geometry.
360 try:
361 val = self.verify_geom(feat.geom, model_field)
362 except GDALException:
363 raise LayerMapError("Could not retrieve geometry from feature.")
364 elif isinstance(model_field, models.base.ModelBase):
365 # The related _model_, not a field was passed in -- indicating
366 # another mapping for the related Model.
367 val = self.verify_fk(feat, model_field, ogr_name)
368 else:
369 # Otherwise, verify OGR Field type.
370 val = self.verify_ogr_field(feat[ogr_name], model_field)
371
372 # Setting the keyword arguments for the field name with the
373 # value obtained above.
374 kwargs[field_name] = val
375
376 return kwargs
377
378 def unique_kwargs(self, kwargs):
379 """

Callers 1

_saveMethod · 0.95

Calls 5

verify_geomMethod · 0.95
verify_fkMethod · 0.95
verify_ogr_fieldMethod · 0.95
LayerMapErrorClass · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected