OwlCyberSecurity - MANAGER
Edit File: datasource.cpython-39.pyc
a jH�f � @ s| d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m Z ddlmZ ddl mZ dd lmZmZ G d d� de�ZdS ) 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 � )�byref)�Path)�GDALBase)�Driver)� GDALException)�Layer)�ds)�force_bytes� force_strc @ sP e Zd ZdZejZddd�Zdd� Zdd � Z d d� Z edd � �Zedd� �Z dS )� DataSourcez Wraps an OGR Data Source object.F�utf-8c C s� |rd| _ nd| _ || _t�� t|ttf�rtt�� }zt� t |�| j t|��}W q� typ td| ��Y q�0 n.t|| j�r�t|tj�r�|}ntdt |� ��|r�|| _t|�| _ntd| ��d S )N� r z%Could not open the datasource at "%s"z"Invalid data source input type: %szInvalid data source file "%s")�_write�encodingr Zensure_registered� isinstance�strr Zptr_type�capiZopen_dsr r r �type�ptr�driver)�selfZds_inputZ ds_driver�writer r � r �d/home/gouroczh/virtualenv/test/3.9/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py�__init__7 s( �zDataSource.__init__c C s� t |t�rBzt�| jt|��}W q� ty> td| ��Y q�0 nRt |t�r�d| krb| j k rvn nt� | j|�}q�td| ��ntdt |� ��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.zInvalid index type: %s)r r r Zget_layer_by_namer r r � IndexError�int�layer_countZ get_layer�_ptr� TypeErrorr r )r �index�layerr r r �__getitem__Z s ��zDataSource.__getitem__c C s | j S )z3Return the number of layers within the data source.)r �r r r r �__len__m s zDataSource.__len__c C s d| j | jf S )z2Return OGR GetName and Driver for the Data Source.z%s (%s))�namer r# r r r �__str__q s zDataSource.__str__c C s t �| j�S )z/Return the number of layers in the data source.)r Zget_layer_countr r# r r r r u s zDataSource.layer_countc C s t �| j�}t|| jdd�S )z#Return the name of the data source.T)Zstrings_only)r Zget_ds_namer r r )r r% r r r r% z s zDataSource.nameN)FFr )�__name__� __module__�__qualname__�__doc__r Z destroy_dsZ destructorr r"