ó
J~‰Pc           @   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 d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ 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, 6Z e g  e j ƒ  D] \ Z Z  e  e f ^ qúƒ Z! d- S(.   iÿÿÿÿ(   t   byreft   c_int(   t   datet   datetimet   time(   t   GDALBase(   t   OGRException(   t   ds(   t
   force_textt   Fieldc           B   sž   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „  ƒ Z
 e	 d „  ƒ Z e	 d	 „  ƒ Z e	 d
 „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z RS(   s`   
    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 |  _ t |  _ n  d S(   sr   
        Initializes on the feature object and the integer index of
        the field within the feature.
        s/   Cannot create OGR Field, invalid pointer given.i    N(   t   _featt   _indext   capit   get_feat_field_defnt   ptrR   t   OGRFieldTypest   typet	   __class__t
   isinstancet   OFTRealt	   precisiont
   OFTIntegert   Truet   _double(   t   selft   featt   indext   fld_ptr(    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt   __init__   s    				c         C   s   t  |  j ƒ j ƒ  S(   s/   Returns the string representation of the Field.(   t   strt   valuet   strip(   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt   __str__+   s    c         C   s   t  j |  j j |  j ƒ S(   s0   Retrieves the Field's value as a double (float).(   R   t   get_field_as_doubleR
   R   R   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt	   as_double0   s    c         C   s   t  j |  j j |  j ƒ S(   s*   Retrieves the Field's value as an integer.(   R   t   get_field_as_integerR
   R   R   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt   as_int4   s    c         C   s7   t  j |  j j |  j ƒ } t | d |  j j d t ƒS(   s(   Retrieves the Field's value as a string.t   encodingt   strings_only(   R   t   get_field_as_stringR
   R   R   R   R%   R   (   R   t   string(    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt	   as_string8   s    c   
      C   sÀ   g  t  d ƒ D] } t ƒ  ^ q \ } } } } } } } t j |  j j |  j t | ƒ t | ƒ t | ƒ t | ƒ t | ƒ t | ƒ t | ƒ ƒ	 }	 |	 r° | | | | | | | f St d ƒ ‚ d S(   sA   Retrieves the Field's value as a tuple of date & time components.i   s:   Unable to retrieve date & time information from the field.N(	   t   rangeR   R   t   get_field_as_datetimeR
   R   R   R    R   (
   R   t   it   yyt   mmt   ddt   hht   mnt   sst   tzt   status(    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt   as_datetime=   s    7**c         C   s.   t  j |  j ƒ } t | d |  j j d t ƒS(   s   Returns the name of this Field.R%   R&   (   R   t   get_field_nameR   R   R
   R%   R   (   R   t   name(    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR7   I   s    c         C   s   t  j |  j ƒ S(   s$   Returns the precision of this Field.(   R   t   get_field_precisionR   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   O   s    c         C   s   t  j |  j ƒ S(   s#   Returns the OGR type of this Field.(   R   t   get_field_typeR   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   T   s    c         C   s   t  j |  j ƒ S(   s.   Return the OGR field type name for this Field.(   R   t   get_field_type_nameR   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt	   type_nameY   s    c         C   s
   |  j  ƒ  S(   s    Returns the value of this Field.(   R)   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   ^   s    c         C   s   t  j |  j ƒ S(   s    Returns the width of this Field.(   R   t   get_field_widthR   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt   widthd   s    (   t   __name__t
   __module__t   __doc__R   R    R"   R$   R)   R5   t   propertyR7   R   R   R;   R   R=   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR	      s   						R   c           B   s,   e  Z e Z e d  „  ƒ Z e d „  ƒ Z RS(   c         C   s'   |  j  r t |  j ƒ  ƒ S|  j ƒ  Sd S(   s+   Returns an integer contained in this field.N(   R   t   intR"   R$   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   m   s    	c         C   s   d S(   sµ   
        GDAL uses OFTReals to represent OFTIntegers in created
        shapefiles -- forcing the type here since the underlying field
        type may actually be OFTReal.
        i    (    (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   w   s    (   R>   R?   t   FalseR   RA   R   R   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   j   s   
R   c           B   s   e  Z e d  „  ƒ Z RS(   c         C   s
   |  j  ƒ  S(   s(   Returns a float contained in this field.(   R"   (   R   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR      s    (   R>   R?   RA   R   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   €   s   t	   OFTStringc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRD   ‡   s    t   OFTWideStringc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRE   ˆ   s    t	   OFTBinaryc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRF   ‰   s    t   OFTDatec           B   s   e  Z e d  „  ƒ Z RS(   c         C   s]   y> |  j  ƒ  \ } } } } } } } t | j | j | j ƒ SWn t t f k
 rX d SXd S(   s5   Returns a Python `date` object for the OFTDate field.N(   R5   R   R   t
   ValueErrorR   t   None(   R   R-   R.   R/   R0   R1   R2   R3   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR      s
    !(   R>   R?   RA   R   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRG   Œ   s   t   OFTDateTimec           B   s   e  Z e d  „  ƒ Z RS(   c         C   so   yP |  j  ƒ  \ } } } } } } } t | j | j | j | j | j | j ƒ SWn t t f k
 rj d SXd S(   s>   Returns a Python `datetime` object for this OFTDateTime field.N(   R5   R   R   RH   R   RI   (   R   R-   R.   R/   R0   R1   R2   R3   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   —   s
    !/(   R>   R?   RA   R   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRJ   –   s   t   OFTTimec           B   s   e  Z e d  „  ƒ Z RS(   c         C   s]   y> |  j  ƒ  \ } } } } } } } t | j | j | j ƒ SWn t t f k
 rX d SXd S(   s6   Returns a Python `time` object for this OFTTime field.N(   R5   R   R   RH   R   RI   (   R   R-   R.   R/   R0   R1   R2   R3   (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyR   ¥   s
    !(   R>   R?   RA   R   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRK   ¤   s   t   OFTIntegerListc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRL   ¯   s    t   OFTRealListc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRM   °   s    t   OFTStringListc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRN   ±   s    t   OFTWideStringListc           B   s   e  Z RS(    (   R>   R?   (    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyRO   ²   s    i    i   i   i   i   i   i   i   i   i	   i
   i   N("   t   ctypesR    R   R   R   R   t   django.contrib.gis.gdal.baseR   t   django.contrib.gis.gdal.errorR   t"   django.contrib.gis.gdal.prototypesR   R   t   django.utils.encodingR   R	   R   R   RD   RE   RF   RG   RJ   RK   RL   RM   RN   RO   R   t   dictt   itemst   numt   clst   ROGRFieldTypes(    (    (    s6   ../Django//lib/python/django/contrib/gis/gdal/field.pyt   <module>   s>   ]


