3
(hO                 @   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j D Z d(S ))    )byrefc_int)datedatetimetime)GDALBase)GDALException)ds)
force_textc               @   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dS )Fieldz`
    This class wraps an OGR Field, and needs to be instantiated
    from a Feature object.
    c             C   s\   || _ || _tj|j|}|s&td|| _t| j | _t	| t
rX| jdkrXt| _d| _dS )zr
        Initializes on the feature object and the integer index of
        the field within the feature.
        z/Cannot create OGR Field, invalid pointer given.r   TN)_feat_indexcapiZget_feat_field_defnptrr   OGRFieldTypestype	__class__
isinstanceOFTReal	precision
OFTInteger_double)selfZfeatindexZfld_ptr r   A/tmp/pip-install-q3hcpn_q/Django/django/contrib/gis/gdal/field.py__init__   s    zField.__init__c             C   s   t | jj S )z/Returns the string representation of the Field.)strvaluestrip)r   r   r   r   __str__+   s    zField.__str__c             C   s   t j| jj| jS )z0Retrieves the Field's value as a double (float).)r   Zget_field_as_doubler   r   r   )r   r   r   r   	as_double0   s    zField.as_doubleFc             C   s,   |rt j| jj| jS t j| jj| jS dS )z*Retrieves the Field's value as an integer.N)r   Zget_field_as_integer64r   r   r   Zget_field_as_integer)r   Zis_64r   r   r   as_int4   s    zField.as_intc             C   s$   t j| jj| j}t|| jjddS )z(Retrieves the Field's value as a string.T)encodingstrings_only)r   Zget_field_as_stringr   r   r   r
   r#   )r   stringr   r   r   	as_string;   s    zField.as_stringc       	      C   s~   dd t dD \}}}}}}}tj| jj| jt|t|t|t|t|t|t|	}|rr|||||||fS tddS )zARetrieves the Field's value as a tuple of date & time components.c             S   s   g | ]
}t  qS r   )r   ).0ir   r   r   
<listcomp>B   s    z%Field.as_datetime.<locals>.<listcomp>   z:Unable to retrieve date & time information from the field.N)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}t|| jjddS )zReturns the name of this Field.T)r#   r$   )r   Zget_field_namer   r
   r   r#   )r   namer   r   r   r5   L   s    z
Field.namec             C   s   t j| jS )z$Returns the precision of this Field.)r   Zget_field_precisionr   )r   r   r   r   r   R   s    zField.precisionc             C   s   t j| jS )z#Returns the OGR type of this Field.)r   Zget_field_typer   )r   r   r   r   r   W   s    z
Field.typec             C   s   t j| 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   | j  S )z Returns the value of this Field.)r&   )r   r   r   r   r   a   s    zField.valuec             C   s   t j| jS )z Returns the width of this Field.)r   Zget_field_widthr   )r   r   r   r   widthg   s    zField.widthN)F)__name__
__module____qualname____doc__r   r    r!   r"   r&   r4   propertyr5   r   r   r6   r   r7   r   r   r   r   r      s   
r   c               @   s,   e Zd ZdZdZedd Zedd ZdS )r   Fc             C   s"   | j rt| j S | j| jS dS )z+Returns an integer contained in this field.N)r   intr!   r"   _bit64)r   r   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)r8   r9   r:   r   r>   r<   r   r   r   r   r   r   r   n   s   
r   c               @   s   e Zd Zedd ZdS )r   c             C   s   | j  S )z(Returns a float contained in this field.)r!   )r   r   r   r   r      s    zOFTReal.valueN)r8   r9   r:   r<   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdS )	OFTStringN)r8   r9   r:   r   r   r   r   r?      s   r?   c               @   s   e Zd ZdS )OFTWideStringN)r8   r9   r:   r   r   r   r   r@      s   r@   c               @   s   e Zd ZdS )	OFTBinaryN)r8   r9   r:   r   r   r   r   rA      s   rA   c               @   s   e Zd Zedd ZdS )OFTDatec             C   sF   y(| j  \}}}}}}}t|j|j|jS  ttfk
r@   dS X dS )z5Returns a Python `date` object for the OFTDate field.N)r4   r   r   
ValueErrorr   )r   r,   r-   r.   r/   r0   r1   r2   r   r   r   r      s
    zOFTDate.valueN)r8   r9   r:   r<   r   r   r   r   r   rB      s   rB   c               @   s   e Zd Zedd ZdS )OFTDateTimec             C   sR   y4| j  \}}}}}}}t|j|j|j|j|j|jS  ttfk
rL   dS X dS )z>Returns a Python `datetime` object for this OFTDateTime field.N)r4   r   r   rC   r   )r   r,   r-   r.   r/   r0   r1   r2   r   r   r   r      s
    zOFTDateTime.valueN)r8   r9   r:   r<   r   r   r   r   r   rD      s   rD   c               @   s   e Zd Zedd ZdS )OFTTimec             C   sF   y(| j  \}}}}}}}t|j|j|jS  ttfk
r@   dS X dS )z6Returns a Python `time` object for this OFTTime field.N)r4   r   r   rC   r   )r   r,   r-   r.   r/   r0   r1   r2   r   r   r   r      s
    zOFTTime.valueN)r8   r9   r:   r<   r   r   r   r   r   rE      s   rE   c               @   s   e Zd ZdZdS )OFTInteger64TN)r8   r9   r:   r>   r   r   r   r   rF      s   rF   c               @   s   e Zd ZdS )OFTIntegerListN)r8   r9   r:   r   r   r   r   rG      s   rG   c               @   s   e Zd ZdS )OFTRealListN)r8   r9   r:   r   r   r   r   rH      s   rH   c               @   s   e Zd ZdS )OFTStringListN)r8   r9   r:   r   r   r   r   rI      s   rI   c               @   s   e Zd ZdS )OFTWideStringListN)r8   r9   r:   r   r   r   r   rJ      s   rJ   c               @   s   e Zd ZdS )OFTInteger64ListN)r8   r9   r:   r   r   r   r   rK      s   rK   )r                     r*      	   
            c             C   s   i | ]\}}||qS r   r   )r'   numclsr   r   r   
<dictcomp>   s    rZ   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?   r@   rA   rB   rD   rE   rF   rG   rH   rI   rJ   rK   r   itemsZROGRFieldTypesr   r   r   r   <module>   sF   `