Ë
    ¹ûàgÒ#  ã                   ó`   — d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 dd„Zd„ Z	 	 	 	 	 	 	 	 	 d	d„Zy)
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                 ó`  — t        | t        «      rt        | «      } nt        | t        «      rnt        d«      ‚i }| |   j                  D ]$  }|j                  «       }|dd dk(  r|dz  }|||<   Œ& | |   j                  }|r|j                  «        t        |«      j                  «       ||<   |S )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           úa/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django/contrib/gis/utils/ogrinspect.pyÚmappingr       sÀ   € ô �+œsÔ#ä  Ó-‰Ü	�K¤Ô	,ØäØLó
ð 	
ð
 €Hð ˜YÑ'×.Ñ.ò !ˆØ—‘“ˆØ�"�#ˆ;˜#ÒØ�gÑˆFØ ˆ�Òð	!ð
 ˜	Ñ"×,Ñ,€EÙØ�‰ÔÜ˜e›*×*Ñ*Ó,€HˆYÑØ€Oó    c                  ó6   — dj                  t        | i |¤Ž«      S )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 �9‰9”[ $Ð1¨&Ñ1Ó2Ð2r!   Nc              #   óx  ‡‡‡K  — t        | t        «      rt        | «      } nt        | t        «      rnt        d«      ‚| |   }|j                  Šˆfd„} ||
«      Š ||	«      Š ||«      }ˆˆfd„}|rd–— d–— d–— d–— d|z  –— t        ‰|j                  |j                  |j                  «      D ]ú  \  }}}}|j                  «       }|dd	 d
k(  r|dz  } ||«      }|t        u r-|j                  «       |v rd||||fz  –— ŒSd|›d|dd	 ›d�–— Œb|t        u rd|›d|dd	 ›d�–— Œy|t        u rd|›d|dd	 ›d�–— Œ�|t        u rd|›d|›|›d�–— Œ¦|t        u rd|›d|dd	 ›d�–— Œ½|t        u rd|›d|dd	 ›d�–— ŒÔ|t         u rd|›d|dd	 ›d�–— Œët        d|›d|›�«      ‚ |j"                  }|r|j%                  «        |j&                  }|€8|j(                  €d}n.|j(                  j*                  }|€d}n|dk(  rd}nd|z  }nd|z  }d|›d|›d|›d�–— |rd–— d|z  –— y	y	­w)z§
    Helper routine for `ogrinspect` that generates GeoDjango models corresponding
    to the given data source.  See the `ogrinspect` docstring for more details.
    r   c                 óÄ   •— t        | t        t        f«      r| D �cg c]  }|j                  «       ‘Œ c}S | r‰D �cg c]  }|j                  «       ‘Œ c}S g S c c}w c c}w )N)r   ÚlistÚtupler   )ÚkwargÚsÚ
ogr_fieldss     €r   Úprocess_kwargz"_ogrinspect.<locals>.process_kwarg¤   sO   ø€ Ü�eœd¤E˜]Ô+Ø',Ö- !�A—G‘G•IÒ-Ð-ÙØ'1Ö2 !�A—G‘G•IÒ2Ð2àˆIùò	 .ùâ2s
   œA¼Ac                 óÂ   •— g }| j                  «       ‰v r|j                  d«       | j                  «       ‰v r|j                  d«       |rddj                  |«      z   S y)Nz	null=Truez
blank=Truez, Ú )r   Úappendr$   )Ú
field_nameÚkwlistÚblank_fieldsÚnull_fieldss     €€r   Úget_kwargs_strz#_ogrinspect.<locals>.get_kwargs_str±   s\   ø€ ØˆØ×ÑÓ Ñ,Ø�M‰M˜+Ô&Ø×ÑÓ Ñ-Ø�M‰M˜,Ô'ÙØ˜$Ÿ)™) FÓ+Ñ+Ð+àr!   zF# This is an auto-generated Django model module created by ogrinspect.z(from django.contrib.gis.db import modelsr2   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   rB   r   Ú
name_fieldÚimportsÚdecimalÚblankÚnullÚlayerr0   Údecimal_fieldsr8   r4   ÚwidthÚ	precisionÚ
field_typer   Ú
kwargs_strr   Ú
geom_fieldÚsrid_strr6   r7   r/   s                           @@@r   r%   r%   ‚   sŸ  úè ø€ ô$ �+œsÔ#Ü  Ó-‰Ü	�K¤Ô	,ØäØLó
ð 	
ð ˜	Ñ"€EØ—‘€Jôñ   Ó%€KÙ  Ó'€LÙ" 7Ó+€Nõ	ñ ØVÒVØ8Ò8ØŠØŠà
# jÑ
0Ò0ä47Ø�E×&Ñ&¨×(>Ñ(>À×@QÑ@Qó5ò +RÑ0ˆ
�E˜9 jð ×!Ñ!Ó#ˆØ�"�#ˆ;˜#ÒØ�gÑˆFñ $ JÓ/ˆ
àœÑ ð ×ÑÓ! ^Ñ3àVàØØØð	ñó ð 4ò ;AÀ*ÈQÈRÂ.ÐQÓQØœ:Ò%Ú8>À
È1È2ÂÐOÓOØœ<Ò'Ú;AÀ:ÈaÈbÂ>ÐRÓRØœ9Ò$âÙÚðó ð
 œ7Ò"Ú5;¸ZÈÈº^ÐLÓLØœ;Ò&Ú9?ÀÈAÈBÂÐPÓPØœ7Ò"Ú5;¸ZÈÈº^ÐLÓLåºZÉÐPÓQÐQðW+Rð\ �O‰O€EÙØ�‰ÔØ—‘€Jð €|Ø�9‰9ÐØ ‰Hà—9‘9—>‘>ˆDØˆ|Ø$‘Ø˜’à‘à$ tÑ+‘à˜tÑ#ˆøâ&/²ºXÐ
FÒFáØŠØ5¸
ÑBÓBð ùs   …H5H:)Úgeomr   F)	rQ   r   NFNTFFF)Ú__doc__Údjango.contrib.gis.gdalr   Údjango.contrib.gis.gdal.fieldr   r   r   r   r   r	   r
   r    r(   r%   © r!   r   ú<module>rV      sO   ðñõ /÷÷ ñ ó%òPD3ðT ØØ	ØØØØØ
Ø	ôJCr!   