MCPcopy
hub / github.com/django/django / __init__

Method __init__

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

A LayerMapping object is initialized using the given Model (not an instance), a DataSource (or string path to an OGR-supported data file), and a mapping dictionary. See the module level docstring for more details and keyword argument usage.

(
        self,
        model,
        data,
        mapping,
        layer=0,
        source_srs=None,
        encoding="utf-8",
        transaction_mode="commit_on_success",
        transform=True,
        unique=None,
        using=None,
    )

Source from the content-addressed store, hash-verified

95 }
96
97 def __init__(
98 self,
99 model,
100 data,
101 mapping,
102 layer=0,
103 source_srs=None,
104 encoding="utf-8",
105 transaction_mode="commit_on_success",
106 transform=True,
107 unique=None,
108 using=None,
109 ):
110 """
111 A LayerMapping object is initialized using the given Model (not an
112 instance), a DataSource (or string path to an OGR-supported data file),
113 and a mapping dictionary. See the module level docstring for more
114 details and keyword argument usage.
115 """
116 # Getting the DataSource and the associated Layer.
117 if isinstance(data, (str, Path)):
118 self.ds = DataSource(data, encoding=encoding)
119 else:
120 self.ds = data
121 self.layer = self.ds[layer]
122
123 self.using = using if using is not None else router.db_for_write(model)
124 connection = connections[self.using]
125 self.spatial_backend = connection.ops
126
127 # Setting the mapping & model attributes.
128 self.mapping = mapping
129 self.model = model
130
131 # Checking the layer -- initialization of the object will fail if
132 # things don't check out before hand.
133 self.check_layer()
134
135 # Getting the geometry column associated with the model (an
136 # exception will be raised if there is no geometry column).
137 if connection.features.supports_transform:
138 self.geo_field = self.geometry_field()
139 else:
140 transform = False
141
142 # Checking the source spatial reference system, and getting
143 # the coordinate transformation object (unless the `transform`
144 # keyword is set to False)
145 if transform:
146 self.source_srs = self.check_srs(source_srs)
147 self.transform = self.coord_transform()
148 else:
149 self.transform = transform
150
151 # Setting the encoding for OFTString fields, if specified.
152 if encoding:
153 # Making sure the encoding exists, if not a LookupError
154 # exception will be thrown.

Callers

nothing calls this directly

Calls 8

check_layerMethod · 0.95
geometry_fieldMethod · 0.95
check_srsMethod · 0.95
coord_transformMethod · 0.95
check_uniqueMethod · 0.95
DataSourceClass · 0.90
LayerMapErrorClass · 0.85
db_for_writeMethod · 0.45

Tested by

no test coverage detected