
    h#                     d    S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
  SS jrS r         S	S jrg)
z
This module is for inspecting OGR data sources and generating either
models for GeoDjango and/or mapping dictionaries for use with the
`LayerMapping` utility.
    )
DataSource)OFTDateOFTDateTime
OFTIntegerOFTInteger64OFTReal	OFTStringOFTTimec                 |   [        U [        5      (       a  [        U 5      n O![        U [        5      (       a  O[        S5      e0 nX   R                   H%  nUR                  5       nUSS S:X  a  US-  nXTU'   M'     X   R                  nU(       a  UR                  5         [        U5      R                  5       XA'   U$ )a  
Given a DataSource, generate a dictionary that may be used
for invoking the LayerMapping utility.

Keyword Arguments:
 `geom_name` => The name of the geometry field to use for the model.

 `layer_key` => The key for specifying which layer in the DataSource to use;
   defaults to 0 (the first layer).  May be an integer index or a string
   identifier for the layer.

 `multi_geom` => Boolean (default: False) - specify as multigeometry.
>Data source parameter must be a string or a DataSource object.N_field)	
isinstancestrr   	TypeErrorfieldslower	geom_typeto_multiupper)data_source	geom_name	layer_key
multi_geom_mappingr   mfieldgtypes           U/var/www/html/env/lib/python3.13/site-packages/django/contrib/gis/utils/ogrinspect.pymappingr       s     +s## -	K	,	,L
 	

 H '.."#;#gF 	 /
 ",,Ee***,HO    c                  6    SR                  [        U 0 UD65      $ )a	  
Given a data source (either a string or a DataSource object) and a string
model name this function will generate a GeoDjango model.

Usage:

>>> from django.contrib.gis.utils import ogrinspect
>>> ogrinspect('/path/to/shapefile.shp','NewModel')

...will print model definition to stout

or put this in a Python script and use to redirect the output to a new
model like:

$ python generate_model.py > myapp/models.py

# generate_model.py
from django.contrib.gis.utils import ogrinspect
shp_file = 'data/mapping_hacks/world_borders.shp'
model_name = 'WorldBorders'

print(ogrinspect(shp_file, model_name, multi_geom=True, srid=4326,
                 geom_name='shapes', blank=True))

Required Arguments
 `datasource` => string or DataSource object to file pointer

 `model name` => string of name of new model class to create

Optional Keyword Arguments
 `geom_name` => For specifying the model name for the Geometry Field.
   Otherwise will default to `geom`

 `layer_key` => The key for specifying which layer in the DataSource to use;
   defaults to 0 (the first layer).  May be an integer index or a string
   identifier for the layer.

 `srid` => The SRID to use for the Geometry Field.  If it can be determined,
   the SRID of the datasource is used.

 `multi_geom` => Boolean (default: False) - specify as multigeometry.

 `name_field` => String - specifies a field name to return for the
   __str__() method (which will be generated if specified).

 `imports` => Boolean (default: True) - set to False to omit the
   `from django.contrib.gis.db import models` code from the
   autogenerated models thus avoiding duplicated imports when building
   more than one model by batching ogrinspect()

 `decimal` => Boolean or sequence (default: False).  When set to True
   all generated model fields corresponding to the `OFTReal` type will
   be `DecimalField` instead of `FloatField`.  A sequence of specific
   field names to generate as `DecimalField` may also be used.

 `blank` => Boolean or sequence (default: False).  When set to True all
   generated model fields will have `blank=True`.  If the user wants to
   give specific fields to have blank, then a list/tuple of OGR field
   names may be used.

 `null` => Boolean (default: False) - When set to True all generated
   model fields will have `null=True`.  If the user wants to specify
   give specific fields to have null, then a list/tuple of OGR field
   names may be used.

Note: Call the _ogrinspect() helper to do the heavy lifting.

)join_ogrinspect)argskwargss     r   
ogrinspectr(   ;   s    H 99[$1&122r!   Nc              #     ^^^#    [        U [        5      (       a  [        U 5      n O![        U [        5      (       a  O[        S5      eX   nUR                  mU4S jnU" U
5      mU" U	5      mU" U5      nUU4S jnU(       a  Sv   Sv   Sv   Sv   SU-  v   [        TUR                  UR                  UR                  5       GH  u  nnnnUR                  5       nUSS	 S
:X  a  US-  nU" U5      nU[        L a3  UR                  5       U;   a  SUUUU4-  v   MY  SU< SUSS	 < S3v   Mk  U[        L a  SU< SUSS	 < S3v   M  U[        L a  SU< SUSS	 < S3v   M  U[        L a  SU< SU< U< S3v   M  U[        L a  SU< SUSS	 < S3v   M  U[        L a  SU< SUSS	 < S3v   M  U[         L a  SU< SUSS	 < S3v   GM  [        SU< SU< 35      e   UR"                  nU(       a  UR%                  5         UR&                  nUc;  UR(                  c  SnO0UR(                  R*                  nUc  SnOUS:X  a  SnOSU-  nOSU-  nSU< SU< SU< S3v   U(       a  Sv   SU-  v   g	g	7f)z
Helper routine for `ogrinspect` that generates GeoDjango models corresponding
to the given data source.  See the `ogrinspect` docstring for more details.
r   c                    > [        U [        [        45      (       a   U  Vs/ s H  oR                  5       PM     sn$ U (       a   T Vs/ s H  oR                  5       PM     sn$ / $ s  snf s  snf )N)r   listtupler   )kwargs
ogr_fieldss     r   process_kwarg"_ogrinspect.<locals>.process_kwarg   sV    edE]++',-u!GGIu--'12z!GGIz22I	 .2s   A&A+c                    > / nU R                  5       T;   a  UR                  S5        U R                  5       T;   a  UR                  S5        U(       a  SSR                  U5      -   $ g)Nz	null=Truez
blank=Truez,  )r   appendr$   )
field_namekwlistblank_fieldsnull_fieldss     r   get_kwargs_str#_ogrinspect.<locals>.get_kwargs_str   s\    ,MM+&-MM,'$))F+++r!   zF# This is an auto-generated Django model module created by ogrinspect.z(from django.contrib.gis.db import modelsr3   zclass %s(models.Model):r   Nr   r   z@    %s = models.DecimalField(max_digits=%d, decimal_places=%d%s)z    z = models.FloatField(   )z = models.IntegerField(z = models.BigIntegerField(z = models.CharField(max_length=z = models.DateField(z = models.DateTimeField(z = models.TimeField(zUnknown field type z in zsrid=-1i  zsrid=%sz
 = models.(z%    def __str__(self): return self.%s)r   r   r   r   r   zipfield_widthsfield_precisionsfield_typesr   r   r   r   r	   r   r   r
   r   r   djangosrssrid)r   
model_namer   r   rD   r   
name_fieldimportsdecimalblanknulllayerr0   decimal_fieldsr9   r5   width	precision
field_typer   
kwargs_strr   
geom_fieldsrid_strr7   r8   r/   s                           @@@r   r%   r%      s    $ +s## -	K	,	,L
 	
 "EJ  %K 'L"7+N	 VV88
#j
0047E&&(>(>@Q@Q50
E9j !!#"#;#gF $J/
  !^3V	  4 ;A*QR.QQ:%8>
12OO<';A:ab>RR9$ 
 7"5;Z^LL;&9?ABPP7"5;Z^LLZPQQW5\ OOEJ |99 H99>>D|$$t+t#&/X
FF5
BB s   I<J)geomr   F)	rS   r   NFNTFFF)__doc__django.contrib.gis.gdalr   django.contrib.gis.gdal.fieldr   r   r   r   r   r	   r
   r    r(   r%    r!   r   <module>rX      sO    /  %PD3T 	
	JCr!   