
    g                     v    d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z d dl	mZ d dlmZmZ  G d d	e      Zy
)    )GDALBase)GDALException)Field)OGRGeometryOGRGeomType)ds)geom)force_bytes	force_strc                       e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zed        Zed        Zed	        Zed
        Zed        Zed        Zed        Zd Zd Zy)Featureza
    This class that wraps an OGR Feature, needs to be instantiated
    from a Layer object.
    c                 :    |st        d      || _        || _        y)zI
        Initialize Feature from a pointer and its Layer object.
        z1Cannot create OGR Feature, invalid pointer given.N)r   ptr_layer)selffeatlayers      w/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/gis/gdal/feature.py__init__zFeature.__init__   s!      STT    c                     t        |t              r| j                  |      }n)d|cxk  r| j                  k  rn n|}nt	        d|z        t        | |      S )a.  
        Get the Field object at the specified index, which may be either
        an integer or the Field's string label.  Note that the Field object
        is not the field's _value_ -- use the `get` method instead to
        retrieve the value (e.g. an integer) instead of a Field instance.
        r   z9Index out of range when accessing field in a feature: %s.)
isinstancestrindex
num_fields
IndexErrorr   )r   r   is      r   __getitem__zFeature.__getitem__   sU     eS!

5!A%)$//)AKeS  T1~r   c                     | j                   S )z+Return the count of fields in this feature.)r   r   s    r   __len__zFeature.__len__0   s    r   c                 8    d| j                   | j                  fz  S )zThe string name of the feature.zFeature FID %d in Layer<%s>)fid
layer_namer    s    r   __str__zFeature.__str__4   s    ,$///JJJr   c                 h    t        t        j                  | j                  |j                              S )z'Do equivalence testing on the features.)boolcapifeature_equalr   _ptr)r   others     r   __eq__zFeature.__eq__8   s"    D&&txx<==r   c                 B    | j                   j                  j                  S )N)r   _dsencodingr    s    r   r/   zFeature.encoding=   s    {{'''r   c                 @    t        j                  | j                        S )zReturn the feature identifier.)r(   get_fidr   r    s    r   r#   zFeature.fidA   s     ||DHH%%r   c                     t        j                  | j                  j                        }t	        || j
                  d      S )z-Return the name of the layer for the feature.Tstrings_only)r(   get_feat_namer   _ldefnr   r/   )r   names     r   r$   zFeature.layer_nameF   s1     !!$++"4"45t}}4@@r   c                 @    t        j                  | j                        S )z+Return the number of fields in the Feature.)r(   get_feat_field_countr   r    s    r   r   zFeature.num_fieldsL   s     ((22r   c                     t        | j                        D cg c]U  }t        t        j                  t        j
                  | j                  j                  |            | j                  d      W c}S c c}w )z'Return a list of fields in the Feature.Tr3   )	ranger   r   r(   get_field_nameget_field_defnr   r6   r/   )r   r   s     r   fieldszFeature.fieldsQ   sj     4??+
 , ##D$7$78J8JA$NO!
 ,
 	
 
s   AA5c                 |    t        j                  | j                        }t        t	        j
                  |            S )z)Return the OGR Geometry for this Feature.)r(   get_feat_geom_refr   r   geom_api
clone_geom)r   geom_ptrs     r   r	   zFeature.geom]   s.     ))$((38..x899r   c                 f    t        t        j                  | j                  j                              S )z.Return the OGR Geometry Type for this Feature.)r   r(   get_fd_geom_typer   r6   r    s    r   	geom_typezFeature.geom_typed   s$     4001C1CDEEr   c                 :    t        |d|      }| |   j                  S )z
        Return the value of the field, instead of an instance of the Field
        object.  May take a string of the field name or a Field object as
        parameters.
        r7   )getattrvalue)r   field
field_names      r   getzFeature.getj   s#     UFE2
J%%%r   c                 ~    t        j                  | j                  t        |            }|dk  rt	        d|z        |S )z)Return the index of the given field name.r   z!Invalid OFT field name given: %s.)r(   get_field_indexr   r
   r   )r   rK   r   s      r   r   zFeature.indexs   s:      ;z+BCq5@:MNNr   N)__name__
__module____qualname____doc__r(   destroy_feature
destructorr   r   r!   r%   r,   propertyr/   r#   r$   r   r>   r	   rF   rL   r    r   r   r   r      s    
 %%J"K>
 ( ( & & A A
 3 3 	
 	
 : : F F
&r   r   N)django.contrib.gis.gdal.baser   django.contrib.gis.gdal.errorr   django.contrib.gis.gdal.fieldr   "django.contrib.gis.gdal.geometriesr   r   "django.contrib.gis.gdal.prototypesr   r(   r	   rA   django.utils.encodingr
   r   r   rV   r   r   <module>r]      s(    1 7 / G 9 ? 8jh jr   