1212
1313def mapping (data_source , geom_name = 'geom' , layer_key = 0 , multi_geom = False ):
1414 """
15- Given a DataSource, generates a dictionary that may be used
15+ Given a DataSource, generates a dictionary that may be used
1616 for invoking the LayerMapping utility.
1717
1818 Keyword Arguments:
1919 `geom_name` => The name of the geometry field to use for the model.
20-
20+
2121 `layer_key` => The key for specifying which layer in the DataSource to use;
2222 defaults to 0 (the first layer). May be an integer index or a string
2323 identifier for the layer.
@@ -31,7 +31,7 @@ def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False):
3131 pass
3232 else :
3333 raise TypeError ('Data source parameter must be a string or a DataSource object.' )
34-
34+
3535 # Creating the dictionary.
3636 _mapping = {}
3737
@@ -52,32 +52,32 @@ def ogrinspect(*args, **kwargs):
5252 model name this function will generate a GeoDjango model.
5353
5454 Usage:
55-
55+
5656 >>> from django.contrib.gis.utils import ogrinspect
5757 >>> ogrinspect('/path/to/shapefile.shp','NewModel')
58-
58+
5959 ...will print model definition to stout
60-
60+
6161 or put this in a python script and use to redirect the output to a new
6262 model like:
63-
63+
6464 $ python generate_model.py > myapp/models.py
65-
66- # generate_model.py
65+
66+ # generate_model.py
6767 from django.contrib.gis.utils import ogrinspect
6868 shp_file = 'data/mapping_hacks/world_borders.shp'
6969 model_name = 'WorldBorders'
7070
7171 print ogrinspect(shp_file, model_name, multi_geom=True, srid=4326,
7272 geom_name='shapes', blank=True)
73-
73+
7474 Required Arguments
7575 `datasource` => string or DataSource object to file pointer
76-
76+
7777 `model name` => string of name of new model class to create
78-
78+
7979 Optional Keyword Arguments
80- `geom_name` => For specifying the model name for the Geometry Field.
80+ `geom_name` => For specifying the model name for the Geometry Field.
8181 Otherwise will default to `geom`
8282
8383 `layer_key` => The key for specifying which layer in the DataSource to use;
@@ -86,38 +86,38 @@ def ogrinspect(*args, **kwargs):
8686
8787 `srid` => The SRID to use for the Geometry Field. If it can be determined,
8888 the SRID of the datasource is used.
89-
89+
9090 `multi_geom` => Boolean (default: False) - specify as multigeometry.
91-
91+
9292 `name_field` => String - specifies a field name to return for the
9393 `__unicode__` function (which will be generated if specified).
94-
95- `imports` => Boolean (default: True) - set to False to omit the
96- `from django.contrib.gis.db import models` code from the
94+
95+ `imports` => Boolean (default: True) - set to False to omit the
96+ `from django.contrib.gis.db import models` code from the
9797 autogenerated models thus avoiding duplicated imports when building
9898 more than one model by batching ogrinspect()
99-
99+
100100 `decimal` => Boolean or sequence (default: False). When set to True
101101 all generated model fields corresponding to the `OFTReal` type will
102102 be `DecimalField` instead of `FloatField`. A sequence of specific
103103 field names to generate as `DecimalField` may also be used.
104104
105105 `blank` => Boolean or sequence (default: False). When set to True all
106- generated model fields will have `blank=True`. If the user wants to
106+ generated model fields will have `blank=True`. If the user wants to
107107 give specific fields to have blank, then a list/tuple of OGR field
108108 names may be used.
109109
110110 `null` => Boolean (default: False) - When set to True all generated
111111 model fields will have `null=True`. If the user wants to specify
112112 give specific fields to have null, then a list/tuple of OGR field
113113 names may be used.
114-
114+
115115 Note: This routine calls the _ogrinspect() helper to do the heavy lifting.
116116 """
117117 return '\n ' .join (s for s in _ogrinspect (* args , ** kwargs ))
118118
119119def _ogrinspect (data_source , model_name , geom_name = 'geom' , layer_key = 0 , srid = None ,
120- multi_geom = False , name_field = None , imports = True ,
120+ multi_geom = False , name_field = None , imports = True ,
121121 decimal = False , blank = False , null = False ):
122122 """
123123 Helper routine for `ogrinspect` that generates GeoDjango models corresponding
@@ -140,7 +140,7 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non
140140 # keyword arguments.
141141 def process_kwarg (kwarg ):
142142 if isinstance (kwarg , (list , tuple )):
143- return [s .lower () for s in kwarg ]
143+ return [s .lower () for s in kwarg ]
144144 elif kwarg :
145145 return [s .lower () for s in ogr_fields ]
146146 else :
@@ -164,18 +164,18 @@ def get_kwargs_str(field_name):
164164 yield ''
165165
166166 yield 'class %s(models.Model):' % model_name
167-
167+
168168 for field_name , width , precision , field_type in izip (ogr_fields , layer .field_widths , layer .field_precisions , layer .field_types ):
169169 # The model field name.
170170 mfield = field_name .lower ()
171171 if mfield [- 1 :] == '_' : mfield += 'field'
172-
172+
173173 # Getting the keyword args string.
174174 kwargs_str = get_kwargs_str (field_name )
175175
176176 if field_type is OFTReal :
177177 # By default OFTReals are mapped to `FloatField`, however, they
178- # may also be mapped to `DecimalField` if specified in the
178+ # may also be mapped to `DecimalField` if specified in the
179179 # `decimal` keyword.
180180 if field_name .lower () in decimal_fields :
181181 yield ' %s = models.DecimalField(max_digits=%d, decimal_places=%d%s)' % (mfield , width , precision , kwargs_str )
@@ -192,8 +192,8 @@ def get_kwargs_str(field_name):
192192 elif field_type is OFTDate :
193193 yield ' %s = models.TimeField(%s)' % (mfield , kwargs_str [2 :])
194194 else :
195- raise TypeError ('Unknown field type %s in %s' % (fld_type , mfield ))
196-
195+ raise TypeError ('Unknown field type %s in %s' % (field_type , mfield ))
196+
197197 # TODO: Autodetection of multigeometry types (see #7218).
198198 gtype = layer .geom_type
199199 if multi_geom and gtype .num in (1 , 2 , 3 ):
0 commit comments