class documentation

class LayerMapping:

View In Hierarchy

A class that maps OGR Layers to GeoDjango Models.
Constant FIELD​_TYPES Undocumented
Constant MULTI​_TYPES Undocumented
Method __init__ No summary
Method check​_fid​_range Check the fid_range keyword.
Method check​_layer Check the Layer metadata and ensure that it's compatible with the mapping information and model. Unlike previous revisions, there is no need to increment through each feature in the Layer.
Method check​_srs Check the compatibility of the given spatial reference object.
Method check​_unique Check the unique keyword parameter -- may be a sequence or string.
Method coord​_transform Return the coordinate transformation object.
Method feature​_kwargs Given an OGR Feature, return a dictionary of keyword arguments for constructing the mapped model.
Method geometry​_field Return the GeometryField instance associated with the geographic column.
Method make​_multi Given the OGRGeomType for a geometry and its associated GeometryField, determine whether the geometry should be turned into a GeometryCollection.
Method save Save the contents from the OGR DataSource Layer into the database according to the mapping dictionary given at initialization.
Method unique​_kwargs Given the feature keyword arguments (from feature_kwargs), construct and return the uniqueness keyword arguments -- a subset of the feature kwargs.
Method verify​_fk Given an OGR Feature, the related model and its dictionary mapping, retrieve the related model for the ForeignKey mapping.
Method verify​_geom Verify the geometry -- construct and return a GeometryCollection if necessary (for example if the model field is MultiPolygonField while the mapped shapefile only contains Polygons).
Method verify​_ogr​_field Verify if the OGR Field contents are acceptable to the model field. If they are, return the verified value, otherwise raise an exception.
Instance Variable coord​_dim Undocumented
Instance Variable ds Undocumented
Instance Variable encoding Undocumented
Instance Variable fields Undocumented
Instance Variable geo​_field Undocumented
Instance Variable geom​_field Undocumented
Instance Variable layer Undocumented
Instance Variable mapping Undocumented
Instance Variable model Undocumented
Instance Variable source​_srs Undocumented
Instance Variable spatial​_backend Undocumented
Instance Variable transaction​_decorator Undocumented
Instance Variable transaction​_mode Undocumented
Instance Variable transform Undocumented
Instance Variable unique Undocumented
Instance Variable using Undocumented
MULTI_TYPES =

Undocumented

Value
{1: OGRGeomType('MultiPoint'),
 2: OGRGeomType('MultiLineString'),
 3: OGRGeomType('MultiPolygon'),
 OGRGeomType('Point25D').num: OGRGeomType('MultiPoint25D'),
 OGRGeomType('LineString25D').num: OGRGeomType('MultiLineString25D'),
 OGRGeomType('Polygon25D').num: OGRGeomType('MultiPolygon25D')}
def __init__(self, model, data, mapping, layer=0, source_srs=None, encoding='utf-8', transaction_mode='commit_on_success', transform=True, unique=None, using=None):
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.
def check_fid_range(self, fid_range):
Check the fid_range keyword.
def check_layer(self):
Check the Layer metadata and ensure that it's compatible with the mapping information and model. Unlike previous revisions, there is no need to increment through each feature in the Layer.
def check_srs(self, source_srs):
Check the compatibility of the given spatial reference object.
def check_unique(self, unique):
Check the unique keyword parameter -- may be a sequence or string.
def coord_transform(self):
Return the coordinate transformation object.
def feature_kwargs(self, feat):
Given an OGR Feature, return a dictionary of keyword arguments for constructing the mapped model.
def geometry_field(self):
Return the GeometryField instance associated with the geographic column.
def make_multi(self, geom_type, model_field):
Given the OGRGeomType for a geometry and its associated GeometryField, determine whether the geometry should be turned into a GeometryCollection.
def save(self, verbose=False, fid_range=False, step=False, progress=False, silent=False, stream=sys.stdout, strict=False):

Save the contents from the OGR DataSource Layer into the database according to the mapping dictionary given at initialization.

Keyword Parameters:
verbose:
If set, information will be printed subsequent to each model save executed on the database.
fid_range:
May be set with a slice or tuple of (begin, end) feature ID's to map from the data source. In other words, this keyword enables the user to selectively import a subset range of features in the geographic data source.
step:
If set with an integer, transactions will occur at every step interval. For example, if step=1000, a commit would occur after the 1,000th feature, the 2,000th feature etc.
progress:
When this keyword is set, status information will be printed giving the number of features processed and successfully saved. By default, progress information will pe printed every 1000 features processed, however, this default may be overridden by setting this keyword with an integer for the desired interval.
stream:
Status information will be written to this file handle. Defaults to using sys.stdout, but any object with a write method is supported.
silent:
By default, non-fatal error notifications are printed to stdout, but this keyword may be set to disable these notifications.
strict:
Execution of the model mapping will cease upon the first error encountered. The default behavior is to attempt to continue.
def unique_kwargs(self, kwargs):
Given the feature keyword arguments (from feature_kwargs), construct and return the uniqueness keyword arguments -- a subset of the feature kwargs.
def verify_fk(self, feat, rel_model, rel_mapping):
Given an OGR Feature, the related model and its dictionary mapping, retrieve the related model for the ForeignKey mapping.
def verify_geom(self, geom, model_field):
Verify the geometry -- construct and return a GeometryCollection if necessary (for example if the model field is MultiPolygonField while the mapped shapefile only contains Polygons).
def verify_ogr_field(self, ogr_field, model_field):
Verify if the OGR Field contents are acceptable to the model field. If they are, return the verified value, otherwise raise an exception.
coord_dim =

Undocumented

ds =

Undocumented

encoding =

Undocumented

fields: dict =

Undocumented

geo_field =

Undocumented

geom_field =

Undocumented

layer =

Undocumented

mapping =

Undocumented

model =

Undocumented

source_srs =

Undocumented

spatial_backend =

Undocumented

transaction_decorator =

Undocumented

transaction_mode =

Undocumented

transform =

Undocumented

unique =

Undocumented

using =

Undocumented