class documentation

class LayerMapping: (source)

View In Hierarchy

A class that maps OGR Layers to GeoDjango Models.

Method __init__ 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.
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.
Constant FIELD_TYPES Undocumented
Constant MULTI_TYPES Undocumented
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
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): (source)

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): (source)

Check the `fid_range` keyword.

def check_layer(self): (source)

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): (source)

Check the compatibility of the given spatial reference object.

def check_unique(self, unique): (source)

Check the `unique` keyword parameter -- may be a sequence or string.

def coord_transform(self): (source)

Return the coordinate transformation object.

def feature_kwargs(self, feat): (source)

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

def geometry_field(self): (source)

Return the GeometryField instance associated with the geographic column.

def make_multi(self, geom_type, model_field): (source)

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): (source)

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): (source)

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): (source)

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): (source)

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): (source)

Verify if the OGR Field contents are acceptable to the model field. If they are, return the verified value, otherwise raise an exception.

MULTI_TYPES = (source)

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')}
coord_dim = (source)

Undocumented

Undocumented

encoding = (source)

Undocumented

Undocumented

geo_field = (source)

Undocumented

geom_field = (source)

Undocumented

Undocumented

Undocumented

Undocumented

source_srs = (source)

Undocumented

spatial_backend = (source)

Undocumented

transaction_decorator = (source)

Undocumented

transaction_mode = (source)

Undocumented

transform = (source)

Undocumented

Undocumented

Undocumented