MCPcopy
hub / github.com/django/django / LayerMapping

Class LayerMapping

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

A class that maps OGR Layers to GeoDjango Models.

Source from the content-addressed store, hash-verified

57
58
59class LayerMapping:
60 "A class that maps OGR Layers to GeoDjango Models."
61
62 # Acceptable 'base' types for a multi-geometry type.
63 MULTI_TYPES = {
64 1: OGRGeomType("MultiPoint"),
65 2: OGRGeomType("MultiLineString"),
66 3: OGRGeomType("MultiPolygon"),
67 OGRGeomType("Point25D").num: OGRGeomType("MultiPoint25D"),
68 OGRGeomType("LineString25D").num: OGRGeomType("MultiLineString25D"),
69 OGRGeomType("Polygon25D").num: OGRGeomType("MultiPolygon25D"),
70 }
71 # Acceptable Django field types and corresponding acceptable OGR
72 # counterparts.
73 FIELD_TYPES = {
74 models.AutoField: OFTInteger,
75 models.BigAutoField: OFTInteger64,
76 models.SmallAutoField: OFTInteger,
77 models.BooleanField: (OFTInteger, OFTReal, OFTString),
78 models.IntegerField: (OFTInteger, OFTReal, OFTString),
79 models.FloatField: (OFTInteger, OFTReal),
80 models.DateField: OFTDate,
81 models.DateTimeField: OFTDateTime,
82 models.EmailField: OFTString,
83 models.TimeField: OFTTime,
84 models.DecimalField: (OFTInteger, OFTReal),
85 models.CharField: OFTString,
86 models.SlugField: OFTString,
87 models.TextField: OFTString,
88 models.URLField: OFTString,
89 models.UUIDField: OFTString,
90 models.BigIntegerField: (OFTInteger, OFTReal, OFTString),
91 models.SmallIntegerField: (OFTInteger, OFTReal, OFTString),
92 models.PositiveBigIntegerField: (OFTInteger, OFTReal, OFTString),
93 models.PositiveIntegerField: (OFTInteger, OFTReal, OFTString),
94 models.PositiveSmallIntegerField: (OFTInteger, OFTReal, OFTString),
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.

Callers 15

test_3d_layermappingMethod · 0.90
test_initMethod · 0.90
test_simple_layermapMethod · 0.90
test_data_source_strMethod · 0.90
test_layermap_strictMethod · 0.90
test_invalid_layerMethod · 0.90
test_textfieldMethod · 0.90

Calls 1

OGRGeomTypeClass · 0.90

Tested by 15

test_3d_layermappingMethod · 0.72
test_initMethod · 0.72
test_simple_layermapMethod · 0.72
test_data_source_strMethod · 0.72
test_layermap_strictMethod · 0.72
test_invalid_layerMethod · 0.72
test_textfieldMethod · 0.72