
    Mh
                         d dl Z d dlZ e j        e j        d            e j        e          Zd Zd Zd Z	d Z
d Zd	 ZdS )
    Nz)%(asctime)s - %(levelname)s - %(message)s)levelformatc                 |    | d         | d         z
  |z  }| d         | d         z
  |z  }| d         |d| d         d| gS )zI
    This function computes the resolution based on data dimensions.
       r          )extentnlinesncolsresxresys        ./home/jovyan/projeto_inpe/dados_merge/utils.pygetGeoTr      sO     1Iq	!U*D1Iq	!V+D1ItQq	Au55    c                     ||d         z
  |d         z  }| |d         z
  |d         z  }t          |          t          |          fS )a;  
    This function returns the grid point associated to a spatial location.
    - param x The spatial x-coordiante.
    - param y The spatial y-coordiante.
    - param geoTransform A list of 6 coefficients describing an affine transformation to georeference a grid.
    - return The grid point line and column.
    r      r   r   )int)xygeoTlincols        r   geo2gridr      sG     tAw;$q'
!CtAw;$q'
!Cs88SXXr   c                 Z    ||d         z  |d         z   }| |d         z  |d         z   }||fS )a!  
    This function returns the spatial location of a grid point.
    - param geoTransform A list of 6 coefficients describing an affine transformation to georeference a grid.
    - param col The grid point column.
    - param row The grid point row.
    - return The spatial location.
    r   r   r   r   r	   )r   r   r   r   r   s        r   grid2geor   #   s9     	d1gQAd1gQAa4Kr   c                     | d         }| d         |d         | d         z  z   }| d         |d         | d         z  z   }| d         }||||fS )zo
    This function returns the extent based on the given GDAL
    geo-transform parameters and dimensions.
    r   r   r   r   r	   )gtshapellxllyurxurys         r   	getExtentr$   /   s[    
 Q%C
Q%E!H1%
&C
Q%E!HA&
'C
Q%Cc3r   c                     t          |||          }t          | d          5 }dD ]0}|                    d                    ||                              1	 d d d            d S # 1 swxY w Y   d S )Nw)r   r      r   r   r   z{}
)r   openwriter   )pathr
   r   r   r   fileis          r   createWorldFiler-   :   s    665))D	dC /D# 	/ 	/AJJv}}T!W--....	// / / / / / / / / / / / / / / / / /s   4A$$A(+A(c                     	 t           j                            |           st          j        |            dS dS # t          $ r+}t                              d|  d|            Y d}~dS d}~ww xY w)z. It Create the directory if it does not exist.TFz%Directory created or already exists: zError creating directory z: N)osr*   existsmakedirsloggerinfoOSErrorerror)	directoryr5   s     r   create_directory_if_not_existsr7   B   s    w~~i(( 	K	"""45    EEEeEEFFFuuuuus   39 
A. A))A.)loggingr/   basicConfigINFO	getLogger__name__r2   r   r   r   r$   r-   r7   r	   r   r   <module>r=      s     				  ',/Z [ [ [ [		8	$	$6 6 6
 
 

 
 
	  	  	 / / /    r   