
    hy"                         S SK JrJr  S SKJr  S SKJrJr  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJrJr   " S S\5      rg)    )byrefc_double)GDALBase)EnvelopeOGREnvelope)GDALExceptionSRSException)Feature)OGRFieldTypes)OGRGeometry)OGRGeomType)ds)geom)srs)SpatialReference)force_bytes	force_strc                      \ rS rSrSrS rS rS rS rS r	S r
\S	 5       r\S
 5       r\SS j5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS r\" \\5      rS rSS jrS rSrg)Layer   zU
A class that wraps an OGR Layer, needs to be instantiated from a DataSource
object.
c                     U(       d  [        S5      eXl        X l        [        R                  " U R
                  5      U l        U R                  S5      U l        g)a  
Initialize 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.
z*Cannot create Layer, invalid pointer givens
   RandomReadN)	r   ptr_dscapiget_layer_defn_ptr_ldefntest_capability_random_read)self	layer_ptrr   s      O/var/www/html/env/lib/python3.13/site-packages/django/contrib/gis/gdal/layer.py__init__Layer.__init__   sF      LMM))$))4 00?    c                 L   [        U[        5      (       a"  US:  a  [        S5      eU R                  U5      $ [        U[        5      (       aI  UR                  U R                  5      u  p#n[        X#U5       Vs/ s H  oPR                  U5      PM     sn$ [        S5      es  snf )z'Get the Feature at the specified index.r   z/Negative indices are not allowed on OGR Layers.z>Integers and slices may only be used when indexing OGR Layers.)	
isinstanceint
IndexError_make_featuresliceindicesnum_featrange	TypeError)r    indexstartstopstridefids         r"   __getitem__Layer.__getitem__*   s    eS!! qy !RSS%%e,,u%%"'--">E7<U&7QR7Q&&s+7QRRP  Ss   9B!c              #      #    [         R                  " U R                  5        [        U R                  5       H/  n[        [         R                  " U R                  5      U 5      v   M1     g7f)z'Iterate over each Feature in the Layer.N)r   reset_readingr   r.   r-   r
   get_next_featurer    is     r"   __iter__Layer.__iter__<   sH      	499%t}}%A$//		:DAA &s   A*A,c                     U R                   $ )z%The length is the number of features.)r-   r    s    r"   __len__Layer.__len__C   s    }}r%   c                     U R                   $ )zThe string name of the layer.)namer?   s    r"   __str__Layer.__str__G   s    yyr%   c                     U R                   (       a,   [        [        R                  " U R                  U5      U 5      $ U  H  nUR                  U:X  d  M  Us  $    [        SU-  5      e! [
         a     Nf = f)a  
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.
zInvalid feature id: %s.)r   r
   r   get_featurer   r   r4   r)   )r    feat_idfeats      r"   r*   Layer._make_featureK   st     t//'BDII 88w&K  2W<== ! s   *A) )
A65A6c                     [        5       n[        R                  " U R                  [	        U5      S5        [        U5      $ )z.Return the extent (an Envelope) of this layer.   )r   r   
get_extentr   r   r   )r    envs     r"   extentLayer.extentb   s-     m%*a0}r%   c                 ~    [         R                  " U R                  5      n[        XR                  R
                  SS9$ )z1Return the name of this layer in the Data Source.Tstrings_only)r   get_fd_namer   r   r   encoding)r    rC   s     r"   rC   
Layer.namei   s/     ,xx00tDDr%   c                 D    [         R                  " U R                  U5      $ )z+Return the number of features in the Layer.)r   get_feature_countr   )r    forces     r"   r-   Layer.num_feato   s     %%dhh66r%   c                 B    [         R                  " U R                  5      $ )z)Return the number of fields in the Layer.)r   get_field_countr   r?   s    r"   
num_fieldsLayer.num_fieldst   s     ##DKK00r%   c                 T    [        [        R                  " U R                  5      5      $ )z4Return the geometry type (OGRGeomType) of the Layer.)r   r   get_fd_geom_typer   r?   s    r"   	geom_typeLayer.geom_typey   s     400=>>r%   c                      [         R                  " U R                  5      n[        [        R
                  " U5      5      $ ! [         a     gf = f)z0Return the Spatial Reference used in this Layer.N)r   get_layer_srsr   r   srs_api	clone_srsr	   )r    r   s     r"   r   	Layer.srs~   sC    	$$TXX.C#G$5$5c$:;; 		s   >A 
AAc                     [        U R                  5       Vs/ s HU  n[        [        R                  " [        R
                  " U R                  U5      5      U R                  R                  SS9PMW     sn$ s  snf )z\
Return a list of string names corresponding to each of the Fields
available in this Layer.
TrR   )	r.   r]   r   r   get_field_nameget_field_defnr   r   rU   r:   s     r"   fieldsLayer.fields   sj     4??+
 , ##D$7$7Q$GH!!!
 ,
 	
 
s   AA7c           
          [        U R                  5       Vs/ s H?  n[        [        R                  " [        R
                  " U R                  U5      5         PMA     sn$ s  snf )z
Return a list of the types of fields in this Layer.  For example,
return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that
has an integer, a floating-point, and string fields.
)r.   r]   r   r   get_field_typerj   r   r:   s     r"   field_typesLayer.field_types   sS     4??+
+ $--d.A.A$++q.QRS+
 	
 
s   AA!c           	          [        U R                  5       Vs/ s H8  n[        R                  " [        R                  " U R
                  U5      5      PM:     sn$ s  snf )z;Return a list of the maximum field widths for the features.)r.   r]   r   get_field_widthrj   r   r:   s     r"   field_widthsLayer.field_widths   sN    
 4??+
+   !4!4T[[!!DE+
 	
 
   ?Ac           	          [        U R                  5       Vs/ s H8  n[        R                  " [        R                  " U R
                  U5      5      PM:     sn$ s  snf )z-Return the field precisions for the features.)r.   r]   r   get_field_precisionrj   r   r:   s     r"   field_precisionsLayer.field_precisions   sN    
 4??+
+ $$T%8%8a%HI+
 	
 
ru   c                      [        [        R                  " [        R                  " U R
                  5      5      5      $ ! [         a     g f = f)N)r   geom_api
clone_geomr   get_spatial_filterr   r   r?   s    r"   _get_spatial_filterLayer._get_spatial_filter   s>    	x2243J3J4883TUVV 		s   <? 
AAc                    [        U[        5      (       a,  [        R                  " U R                  UR                  5        g [        U[
        [        45      (       aP  [        U5      S:X  d  [        S5      e[        [        U5      u  p#pE[        R                  " U R                  X#XE5        g Uc"  [        R                  " U R                  S 5        g [        S5      e)N   z/Spatial filter list/tuple must have 4 elements.zJSpatial filter must be either an OGRGeometry instance, a 4-tuple, or None.)r'   r   r   set_spatial_filterr   tuplelistlen
ValueErrormapr   set_spatial_filter_rectr/   )r    filterxminyminxmaxymaxs         r"   _set_spatial_filterLayer._set_spatial_filter   s    fk**##DHHfjj9..v;!# !RSS &)6%:"D((4tJ^##DHHd3 r%   c                     XR                   ;  a  [        SU-  5      eU  Vs/ s H  o"R                  U5      PM     sn$ s  snf )zO
Return a list containing the given field name for every Feature
in the Layer.
zinvalid field name: %s)rk   r   get)r    
field_namerI   s      r"   
get_fieldsLayer.get_fields   s>    
 [[( 8: EFF156$666s   ?c                     U(       a2  SSK Jn  U  Vs/ s H  o2" UR                  R                  5      PM      sn$ U  Vs/ s H  o3R                  PM     sn$ s  snf s  snf )zJ
Return a list containing the OGRGeometry for every Feature in
the Layer.
r   )GEOSGeometry)django.contrib.gis.geosr   r   wkb)r    geosr   rI   s       r"   	get_geomsLayer.get_geoms   sL    
 <<@ADDL/DAA*./$$II$// B/s
   %AAc                 h    [        [        R                  " U R                  [	        U5      5      5      $ )a8  
Return 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'.
)boolr   r   r   r   )r    
capabilitys     r"   r   Layer.test_capability   s%     D((;z3JKLLr%   )r   r   r   r   N)rL   )F)__name__
__module____qualname____firstlineno____doc__r#   r5   r<   r@   rD   r*   propertyrO   rC   r-   r]   ra   r   rk   ro   rs   rx   r~   r   spatial_filterr   r   r   __static_attributes__ r%   r"   r   r      s   
@$B>.   E E
 7 7 1 1 ? ?   
 
 	
 	
 
 
 
 
$ 13FGN7
0Mr%   r   N) ctypesr   r   django.contrib.gis.gdal.baser    django.contrib.gis.gdal.enveloper   r   django.contrib.gis.gdal.errorr   r	   django.contrib.gis.gdal.featurer
   django.contrib.gis.gdal.fieldr   "django.contrib.gis.gdal.geometriesr    django.contrib.gis.gdal.geomtyper   "django.contrib.gis.gdal.prototypesr   r   r   r{   r   re   django.contrib.gis.gdal.srsr   django.utils.encodingr   r   r   r   r%   r"   <module>r      s<    " 1 B E 3 7 : 8 9 ? = 8 8UMH UMr%   