
    Dvg=                     ~    d 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
 ddlmZ ddlmZmZ  G d	 d
e          ZdS )a  
 DataSource is a wrapper for the OGR Data Source object, which provides
 an interface for reading vector geometry data from many different file
 formats (including ESRI shapefiles).

 When instantiating a DataSource object, use the filename of a
 GDAL-supported data source.  For example, a SHP file or a
 TIGER/Line file from the government.

 The ds_driver keyword is used internally when a ctypes pointer
 is passed in directly.

 Example:
  ds = DataSource('/home/foo/bar.shp')
  for layer in ds:
      for feature in layer:
          # Getting the geometry for the feature.
          g = feature.geom

          # Getting the 'description' field for the feature.
          desc = feature['description']

          # We can also increment through all of the fields
          #  attached to this feature.
          for field in feature:
              # Get the name of the field (e.g. 'description')
              nm = field.name

              # Get the type (integer) of the field, e.g. 0 => OFTInteger
              t = field.type

              # Returns the value the field; OFTIntegers return ints,
              #  OFTReal returns floats, all else returns string.
              val = field.value
    )Path)GDALBase)Driver)GDALException)Layer)ds)force_bytes	force_strc                   f    e Zd ZdZej        ZddZd Zd Z	d Z
ed             Zed	             Zd
S )
DataSourcez Wraps an OGR Data Source object.Futf-8c                    |rt           j        nt           j        | _        || _        t          j                     t          |t          t          f          rY	 t          j
        t          |          | j        t           j        z  d d d           }nq# t          $ r t          d|z            w xY wt          || j                  rt          |t
          j                  r|}nt          dt          |          z            |r1|| _        t          j        |          }t          |          | _        d S t          d|z            )Nz%Could not open the datasource at "%s"z"Invalid data source input type: %szInvalid data source file "%s")capiGDAL_OF_UPDATEGDAL_OF_READONLY_writeencodingr   ensure_registered
isinstancestrr   open_dsr	   GDAL_OF_VECTORr   ptr_typetypeptrget_dataset_driverdriver)selfds_input	ds_driverwriter   r   r   s          _/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/gis/gdal/datasource.py__init__zDataSource.__init__7   sQ   -2Md))8M  """hd,, 	WX\))K$"55  ! X X X $$Kh$VWWWX $-00 	WZv6
 6
 	W BB DtH~~ UVVV 	LDH,R00F ..DKKK   ?( JKKKs   7B B,c                    t          |t                    rI	 t          j        | j        t          |                    }n# t          $ r t          d|z            w xY wt          |t                    rBd|cxk    r| j	        k     rn nt          j
        | j        |          }n1t          d|z            t          dt          |          z            t          ||           S )z@Allows use of the index [] operator to get a layer at the index.z!Invalid OGR layer name given: %s.r   z=Index out of range when accessing layers in a datasource: %s.zInvalid index type: %s)r   r   r   get_layer_by_namer   r	   r   
IndexErrorintlayer_count	get_layer_ptr	TypeErrorr   r   )r   indexlayers      r"   __getitem__zDataSource.__getitem__\   s   eS!! 	DN.txU9K9KLL  N N N !Du!LMMMNs## 		DE,,,,D,,,,,,ty%88 S  
 4tE{{BCCCUD!!!s	   '? Ac                     | j         S )z3Return the number of layers within the data source.)r(   r   s    r"   __len__zDataSource.__len__o   s        c                 &    | j         d| j        dS )z2Return OGR GetName and Driver for the Data Source.z ())namer   r0   s    r"   __str__zDataSource.__str__s   s     IIIt{{{33r2   c                 4    t          j        | j                  S )z/Return the number of layers in the data source.)r   get_layer_countr*   r0   s    r"   r(   zDataSource.layer_countw   s     #DI...r2   c                 b    t          j        | j                  }t          || j        d          S )z#Return the name of the data source.T)strings_only)r   get_ds_namer*   r
   r   )r   r5   s     r"   r5   zDataSource.name|   s-     	**t}4@@@@r2   N)FFr   )__name__
__module____qualname____doc__r   
destroy_ds
destructorr#   r.   r1   r6   propertyr(   r5    r2   r"   r   r   3   s        &&J#L #L #L #LJ" " "&     4 4 4 / / X/ A A XA A Ar2   r   N)r?   pathlibr   django.contrib.gis.gdal.baser   django.contrib.gis.gdal.driverr   django.contrib.gis.gdal.errorr   django.contrib.gis.gdal.layerr   "django.contrib.gis.gdal.prototypesr   r   django.utils.encodingr	   r
   r   rC   r2   r"   <module>rK      s   " "H       1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 7 7 / / / / / / 9 9 9 9 9 9 8 8 8 8 8 8 8 8MA MA MA MA MA MA MA MA MA MAr2   