ó
i4Vdc           @   s  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
 m Z d  d l m Z d  d l m Z d  d l m Z d  d l 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  m! Z! d  d l" m# Z# d e f d „  ƒ  YZ$ d S(   iÿÿÿÿ(   t   byreft   c_double(   t   GDALBase(   t   Envelopet   OGREnvelope(   t   GDALExceptiont   OGRIndexErrort   SRSException(   t   Feature(   t   OGRFieldTypes(   t   OGRGeometry(   t   OGRGeomType(   t   dst   geomt   srs(   t   SpatialReference(   t   six(   t   force_bytest
   force_text(   t   ranget   Layerc           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	 d
 „ ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z d „  Z d „  Z e	 e e ƒ Z d „  Z e d „ Z d „  Z RS(   sS   A class that wraps an OGR Layer, needs to be instantiated from a DataSource object.c         C   sR   | s t  d ƒ ‚ n  | |  _ | |  _ t j |  j ƒ |  _ |  j d ƒ |  _ d S(   s8  
        Initializes on an OGR C pointer to the Layer and the `DataSource` object
        that owns this layer.  The `DataSource` object is required so that a
        reference to it is kept with this Layer.  This prevents garbage
        collection of the `DataSource` while this Layer is still active.
        s*   Cannot create Layer, invalid pointer givent
   RandomReadN(	   R   t   ptrt   _dst   capit   get_layer_defnt   _ptrt   _ldefnt   test_capabilityt   _random_read(   t   selft	   layer_ptrR   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   __init__   s    		c         C   s    t  | t j ƒ r: | d k  r- t d ƒ ‚ n  |  j | ƒ St  | t ƒ r | j |  j ƒ \ } } } g  t | | | ƒ D] } |  j | ƒ ^ qw St	 d ƒ ‚ d S(   s(   Gets the Feature at the specified index.i    s/   Negative indices are not allowed on OGR Layers.s>   Integers and slices may only be used when indexing OGR Layers.N(
   t
   isinstanceR   t   integer_typesR   t   _make_featuret   slicet   indicest   num_featR   t	   TypeError(   R   t   indext   startt   stopt   stridet   fid(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   __getitem__+   s    ,c         c   sH   t  j |  j ƒ x1 t |  j ƒ D]  } t t  j |  j ƒ |  ƒ Vq  Wd S(   s(   Iterates over each Feature in the Layer.N(   R   t   reset_readingR   R   R&   R   t   get_next_feature(   R   t   i(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   __iter__;   s    c         C   s   |  j  S(   s%   The length is the number of features.(   R&   (   R   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   __len__B   s    c         C   s   |  j  S(   s   The string name of the layer.(   t   name(   R   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   __str__F   s    c         C   sx   |  j  r@ y  t t j |  j | ƒ |  ƒ SWqd t k
 r< qd Xn$ x! |  D] } | j | k rG | SqG Wt d | ƒ ‚ d S(   s.  
        Helper routine for __getitem__ that constructs a Feature from the given
        Feature ID.  If the OGR Layer does not support random-access reading,
        then each feature of the layer will be incremented through until the
        a Feature is found matching the given feature ID.
        s   Invalid feature id: %s.N(   R   R   R   t   get_featureR   R   R,   R   (   R   t   feat_idt   feat(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyR#   J   s    	 c         C   s/   t  ƒ  } t j |  j t | ƒ d ƒ t | ƒ S(   s/   Returns the extent (an Envelope) of this layer.i   (   R   R   t
   get_extentR   R    R   (   R   t   env(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   extenta   s    	c         C   s+   t  j |  j ƒ } t | |  j j d t ƒS(   s2   Returns the name of this layer in the Data Source.t   strings_only(   R   t   get_fd_nameR   R   R   t   encodingt   True(   R   R3   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyR3   h   s    i   c         C   s   t  j |  j | ƒ S(   s,   Returns the number of features in the Layer.(   R   t   get_feature_countR   (   R   t   force(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyR&   n   s    c         C   s   t  j |  j ƒ S(   s*   Returns the number of fields in the Layer.(   R   t   get_field_countR   (   R   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt
   num_fieldss   s    c         C   s   t  t j |  j ƒ ƒ S(   s5   Returns the geometry type (OGRGeomType) of the Layer.(   R   R   t   get_fd_geom_typeR   (   R   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt	   geom_typex   s    c         C   sB   y) t  j |  j ƒ } t t j | ƒ ƒ SWn t k
 r= d SXd S(   s1   Returns the Spatial Reference used in this Layer.N(   R   t   get_layer_srsR   R   t   srs_apit	   clone_srsR   t   None(   R   R   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyR   }   s
    c         C   sM   g  t  |  j ƒ D]9 } t t j t j |  j | ƒ ƒ |  j j d t	 ƒ^ q S(   su   
        Returns a list of string names corresponding to each of the Fields
        available in this Layer.
        R;   (
   R   RB   R   R   t   get_field_namet   get_field_defnR   R   R=   R>   (   R   R0   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   fields†   s    c         C   s<   g  t  |  j ƒ D]( } t t j t j |  j | ƒ ƒ ^ q S(   só   
        Returns a list of the types of fields in this Layer.  For example,
        the list [OFTInteger, OFTReal, OFTString] would be returned for
        an OGR layer that had an integer, a floating-point, and string
        fields.
        (   R   RB   R	   R   t   get_field_typeRJ   R   (   R   R0   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   field_types   s    c         C   s8   g  t  |  j ƒ D]$ } t j t j |  j | ƒ ƒ ^ q S(   s<   Returns a list of the maximum field widths for the features.(   R   RB   R   t   get_field_widthRJ   R   (   R   R0   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   field_widths›   s    c         C   s8   g  t  |  j ƒ D]$ } t j t j |  j | ƒ ƒ ^ q S(   s.   Returns the field precisions for the features.(   R   RB   R   t   get_field_precisionRJ   R   (   R   R0   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   field_precisions¡   s    c         C   s<   y# t  t j t j |  j ƒ ƒ ƒ SWn t k
 r7 d  SXd  S(   N(   R
   t   geom_apit
   clone_geomR   t   get_spatial_filterR   R   RH   (   R   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   _get_spatial_filter§   s    #c         C   sÊ   t  | t ƒ r( t j |  j | j ƒ nž t  | t t f ƒ r˜ t | ƒ d k s^ t d ƒ ‚ n  t	 t
 | ƒ \ } } } } t j |  j | | | | ƒ n. | d  k rº t j |  j d  ƒ n t d ƒ ‚ d  S(   Ni   s/   Spatial filter list/tuple must have 4 elements.sJ   Spatial filter must be either an OGRGeometry instance, a 4-tuple, or None.(   R!   R
   R   t   set_spatial_filterR   t   tuplet   listt   lent
   ValueErrort   mapR   t   set_spatial_filter_rectRH   R'   (   R   t   filtert   xmint   ymint   xmaxt   ymax(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   _set_spatial_filter­   s    c         C   sB   | |  j  k r" t d | ƒ ‚ n  g  |  D] } | j | ƒ ^ q) S(   sh   
        Returns a list containing the given field name for every Feature
        in the Layer.
        s   invalid field name: %s(   RK   R   t   get(   R   t
   field_nameR7   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt
   get_fields¿   s    c         C   sW   | r9 d d l  m } g  |  D] } | | j j ƒ ^ q Sg  |  D] } | j ^ q@ Sd S(   sc   
        Returns a list containing the OGRGeometry for every Feature in
        the Layer.
        iÿÿÿÿ(   t   GEOSGeometryN(   t   django.contrib.gis.geosRf   R   t   wkb(   R   t   geosRf   R7   (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt	   get_geomsÈ   s    #c         C   s   t  t j |  j t | ƒ ƒ ƒ S(   si  
        Returns a bool indicating whether the this Layer supports the given
        capability (a string).  Valid capability strings include:
          'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter',
          'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions',
          'DeleteFeature', and 'FastSetNextByIndex'.
        (   t   boolR   R   R   R   (   R   t
   capability(    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyR   Ó   s    (   t   __name__t
   __module__t   __doc__R    R-   R1   R2   R4   R#   t   propertyR:   R3   R&   RB   RD   R   RK   RM   RO   RQ   RU   Rb   t   spatial_filterRe   t   FalseRj   R   (    (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyR      s0   							
				N(%   t   ctypesR    R   t   django.contrib.gis.gdal.baseR   t    django.contrib.gis.gdal.envelopeR   R   t   django.contrib.gis.gdal.errorR   R   R   t   django.contrib.gis.gdal.featureR   t   django.contrib.gis.gdal.fieldR	   t"   django.contrib.gis.gdal.geometriesR
   t    django.contrib.gis.gdal.geomtypeR   t"   django.contrib.gis.gdal.prototypesR   R   R   RR   R   RF   t   django.contrib.gis.gdal.srsR   t   django.utilsR   t   django.utils.encodingR   R   t   django.utils.six.movesR   R   (    (    (    sk   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/gdal/layer.pyt   <module>   s   