
    Dvg                     ~    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d
S )    )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dS )Featureza
    This class that wraps an OGR Feature, needs to be instantiated
    from a Layer object.
    c                 D    |st          d          || _        || _        dS )zI
        Initialize Feature from a pointer and its Layer object.
        z1Cannot create OGR Feature, invalid pointer given.N)r   ptr_layer)selffeatlayers      \/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/gis/gdal/feature.py__init__zFeature.__init__   s.      	U STTT    c                     t          |t                    r|                     |          }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__   s~     eS!! 	

5!!AA%))))$/)))))AA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                 $    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                 Z    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&tx<<===r   c                 $    | j         j        j        S )N)r   _dsencodingr    s    r   r/   zFeature.encoding=   s    {''r   c                 4    t          j        | j                  S )zReturn the feature identifier.)r(   get_fidr   r    s    r   r#   zFeature.fidA   s     |DH%%%r   c                 l    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   s0     !$+"455t}4@@@@r   c                 4    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22r   c                 D      fdt           j                  D             S )z'Return a list of fields in the Feature.c           
          g | ]H}t          t          j        t          j        j        j        |                    j        d           IS )Tr3   )r   r(   get_field_nameget_field_defnr   r6   r/   ).0r   r   s     r   
<listcomp>z"Feature.fields.<locals>.<listcomp>T   sb     
 
 
  #D$78JA$N$NOO!  
 
 
r   )ranger   r    s   `r   fieldszFeature.fieldsQ   s:    
 
 
 
 4?++
 
 
 	
r   c                 v    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38.x88999r   c                 X    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1CDDE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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   rN   r   s      r   r   zFeature.indexs   s@     ;z+B+BCCq55@:MNNNr   N)__name__
__module____qualname____doc__r(   destroy_feature
destructorr   r   r!   r%   r,   propertyr/   r#   r$   r   rA   r	   rI   rO   r    r   r   r   r      sW        
 %J    "  K K K> > >
 ( ( X( & & X& A A XA
 3 3 X3 	
 	
 X	
 : : X: F F X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	   rD   django.utils.encodingr
   r   r   rY   r   r   <module>r`      s    1 1 1 1 1 1 7 7 7 7 7 7 / / / / / / G G G G G G G G 9 9 9 9 9 9 ? ? ? ? ? ? 8 8 8 8 8 8 8 8j j j j jh j j j j jr   