î
ªÍ X—  ã               @   s²   d  d l  m Z d  d l m Z m Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z m Z d  d l m Z d  d l m Z m Z d  d l m Z Gd	 d
 „  d
 e ƒ Z d S)é    )ÚGDALBase)ÚGDALExceptionÚOGRIndexError)ÚField)ÚOGRGeometryÚOGRGeomType)ÚdsÚgeom)Úsix)Úforce_bytesÚ
force_text)Úrangec               @   s   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d d	 „  Z 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 d „  Z d  d! „  Z d" S)#ÚFeatureza
    This class that wraps an OGR Feature, needs to be instantiated
    from a Layer object.
    c             C   s+   | s t  d ƒ ‚ n  | |  _ | |  _ d S)zJ
        Initializes Feature from a pointer and its Layer object.
        z1Cannot create OGR Feature, invalid pointer given.N)r   ÚptrÚ_layer)ÚselfZfeatZlayer© r   úM/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/gdal/feature.pyÚ__init__   s    	zFeature.__init__c             C   s3   y t  j |  j ƒ Wn t t f k
 r. Yn Xd S)z$Releases a reference to this object.N)ÚcapiZdestroy_featureÚ_ptrÚAttributeErrorÚ	TypeError)r   r   r   r   Ú__del__   s    zFeature.__del__c             C   sa   t  | t j ƒ r$ |  j | ƒ } n0 | d k  s? | |  j k rN t d ƒ ‚ n  | } t |  | ƒ S)a/  
        Gets the Field object at the specified index, which may be either
        an integer or the Field's string label.  Note that the Field object
        is not the field's _value_ -- use the `get` method instead to
        retrieve the value (e.g. an integer) instead of a Field instance.
        r   zindex out of range)Ú
isinstancer
   Ústring_typesÚindexÚ
num_fieldsr   r   )r   r   Úir   r   r   Ú__getitem__%   s    zFeature.__getitem__c             c   s'   x  t  |  j ƒ D] } |  | Vq Wd S)z(Iterates over each field in the Feature.N)r   r   )r   r   r   r   r   Ú__iter__4   s    zFeature.__iter__c             C   s   |  j  S)z,Returns the count of fields in this feature.)r   )r   r   r   r   Ú__len__9   s    zFeature.__len__c             C   s   d |  j  |  j f S)zThe string name of the feature.zFeature FID %d in Layer<%s>)ÚfidÚ
layer_name)r   r   r   r   Ú__str__=   s    zFeature.__str__c             C   s   t  t j |  j | j ƒ ƒ S)z)Does equivalence testing on the features.)Úboolr   Zfeature_equalr   r   )r   Úotherr   r   r   Ú__eq__A   s    zFeature.__eq__c             C   s   |  j  j j S)N)r   Z_dsÚencoding)r   r   r   r   r(   F   s    zFeature.encodingc             C   s   t  j |  j ƒ S)zReturns the feature identifier.)r   Zget_fidr   )r   r   r   r   r"   J   s    zFeature.fidc             C   s+   t  j |  j j ƒ } t | |  j d d ƒS)z.Returns the name of the layer for the feature.Zstrings_onlyT)r   Zget_feat_namer   Ú_ldefnr   r(   )r   Únamer   r   r   r#   O   s    zFeature.layer_namec             C   s   t  j |  j ƒ S)z,Returns the number of fields in the Feature.)r   Zget_feat_field_countr   )r   r   r   r   r   U   s    zFeature.num_fieldsc                s    ‡  f d d †  t  ˆ  j ƒ Dƒ S)z(Returns a list of fields in the Feature.c                s1   g  |  ]' } t  j t  j ˆ  j j | ƒ ƒ ‘ q Sr   )r   Zget_field_nameZget_field_defnr   r)   )Ú.0r   )r   r   r   ú
<listcomp>]   s   	z"Feature.fields.<locals>.<listcomp>)r   r   )r   r   )r   r   ÚfieldsZ   s    zFeature.fieldsc             C   s%   t  j |  j ƒ } t t j | ƒ ƒ S)z*Returns the OGR Geometry for this Feature.)r   Zget_feat_geom_refr   r   Úgeom_apiZ
clone_geom)r   Zgeom_ptrr   r   r   r	   `   s    zFeature.geomc             C   s   t  t j |  j j ƒ ƒ S)z.Returns the OGR Geometry Type for this Feture.)r   r   Zget_fd_geom_typer   r)   )r   r   r   r   Ú	geom_typeg   s    zFeature.geom_typec             C   s   t  | d | ƒ } |  | j S)z³
        Returns the value of the field, instead of an instance of the Field
        object.  May take a string of the field name or a Field object as
        parameters.
        r*   )ÚgetattrÚvalue)r   ÚfieldÚ
field_namer   r   r   Úgetm   s    zFeature.getc             C   s>   t  j |  j t | ƒ ƒ } | d k  r: t d | ƒ ‚ n  | S)z*Returns the index of the given field name.r   z"invalid OFT field name given: "%s")r   Zget_field_indexr   r   r   )r   r3   r   r   r   r   r   v   s    zFeature.indexN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r!   r$   r'   Úpropertyr(   r"   r#   r   r-   r	   r/   r4   r   r   r   r   r   r      s"   		r   N)Zdjango.contrib.gis.gdal.baser   Zdjango.contrib.gis.gdal.errorr   r   Zdjango.contrib.gis.gdal.fieldr   Z"django.contrib.gis.gdal.geometriesr   r   Z"django.contrib.gis.gdal.prototypesr   r   r	   r.   Zdjango.utilsr
   Zdjango.utils.encodingr   r   Zdjango.utils.six.movesr   r   r   r   r   r   Ú<module>   s   