o
    [h                     @   s|  d dl mZmZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ G dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZeeeeeeeeeeeeeed%Zd&d' e D Z d(S ))    )byrefc_int)datedatetimetime)GDALBase)GDALException)ds)	force_strc                   @   s   e Zd ZdZdd Zdd Zdd Zd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S )FieldzL
    Wrap an OGR Field. Needs to be instantiated from a Feature object.
    c                 C   s<   || _ || _t|j|}|std|| _t| j | _dS )zq
        Initialize on the feature object and the integer index of
        the field within the feature.
        z/Cannot create OGR Field, invalid pointer given.N)	_feat_indexcapiZget_feat_field_defnptrr   OGRFieldTypestype	__class__)selfZfeatindexZfld_ptr r   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/contrib/gis/gdal/field.py__init__   s   zField.__init__c                 C   s   t | j S )z.Return the string representation of the Field.)strvaluestripr   r   r   r   __str__%   s   zField.__str__c                 C   s   | j rt| jj| jS dS )z/Retrieve the Field's value as a double (float).N)is_setr   Zget_field_as_doubler   r   r   r   r   r   r   	as_double*   s
   zField.as_doubleFc                 C   s<   |r| j rt| jj| jS dS | j rt| jj| jS dS )z)Retrieve the Field's value as an integer.N)r   r   Zget_field_as_integer64r   r   r   Zget_field_as_integer)r   Zis_64r   r   r   as_int2   s   zField.as_intc                 C   s.   | j sdS t| jj| j}t|| jjddS )z'Retrieve the Field's value as a string.NTencodingZstrings_only)r   r   Zget_field_as_stringr   r   r   r
   r!   )r   stringr   r   r   	as_stringA   s   zField.as_stringc           	      C   s   | j sdS dd tdD \}}}}}}}t| jj| jt|t|t|t|t|t|t|	}|r>|||||||fS td)z@Retrieve the Field's value as a tuple of date & time components.Nc                 S   s   g | ]}t  qS r   )r   ).0ir   r   r   
<listcomp>L   s    z%Field.as_datetime.<locals>.<listcomp>   z:Unable to retrieve date & time information from the field.)	r   ranger   Zget_field_as_datetimer   r   r   r   r   )	r   yymmddhhmnsstzstatusr   r   r   as_datetimeH   s&    zField.as_datetimec                 C   s   t | jj| jS )zCReturn True if the value of this field isn't null, False otherwise.)r   Zis_field_setr   r   r   r   r   r   r   r   `   s   zField.is_setc                 C   s   t | j}t|| jjddS )zReturn the name of this Field.Tr    )r   Zget_field_namer   r
   r   r!   )r   namer   r   r   r2   e   s   z
Field.namec                 C      t | jS )z#Return the precision of this Field.)r   Zget_field_precisionr   r   r   r   r   	precisionk      zField.precisionc                 C   r3   )z"Return the OGR type of this Field.)r   Zget_field_typer   r   r   r   r   r   p   r5   z
Field.typec                 C   r3   )z.Return the OGR field type name for this Field.)r   Zget_field_type_namer   r   r   r   r   	type_nameu   r5   zField.type_namec                 C      |   S )zReturn the value of this Field.)r#   r   r   r   r   r   z   s   zField.valuec                 C   r3   )zReturn the width of this Field.)r   Zget_field_widthr   r   r   r   r   width   r5   zField.widthN)F)__name__
__module____qualname____doc__r   r   r   r   r#   r1   propertyr   r2   r4   r   r6   r   r8   r   r   r   r   r      s,    






r   c                   @   s(   e Zd ZdZedd Zedd ZdS )
OFTIntegerFc                 C   s   |  | jS )z*Return an integer contained in this field.)r   _bit64r   r   r   r   r      r5   zOFTInteger.valuec                 C   s   dS )z
        GDAL uses OFTReals to represent OFTIntegers in created
        shapefiles -- forcing the type here since the underlying field
        type may actually be OFTReal.
        r   r   r   r   r   r   r      s   zOFTInteger.typeN)r9   r:   r;   r?   r=   r   r   r   r   r   r   r>      s    
r>   c                   @      e Zd Zedd ZdS )OFTRealc                 C   r7   )z'Return a float contained in this field.)r   r   r   r   r   r      s   zOFTReal.valueNr9   r:   r;   r=   r   r   r   r   r   rA          rA   c                   @      e Zd ZdS )	OFTStringNr9   r:   r;   r   r   r   r   rE          rE   c                   @   rD   )OFTWideStringNrF   r   r   r   r   rH      rG   rH   c                   @   rD   )	OFTBinaryNrF   r   r   r   r   rI      rG   rI   c                   @   r@   )OFTDatec              
   C   sF   z|   \}}}}}}}t|j|j|jW S  tttfy"   Y dS w )z4Return a Python `date` object for the OFTDate field.N)r1   r   r   	TypeError
ValueErrorr   r   r)   r*   r+   r,   r-   r.   r/   r   r   r   r      s   zOFTDate.valueNrB   r   r   r   r   rJ      rC   rJ   c                   @   r@   )OFTDateTimec              
   C   sR   z|   \}}}}}}}t|j|j|j|j|j|jW S  tttfy(   Y dS w )z=Return a Python `datetime` object for this OFTDateTime field.N)r1   r   r   rK   rL   r   rM   r   r   r   r      s    zOFTDateTime.valueNrB   r   r   r   r   rN      rC   rN   c                   @   r@   )OFTTimec              	   C   sD   z|   \}}}}}}}t|j|j|jW S  ttfy!   Y dS w )z5Return a Python `time` object for this OFTTime field.N)r1   r   r   rL   r   rM   r   r   r   r      s   zOFTTime.valueNrB   r   r   r   r   rO      rC   rO   c                   @   s   e Zd ZdZdS )OFTInteger64TN)r9   r:   r;   r?   r   r   r   r   rP      s    rP   c                   @   rD   )OFTIntegerListNrF   r   r   r   r   rQ      rG   rQ   c                   @   rD   )OFTRealListNrF   r   r   r   r   rR      rG   rR   c                   @   rD   )OFTStringListNrF   r   r   r   r   rS      rG   rS   c                   @   rD   )OFTWideStringListNrF   r   r   r   r   rT      rG   rT   c                   @   rD   )OFTInteger64ListNrF   r   r   r   r   rU      rG   rU   )r                     r'      	   
            c                 C   s   i | ]\}}||qS r   r   )r$   numclsr   r   r   
<dictcomp>   s    rd   N)!ctypesr   r   r   r   r   Zdjango.contrib.gis.gdal.baser   Zdjango.contrib.gis.gdal.errorr   Z"django.contrib.gis.gdal.prototypesr	   r   Zdjango.utils.encodingr
   r   r>   rA   rE   rH   rI   rJ   rN   rO   rP   rQ   rR   rS   rT   rU   r   itemsZROGRFieldTypesr   r   r   r   <module>   sJ    y