
v^                 @   s3  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 Gd d   d e  Z Gd	 d
   d
 e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d    d  e  Z Gd! d"   d" e  Z Gd# d$   d$ e  Z d  e d% e d& e d' e d( e d) e d* e d+ e d, e d- e d. e d/ e d0 e d1 e i Z d2 d3   e j   D Z  d4 S)5    )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   sV   | |  _  | |  _ t j | j |  } | s9 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   ?/tmp/pip-build-8lau8j11/django/django/contrib/gis/gdal/field.py__init__   s    			zField.__init__c             C   s   t  |  j  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 |  j  Sd 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   sV   | r, |  j  r( t j |  j j |  j  Sd S|  j  rN t j |  j j |  j  Sd Sd 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   sD   |  j  s d St j |  j j |  j  } t | d |  j j d d S)z'Retrieve the Field's value as a string.Nencodingstrings_onlyT)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 Sd d   t d  D \ } } } } } } } t j |  j j |  j t |  t |  t |  t |  t |  t |  t |  	 } | r | | | | | | | f St d   d S)z@Retrieve the Field's value as a tuple of date & time components.Nc             S   s   g  |  ] } t     q Sr   )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 |  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 |  j  } t | d |  j j d d S)zReturn the name of this Field.r   r    T)r   Zget_field_namer   r
   r   r   )r   namer   r   r   r1   O   s    z
Field.namec             C   s   t  j |  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 |  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 |  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Return the value of this Field.)r"   )r   r   r   r   r   d   s    zField.valuec             C   s   t  j |  j  S)zReturn the width of this Field.)r   Zget_field_widthr   )r   r   r   r   widthj   s    zField.widthN)__name__
__module____qualname____doc__r   r   r   r   r"   r0   propertyr   r1   r2   r   r3   r   r4   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  |  j  S)z*Return an integer contained in this field.)r   _bit64)r   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)r5   r6   r7   r;   r9   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
   |  j    S)z'Return a float contained in this field.)r   )r   r   r   r   r      s    zOFTReal.valueN)r5   r6   r7   r9   r   r   r   r   r   r<      s   r<   c               @   s   e  Z d  Z d S)	OFTStringN)r5   r6   r7   r   r   r   r   r=      s   r=   c               @   s   e  Z d  Z d S)OFTWideStringN)r5   r6   r7   r   r   r   r   r>      s   r>   c               @   s   e  Z d  Z d S)	OFTBinaryN)r5   r6   r7   r   r   r   r   r?      s   r?   c               @   s"   e  Z d  Z e d d    Z d S)OFTDatec             C   sd   y> |  j    \ } } } } } } } t | j | j | j  SWn t t t f k
 r_ d SYn Xd S)z4Return a Python `date` object for the OFTDate field.N)r0   r   r   	TypeError
ValueErrorr   )r   r(   r)   r*   r+   r,   r-   r.   r   r   r   r      s
    !zOFTDate.valueN)r5   r6   r7   r9   r   r   r   r   r   r@      s   r@   c               @   s"   e  Z d  Z e d d    Z d S)OFTDateTimec             C   sv   yP |  j    \ } } } } } } } t | j | j | j | j | j | j  SWn t t t f k
 rq d SYn Xd S)z=Return a Python `datetime` object for this OFTDateTime field.N)r0   r   r   rA   rB   r   )r   r(   r)   r*   r+   r,   r-   r.   r   r   r   r      s
    !/zOFTDateTime.valueN)r5   r6   r7   r9   r   r   r   r   r   rC      s   rC   c               @   s"   e  Z d  Z e d d    Z d S)OFTTimec             C   sa   y> |  j    \ } } } } } } } t | j | j | j  SWn t t f k
 r\ d SYn Xd S)z5Return a Python `time` object for this OFTTime field.N)r0   r   r   rB   r   )r   r(   r)   r*   r+   r,   r-   r.   r   r   r   r      s
    !zOFTTime.valueN)r5   r6   r7   r9   r   r   r   r   r   rD      s   rD   c               @   s   e  Z d  Z d Z d S)OFTInteger64TN)r5   r6   r7   r;   r   r   r   r   rE      s   rE   c               @   s   e  Z d  Z d S)OFTIntegerListN)r5   r6   r7   r   r   r   r   rF      s   rF   c               @   s   e  Z d  Z d S)OFTRealListN)r5   r6   r7   r   r   r   r   rG      s   rG   c               @   s   e  Z d  Z d S)OFTStringListN)r5   r6   r7   r   r   r   r   rH      s   rH   c               @   s   e  Z d  Z d S)OFTWideStringListN)r5   r6   r7   r   r   r   r   rI      s   rI   c               @   s   e  Z d  Z d S)OFTInteger64ListN)r5   r6   r7   r   r   r   r   rJ      s   rJ                     r&      	   
            c             C   s   i  |  ] \ } } | |  q Sr   r   )r#   numclsr   r   r   
<dictcomp>   s   	 rY   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>   r?   r@   rC   rD   rE   rF   rG   rH   rI   rJ   r   itemsZROGRFieldTypesr   r   r   r   <module>   sF   c