î
ªÍ XO  ã               @   sA  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 i e d  6e d% 6e d& 6e d' 6e d( 6e d) 6e d* 6e d+ 6e d, 6e d- 6e d. 6e d/ 6e d0 6e d1 6Z d2 d3 „  e j ƒ  Dƒ Z  d4 S)5é    )Ú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 ƒ ‚ n  | |  _ t |  j |  _ t	 |  t
 ƒ rˆ |  j d k rˆ t |  _ d |  _ n  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   úK/home/ubuntu/projects/ifolica/build/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 ƒ St  j |  j j |  j ƒ Sd 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   s7   t  j |  j j |  j ƒ } t | d |  j j d d ƒS)z(Retrieves the Field's value as a string.ÚencodingÚstrings_onlyT)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 | ƒ ƒ	 } | r§ | | | | | | | f St d ƒ ‚ d S)zARetrieves the Field's value as a tuple of date & time components.c             S   s   g  |  ] } t  ƒ  ‘ q Sr   )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 | d |  j j d d ƒS)zReturns the name of this Field.r#   r$   T)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)Ú__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 ƒ Sd 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   sa   y> |  j  ƒ  \ } } } } } } } t | j | j | j ƒ SWn t t f k
 r\ d SYn Xd 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   ss   yP |  j  ƒ  \ } } } } } } } t | j | j | j | j | j | j ƒ SWn t t f k
 rn d SYn Xd 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   sa   y> |  j  ƒ  \ } } } } } } } t | j | j | j ƒ SWn t t f k
 r\ d SYn Xd 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*   é   é	   é
   é   é   é   c             C   s   i  |  ] \ } } | | “ q Sr   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>   sH   `
