o
    þÞh±  ã                   @   sp   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	„ d	eƒZd
S )é    )ÚGDALBase)ÚGDALException)ÚField)ÚOGRGeometryÚOGRGeomType)Úds)Úgeom)Úforce_bytesÚ	force_strc                   @   s¢   e Zd ZdZejZdd„ Zdd„ Zdd„ Z	dd	„ Z
d
d„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ ZdS )ÚFeatureza
    This class that wraps an OGR Feature, needs to be instantiated
    from a Layer object.
    c                 C   s   |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Úlayer© r   ú_/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/contrib/gis/gdal/feature.pyÚ__init__   s   
zFeature.__init__c                 C   sL   t |tƒr|  |¡}nd|  kr| jk rn n|}ntd| ƒ‚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   Úir   r   r   Ú__getitem__   s   
ÿ
zFeature.__getitem__c                 C   s   | j S )z+Return the count of fields in this feature.)r   ©r   r   r   r   Ú__len__0   s   zFeature.__len__c                 C   s   d| j | jf S )zThe string name of the feature.zFeature FID %d in Layer<%s>)ÚfidÚ
layer_namer   r   r   r   Ú__str__4   s   zFeature.__str__c                 C   s   t t | j|j¡ƒS )z'Do equivalence testing on the features.)ÚboolÚcapiÚfeature_equalr   Ú_ptr)r   Úotherr   r   r   Ú__eq__8   s   zFeature.__eq__c                 C   s
   | j jjS )N)r   Ú_dsÚencodingr   r   r   r   r'   =   s   
zFeature.encodingc                 C   ó   t  | j¡S )zReturn the feature identifier.)r!   Úget_fidr   r   r   r   r   r   A   ó   zFeature.fidc                 C   s   t  | jj¡}t|| jdd�S )z-Return the name of the layer for the feature.T©Ústrings_only)r!   Úget_feat_namer   Ú_ldefnr
   r'   )r   Únamer   r   r   r   F   s   zFeature.layer_namec                 C   r(   )z+Return the number of fields in the Feature.)r!   Úget_feat_field_countr   r   r   r   r   r   L   r*   zFeature.num_fieldsc                    s   ‡ fdd„t ˆ jƒD ƒS )z'Return a list of fields in the Feature.c              	      s.   g | ]}t t t ˆ jj|¡¡ˆ jd d�‘qS )Tr+   )r
   r!   Úget_field_nameÚget_field_defnr   r.   r'   )Ú.0r   r   r   r   Ú
<listcomp>T   s    ûýÿz"Feature.fields.<locals>.<listcomp>)Úranger   r   r   r   r   ÚfieldsQ   s   
úzFeature.fieldsc                 C   s   t  | j¡}tt |¡ƒS )z)Return the OGR Geometry for this Feature.)r!   Úget_feat_geom_refr   r   Úgeom_apiÚ
clone_geom)r   Úgeom_ptrr   r   r   r   ]   s   zFeature.geomc                 C   s   t t | jj¡ƒS )z.Return the OGR Geometry Type for this Feature.)r   r!   Úget_fd_geom_typer   r.   r   r   r   r   Ú	geom_typed   s   zFeature.geom_typec                 C   s   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.
        r/   )ÚgetattrÚvalue)r   ÚfieldÚ
field_namer   r   r   Úgetj   s   
zFeature.getc                 C   s*   t  | jt|ƒ¡}|dk rtd| ƒ‚|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   r@   r   r   r   r   r   s   s   zFeature.indexN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   Údestroy_featureÚ
destructorr   r   r   r   r%   Úpropertyr'   r   r   r   r6   r   r<   rA   r   r   r   r   r   r      s0    	






	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   r8   Údjango.utils.encodingr	   r
   r   r   r   r   r   Ú<module>   s    