o
    <g                     @   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capiget_feat_field_defnptrr   OGRFieldTypestype	__class__)selffeatindexfld_ptr r   P/var/www/html/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   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   get_field_as_integer64r   r   r   get_field_as_integer)r   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encodingstrings_only)r    r   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   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   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   get_field_namer   r
   r   r(   )r   namer   r   r   r>   e   s   z
Field.namec                 C      t | jS )z#Return the precision of this Field.)r   get_field_precisionr   r   r   r   r   	precisionk      zField.precisionc                 C   r?   )z"Return the OGR type of this Field.)r   get_field_typer   r   r   r   r   r   p   rB   z
Field.typec                 C   r?   )z.Return the OGR field type name for this Field.)r   get_field_type_namer   r   r   r   r   	type_nameu   rB   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   r?   )zReturn the width of this Field.)r   get_field_widthr   r   r   r   r   width   rB   zField.widthN)F)__name__
__module____qualname____doc__r   r   r"   r&   r,   r;   propertyr    r>   rA   r   rE   r   rH   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      rB   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)rI   rJ   rK   rO   rM   r   r   r   r   r   r   rN      s    
rN   c                   @      e Zd Zedd ZdS )OFTRealc                 C   rF   )z'Return a float contained in this field.)r"   r   r   r   r   r      s   zOFTReal.valueNrI   rJ   rK   rM   r   r   r   r   r   rQ          rQ   c                   @      e Zd ZdS )	OFTStringNrI   rJ   rK   r   r   r   r   rU          rU   c                   @   rT   )OFTWideStringNrV   r   r   r   r   rX      rW   rX   c                   @   rT   )	OFTBinaryNrV   r   r   r   r   rY      rW   rY   c                   @   rP   )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)r;   r   r   	TypeError
ValueErrorr   r   r3   r4   r5   r6   r7   r8   r9   r   r   r   r      s   zOFTDate.valueNrR   r   r   r   r   rZ      rS   rZ   c                   @   rP   )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)r;   r   r   r[   r\   r   r]   r   r   r   r      s    zOFTDateTime.valueNrR   r   r   r   r   r^      rS   r^   c                   @   rP   )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)r;   r   r   r\   r   r]   r   r   r   r      s   zOFTTime.valueNrR   r   r   r   r   r_      rS   r_   c                   @   s   e Zd ZdZdS )OFTInteger64TN)rI   rJ   rK   rO   r   r   r   r   r`      s    r`   c                   @   rT   )OFTIntegerListNrV   r   r   r   r   ra      rW   ra   c                   @   rT   )OFTRealListNrV   r   r   r   r   rb      rW   rb   c                   @   rT   )OFTStringListNrV   r   r   r   r   rc      rW   rc   c                   @   rT   )OFTWideStringListNrV   r   r   r   r   rd      rW   rd   c                   @   rT   )OFTInteger64ListNrV   r   r   r   r   re      rW   re   )r                     r0      	   
            c                 C   s   i | ]\}}||qS r   r   )r-   numclsr   r   r   
<dictcomp>   s    rt   N)!ctypesr   r   r   r   r   django.contrib.gis.gdal.baser   django.contrib.gis.gdal.errorr   "django.contrib.gis.gdal.prototypesr	   r   django.utils.encodingr
   r   rN   rQ   rU   rX   rY   rZ   r^   r_   r`   ra   rb   rc   rd   re   r   itemsROGRFieldTypesr   r   r   r   <module>   sJ    y