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,
)
| 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. |
nothing calls this directly
no test coverage detected