U
    d                     @   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   A/tmp/pip-unpacked-wheel-7vj2equ7/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 r8t| jj| jS d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dS )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   s   t | jS )z#Return the precision of this Field.)r   Zget_field_precisionr   r   r   r   r   	precisionk   s    zField.precisionc                 C   s   t | jS )z"Return the OGR type of this Field.)r   Zget_field_typer   r   r   r   r   r   p   s    z
Field.typec                 C   s   t | jS )z.Return the OGR field type name for this Field.)r   Zget_field_type_namer   r   r   r   r   	type_nameu   s    zField.type_namec                 C   s   |   S )zReturn the value of this Field.)r#   r   r   r   r   r   z   s    zField.valuec                 C   s   t | jS )zReturn the width of this Field.)r   Zget_field_widthr   r   r   r   r   width   s    zField.widthN)F)__name__
__module____qualname____doc__r   r   r   r   r#   r1   propertyr   r2   r3   r   r4   r   r5   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      s    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)r6   r7   r8   r<   r:   r   r   r   r   r   r   r;      s
   
r;   c                   @   s   e Zd Zedd ZdS )OFTRealc                 C   s   |   S )z'Return a float contained in this field.)r   r   r   r   r   r      s    zOFTReal.valueNr6   r7   r8   r:   r   r   r   r   r   r=      s   r=   c                   @   s   e Zd ZdS )	OFTStringNr6   r7   r8   r   r   r   r   r?      s   r?   c                   @   s   e Zd ZdS )OFTWideStringNr@   r   r   r   r   rA      s   rA   c                   @   s   e Zd ZdS )	OFTBinaryNr@   r   r   r   r   rB      s   rB   c                   @   s   e Zd Zedd ZdS )OFTDatec              
   C   sL   z*|   \}}}}}}}t|j|j|jW S  tttfk
rF   Y dS X dS )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.valueNr>   r   r   r   r   rC      s   rC   c                   @   s   e Zd Zedd ZdS )OFTDateTimec              
   C   sX   z6|   \}}}}}}}t|j|j|j|j|j|jW S  tttfk
rR   Y dS X dS )z=Return a Python `datetime` object for this OFTDateTime field.N)r1   r   r   rD   rE   r   rF   r   r   r   r      s
     zOFTDateTime.valueNr>   r   r   r   r   rG      s   rG   c                   @   s   e Zd Zedd ZdS )OFTTimec              	   C   sJ   z*|   \}}}}}}}t|j|j|jW S  ttfk
rD   Y dS X dS )z5Return a Python `time` object for this OFTTime field.N)r1   r   r   rE   r   rF   r   r   r   r      s
    zOFTTime.valueNr>   r   r   r   r   rH      s   rH   c                   @   s   e Zd ZdZdS )OFTInteger64TN)r6   r7   r8   r<   r   r   r   r   rI      s   rI   c                   @   s   e Zd ZdS )OFTIntegerListNr@   r   r   r   r   rJ      s   rJ   c                   @   s   e Zd ZdS )OFTRealListNr@   r   r   r   r   rK      s   rK   c                   @   s   e Zd ZdS )OFTStringListNr@   r   r   r   r   rL      s   rL   c                   @   s   e Zd ZdS )OFTWideStringListNr@   r   r   r   r   rM      s   rM   c                   @   s   e Zd ZdS )OFTInteger64ListNr@   r   r   r   r   rN      s   rN   )r                     r'      	   
            c                 C   s   i | ]\}}||qS r   r   )r$   numclsr   r   r   
<dictcomp>   s      r]   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;   r=   r?   rA   rB   rC   rG   rH   rI   rJ   rK   rL   rM   rN   r   itemsZROGRFieldTypesr   r   r   r   <module>   sH   y