U
    Haã  ã                   @   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-3jxiddxt/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_int.   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_string5   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>@   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_datetime<   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   J   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   O   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   Ú	precisionU   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   Z   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_name_   s    zField.type_namec                 C   s   |   ¡ S )zReturn the value of this Field.)r#   r   r   r   r   r   d   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   Úwidthj   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   t   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   y   s    zOFTInteger.typeN)r6   r7   r8   r<   r:   r   r   r   r   r   r   r;   q   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   cñ