§
    ¤”jÒ#  ã                   ób   — 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dS )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ÚOFTTimeÚgeomFc                 ó¤  — t          | t          ¦  «        rt          | ¦  «        } n%t          | t          ¦  «        rnt          d¦  «        ‚i }| |         j        D ].}|                     ¦   «         }|dd…         dk    r|dz  }|||<   Œ/| |         j        }|r|                     ¦   «          t          |¦  «                             ¦   «         ||<   |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           úr/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/django/contrib/gis/utils/ogrinspect.pyÚmappingr!      sì   € õ �+�sÑ#Ô#ð 
å  Ñ-Ô-ˆˆÝ	�K¥Ñ	,Ô	,ð 
ØåØLñ
ô 
ð 	
ð
 €Hð ˜YÔ'Ô.ð !ð !ˆØ—’‘”ˆØ�"�#�#Œ;˜#ÒÐØ�gÑˆFØ ˆ�ÑÐØ˜	Ô"Ô,€EØð Ø�ŠÑÔÐÝ˜e™*œ*×*Ò*Ñ,Ô,€HˆYÑØ€Oó    c                  ó@   — d                      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Ð1Ñ2Ô2Ð2r"   NTc              #   óâ  ‡‡‡K  — t          | t          ¦  «        rt          | ¦  «        } n%t          | t          ¦  «        rnt          d¦  «        ‚| |         }|j        Šˆfd„} ||
¦  «        Š ||	¦  «        Š ||¦  «        }ˆˆfd„}|rdV — dV — dV — dV — d|z  V — t          ‰|j        |j        |j        ¦  «        D �]6\  }}}}| 	                    ¦   «         }|dd	…         d
k    r|dz  } ||¦  «        }|t          u r6| 	                    ¦   «         |v rd||||fz  V — Œed|›d|dd	…         ›d�V — Œy|t          u rd|›d|dd	…         ›d�V — Œ–|t          u rd|›d|dd	…         ›d�V — Œ³|t          u rd|›d|›|›d�V — ŒÊ|t          u rd|›d|dd	…         ›d�V — Œç|t          u rd|›d|dd	…         ›d�V — �Œ|t           u rd|›d|dd	…         ›d�V — �Œ#t          d|›d|›�¦  «        ‚|j        }|r|                     ¦   «          |j        }|€*|j        €d}n%|j        j        }|€d}n|dk    rd}nd|z  }nd|z  }d|›d|›d|›d�V — |rdV — d|z  V — d	S d	S )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          t          f¦  «        rd„ | D ¦   «         S | rd„ ‰D ¦   «         S g S )Nc                 ó6   — g | ]}|                      ¦   «         ‘ŒS © ©r   ©Ú.0Úss     r    ú
<listcomp>z6_ogrinspect.<locals>.process_kwarg.<locals>.<listcomp>¦   s    € Ð-Ð-Ð- !�A—G’G‘I”IÐ-Ð-Ð-r"   c                 ó6   — g | ]}|                      ¦   «         ‘ŒS r-   r.   r/   s     r    r2   z6_ogrinspect.<locals>.process_kwarg.<locals>.<listcomp>¨   s    € Ð2Ð2Ð2 !�A—G’G‘I”IÐ2Ð2Ð2r"   )r   ÚlistÚtuple)ÚkwargÚ
ogr_fieldss    €r    Úprocess_kwargz"_ogrinspect.<locals>.process_kwarg¤   sN   ø€ Ý�e�d¥E˜]Ñ+Ô+ð 	Ø-Ð- uÐ-Ñ-Ô-Ð-Øð 	Ø2Ð2 zÐ2Ñ2Ô2Ð2àˆIr"   c                 óì   •— g }|                       ¦   «         ‰v r|                     d¦  «         |                       ¦   «         ‰v r|                     d¦  «         |rdd                     |¦  «        z   S dS )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Ñ+Ô+Ñ+Ð+à�2r"   zF# This is an auto-generated Django model module created by ogrinspect.z(from django.contrib.gis.db import modelsr:   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   rJ   r   Ú
name_fieldÚimportsÚdecimalÚblankÚnullÚlayerr8   Údecimal_fieldsr@   r<   ÚwidthÚ	precisionÚ
field_typer   Ú
kwargs_strr   Ú
geom_fieldÚsrid_strr>   r?   r7   s                           @@@r    r&   r&   ‚   s'  øøøè è € õ$ �+�sÑ#Ô#ð 
Ý  Ñ-Ô-ˆˆÝ	�K¥Ñ	,Ô	,ð 
ØåØLñ
ô 
ð 	
ð ˜	Ô"€EØ”€Jðð ð ð ð ð  �- Ñ%Ô%€KØ �= Ñ'Ô'€LØ"�] 7Ñ+Ô+€Nð	ð 	ð 	ð 	ð 	ð 	ð ð ØVÐVÐVÐVØ8Ð8Ð8Ð8ØˆˆˆØˆˆˆà
# jÑ
0Ð0Ð0Ð0å47Ø�EÔ&¨Ô(>ÀÔ@Qñ5ô 5ð +Rñ +RÑ0ˆ
�E˜9 jð ×!Ò!Ñ#Ô#ˆØ�"�#�#Œ;˜#ÒÐØ�gÑˆFð $�^ JÑ/Ô/ˆ
à�Ð Ð ð ×ÒÑ!Ô! ^Ð3Ð3àVàØØØð	ñð ð ð ð ð 4ð ;A¸&¸&À*ÈQÈRÈRÄ.À.À.ÐQÐQÐQÐQÐQØ�:Ð%Ð%Ð%Ø8>¸¸À
È1È2È2ÄÀÀÐOÐOÐOÐOÐOØ�<Ð'Ð'Ð'Ø;A¸6¸6À:ÈaÈbÈbÄ>À>À>ÐRÐRÐRÐRÐRØ�9Ð$Ð$Ð$à��Ø�Ø�
�
ðð ð ð ð ð
 �7Ð"Ð"Ð"Ø5;°V°V¸ZÈÈÈ¼^¸^¸^ÐLÐLÐLÐLÐLØ�;Ð&Ð&Ð&Ø9?¸¸ÀÈAÈBÈBÄÀÀÐPÐPÐPÐPÑPØ�7Ð"Ð"Ð"Ø5;°V°V¸ZÈÈÈ¼^¸^¸^ÐLÐLÐLÐLÑLå�)¸Z¸Z¸ZÈÈÐPÑQÔQÐQð ŒO€EØð Ø�ŠÑÔÐØ”€Jð €|ØŒ9ÐØ ˆHˆHà”9”>ˆDØˆ|Ø$��Ø˜’�à��à$ tÑ+��à˜tÑ#ˆøà&/ i i°°°¸X¸X¸XÐ
FÐFÐFÐFàð CØˆˆˆØ5¸
ÑBÐBÐBÐBÐBÐBðCð Cr"   )r   r   F)	r   r   NFNTFFF)Ú__doc__Údjango.contrib.gis.gdalr   Údjango.contrib.gis.gdal.fieldr   r   r   r   r   r	   r
   r!   r)   r&   r-   r"   r    ú<module>r\      sì   ððð ð /Ð .Ð .Ð .Ð .Ð .ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð%ð %ð %ð %ðPD3ð D3ð D3ðT ØØ	ØØØØØ
Ø	ðJCð JCð JCð JCð JCð JCr"   