
    !\iI                     B   S r SSKJrJr  SSKrSSKrSSKrSSKrSSKrSSK	r	SSK
rSSKrSSKJr  SSKJrJrJrJr  SSKJr  SSKJr  SSKJr  SS	KJr  \R6                  " \5      rS
 rS rS r S r!S r"S r#\\\ \!\"\#S.r$SSSSSSS\RJ                  SSSSSSS4S jr&g)z5Copy valid pixels from input files to an output file.    )	ExitStackcontextmanagerN)
Resampling)
MergeErrorRasterioDeprecationWarningRasterioErrorWindowError)DatasetWriter)windows)Affine)	subdividec                     [         R                  " USS9n[         R                  " X5S9  [         R                  " X%US9  [         R                  " XUSS9  g)z"Returns the first available pixel.booldtypeoutunsafewherecastingN)np
empty_likelogical_notlogical_andcopytomerged_datanew_datamerged_masknew_maskkwargsmasks         Q/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/merge.py
copy_firstr%      s<    ==F3DNN8&NN;$/IIk4B    c                     [         R                  " USS9n[         R                  " X5S9  [         R                  " XUSS9  g)z!Returns the last available pixel.r   r   r   r   r   N)r   r   r   r   r   s         r$   	copy_lastr(   %   s.    ==F3DNN8&IIk4Br&   c                 *   [         R                  " USS9n[         R                  " X#US9  [         R                  " XUS9  [         R                  " XXSS9  [         R                  " X5S9  [         R
                  " X%US9  [         R                  " XUSS9  g)z Returns the minimum value pixel.r   r   r   r   r   r   r   r   N)r   r   
logical_orr   minimumr   r   r   s         r$   copy_minr-   ,   f    ==F3DMM+T2NN4"JJ{+8TNN8&NN;$/IIk4Br&   c                 *   [         R                  " USS9n[         R                  " X#US9  [         R                  " XUS9  [         R                  " XXSS9  [         R                  " X5S9  [         R
                  " X%US9  [         R                  " XUSS9  g)z Returns the maximum value pixel.r   r   r   r   r*   r   N)r   r   r+   r   maximumr   r   r   s         r$   copy_maxr1   7   r.   r&   c                 *   [         R                  " USS9n[         R                  " X#US9  [         R                  " XUS9  [         R                  " XXSS9  [         R                  " X5S9  [         R
                  " X%US9  [         R                  " XUSS9  g)z$Returns the sum of all pixel values.r   r   r   r   r*   r   Nr   r   r+   r   addr   r   r   s         r$   copy_sumr5   B   sf    ==F3DMM+T2NN4"FF;kxPNN8&NN;$/IIk4Br&   c                 *   [         R                  " USS9n[         R                  " X#US9  [         R                  " XUS9  [         R                  " XXSS9  [         R                  " X5S9  [         R
                  " X%US9  [         R                  " XUSS9  g)z"Returns the count of valid pixels.r   r   r   r   r*   r   Nr3   r   s         r$   
copy_countr7   M   sf    ==F3DMM+T2NN4"FF;+8LNN8&NN;$/IIktX>r&   )firstlastminmaxsumcountr8   F@   c                    Ub  [         R                  " S[        5        U	[        ;   a
  [        U	   nOI[	        U	5      (       a  U	nO6[        SR                  U	[        [        R                  5       5      5      5      e[        U S   [        [        R                  45      (       a  [        R                  nO[        S 5       nUnSn[!        5        nU" U S   5       nUR"                  nUR$                  nUR&                  nUR(                  S   nUnUR*                  S   nUc  UR,                  nO#[        U[.        5      (       a  UnO[1        U5      n UR3                  S5      nSSS5        U(       d  WnU(       a	  Uu  nnn n!GO/ n"/ n#[5        U 5       H  u  n$n%U" U%5       n&U&R6                  n'U(       a  [9        WU&R&                  S S9nU'R:                  (       d  [=        S	5      eU'R>                  S:  a  [=        S
5      eU'R@                  S:  a  [=        S5      eU&RB                  u  n(n)n*n+SSS5        U"RE                  W(W*/5        U#RE                  W)W+/5        M     [9        U"5      [9        U#5      [G        U"5      [G        U#5      4u  nnn n!U(       d  WnO<[        U[H        RJ                  5      (       a  X"4nO[1        U5      S:X  a
  US   US   4nU
(       a  [L        RN                  " UUS   -  5      US   -  n[L        RP                  " U US   -  5      US   -  n [L        RN                  " UUS   -  5      US   -  n[L        RP                  " U!US   -  5      US   -  n![/        [S        U U-
  US   -  5      5      n,[/        [S        U!U-
  US   -  5      5      n-[T        RV                  " UU!5      [T        RX                  " US   US   * 5      -  n.Ub  Un[Z        R]                  SU5        Ub  Un[Z        R]                  SU5        Sn/WGb  [^        R`                  " W[^        Rb                  5      (       a@  [^        Rd                  " U5      n0U0R8                  Us=:*  =(       a    U0RF                  :*  Os  n/O[f        Rh                  " U5      (       ap  [^        Rj                  " U5      n0U0R8                  Us=:*  =(       a    U0RF                  :*  Os  n/[^        Rl                  " U5      n1U/[^        Rn                  " U1U5      -  n/OSn/U/(       d  [         R                  " SU SU S35        WnO[Z        R]                  S5        Sn[p        Rr                  " SSU,U-5      n2Ub  [        U[t        5      (       a  UnOgWn3U3Rv                  " S%0 U=(       d    0 D6  U.U3S'   U-U3S'   U,U3S'   UU3S'   WU3S'   Ub  UU3S'   [        R                  " US40 U3D6nURy                  U5        US-  [^        Rz                  " W5      R|                  U-  -  n4U,U--  U4:  a  U2/n5O;[L        RN                  " [L        R~                  " U45      5      n6[        U2U6U65      n5OU2/n5S n7U5 GH`  n8[p        RB                  " U8U.5      u  nnn n![^        R                  " UU8R                  U8R                  4WS9n9U/(       a  U9R                  U5        [p        RB                  " U8U.5      n:[p        R6                  " U8U.5      n;S n<[5        U 5       GH  u  n=n%U" U%5       n&WU&R$                  :w  a  [        SU% 35      e U7" U&RB                  U:U;5      n>[p        R                  " / U>QU&R6                  P76 n?[p        R                  " / U>QU;P76 n@U<" W@5      n@U@R                  5       u  nAnBU9SS2UAUB4   nC[f        R                  " U5      (       a  [^        R                  " WC5      nDOQ[^        R`                  " WCRz                  [^        Rb                  5      (       d  [^        R                  " WCU5      nDOWCU:H  nDU&R                  WW@R                  U@R                  4USU?US!9nEU" WCUEWDUER                  U=U@R                  U@R                  S"9  SSS5        GM     U(       d  GM0  [p        R                  " / U:QU.P76 nFU<" UF5      nFUR                  U9UFS#9  GMc     Uc3  U(       a  [^        R                  R                  W9USS$9n9W9U.4sSSS5        $ W(       a  UR                  SU5        UR                  5          SSS5        g! [
         a    Sn GNf = f! , (       d  f       GN= f! , (       d  f       GN"= f! [
        [        4 a.    [Z        R                  S U&U&RB                  5         SSS5        GM  f = f! , (       d  f       GM  = f! , (       d  f       g= f)&a  Copy valid pixels from input files to an output file.

All files must have the same number of bands, data type, and
coordinate reference system. Rotated, flipped, or upside-down
rasters cannot be merged.

Input files are merged in their listed order using the reverse
painter's algorithm (default) or another method. If the output file
exists, its values will be overwritten by input values.

Geospatial bounds and resolution of a new output file in the units
of the input file coordinate reference system may be provided and
are otherwise taken from the first input file.

Parameters
----------
sources : list
    A sequence of dataset objects opened in 'r' mode or Path-like
    objects.
bounds: tuple, optional
    Bounds of the output image (left, bottom, right, top).
    If not set, bounds are determined from bounds of input rasters.
res: tuple, optional
    Output resolution in units of coordinate reference system. If
    not set, a source resolution will be used. If a single value is
    passed, output pixels will be square.
use_highest_res: bool, optional. Default: False.
    If True, the highest resolution of all sources will be used. If
    False, the first source's resolution will be used.
nodata: float, optional
    nodata value to use in output file. If not set, uses the nodata
    value in the first input raster.
masked: bool, optional. Default: False.
    If True, return a masked array. Note: nodata is always set in
    the case of file output.
dtype: numpy.dtype or string
    dtype to use in outputfile. If not set, uses the dtype value in
    the first input raster.
precision: int, optional
    This parameters is unused, deprecated in rasterio 1.3.0, and
    will be removed in version 2.0.0.
indexes : list of ints or a single int, optional
    bands to read and merge
output_count: int, optional
    If using callable it may be useful to have additional bands in
    the output in addition to the indexes specified for read
resampling : Resampling, optional
    Resampling algorithm used when reading input files.
    Default: `Resampling.nearest`.
method : str or callable
    pre-defined method:
        first: reverse painting
        last: paint valid new on top of existing
        min: pixel-wise min of existing and new
        max: pixel-wise max of existing and new
    or custom callable with signature:
        merged_data : array_like
            array to update with new_data
        new_data : array_like
            data to merge
            same shape as merged_data
        merged_mask, new_mask : array_like
            boolean masks where merged/new data pixels are invalid
            same shape as merged_data
        index: int
            index of the current dataset within the merged dataset
            collection
        roff: int
            row offset in base array
        coff: int
            column offset in base array

target_aligned_pixels : bool, optional
    Whether to adjust output image bounds so that pixel coordinates
    are integer multiples of pixel size, matching the ``-tap``
    options of GDAL utilities.  Default: False.
mem_limit : int, optional
    Process merge output in chunks of mem_limit MB in size.
dst_path : str or PathLike, optional
    Path of output dataset
dst_kwds : dict, optional
    Dictionary of creation options and other parameters that will be
    overlaid on the profile of the output dataset.

Returns
-------
tuple
    Two elements:
        dest: numpy.ndarray
            Contents of all input rasters in single array
        out_transform: affine.Affine()
            Information for mapping pixel coordinates in `dest` to
            another coordinate system

Raises
------
MergeError
    When sources cannot be merged due to incompatibility between
    them or limitations of the tool.
NzLThe precision parameter is unused, deprecated, and will be removed in 2.0.0.z0Unknown method {}, must be one of {} or callabler   c              3       #     U v   g ! f = f7f)N )objs    r$   nullcontextmerge.<locals>.nullcontext   s     	s   	    c                     [        U [        R                  5      (       a  U $ [        R                  " U S   S-  U S   S-  -   5      $ )Nr      rE   )
isinstancenumbersNumbermathsqrt)xs    r$   <lambda>merge.<locals>.<lambda>!  sE    )!W^^<< +, +B!%1Q419qtqy+@!A+Br&   )keyz2Rotated, non-rectilinear rasters cannot be merged.zGRasters with negative pixel width ("flipped" rasters) cannot be merged.zLRasters with negative pixel height ("upside down" rasters) cannot be merged.zSet dtype: %szSet nodataval: %rFTz)Ignoring nodata value. The nodata value, z8, cannot safely be represented in the chosen data type, zs. Consider overriding it using the --nodata option for better results. Falling back to first source's nodata value.zSet nodataval to 0	transformheightwidthr=   r   nodatawg    .Ac                 F   [        U S   US   5      n[        U S   US   5      nX4:  a  [        eUR                  S:  a0  [        U S   US   5      n[        U S   US   5      nXV:  a  [        eO/[        U S   US   5      n[        U S   US   5      nXe:  a  [        eX5XF4$ )zBased on gdal_merge.py.r   rG   rE      )r;   r:   
ValueErrore)bounds1bounds2rQ   int_wint_eint_sint_ns          r$   _intersect_bounds merge.<locals>._intersect_bounds  s    
GAJ/E
GAJ/E~  {{QGAJ
3GAJ
3>$$ " GAJ
3GAJ
3>$$--r&   r   c                 H   [         R                  " U R                  S-   5      n[         R                  " U R                  S-   5      n[         R                  " U R                  S-   5      n[         R                  " U R
                  S-   5      n[        R                  " X!XC5      $ )a   Equivalent to rounding both offsets and lengths.

This method computes offsets, width, and height that are
useful for compositing arrays into larger arrays and
datasets without seams. It is used by Rasterio's merge
tool and is based on the logic in gdal_merge.py.

Returns
-------
Window
g?g      ?)rK   floorrow_offcol_offrR   rS   r   Window)windowrd   re   rR   rS   s        r$   	win_alignmerge.<locals>.win_align  sq     **V^^c%9:**V^^c%9:FMMC$78

6<<##56~~gFFr&   zCRS mismatch with source: z"Skipping source: src=%r, bounds=%r)	out_shapeindexesmaskedrg   
resampling)indexroffcoff)rg   )copyrA   )Uwarningswarnr   MERGE_METHODScallablerX   formatlistkeysrH   strosPathLikerasterioopenr   r   profilecrsres
nodatavalsdtypesr=   intlencolormap	enumeraterQ   r:   is_rectilinearr   arY   boundsextendr;   rI   rJ   rK   rc   ceilroundr   translationscaleloggerdebugr   
issubdtypeintegeriinfocmathisfinitefinfomin_scalar_typecan_castr   rf   r
   updateenter_contextr   itemsizerL   r   zerosrR   rS   fillr   from_boundsr	   infotoslicesisnanisclosereadr#   rd   re   writemamasked_equalwrite_colormapclose)Gsourcesr   r   rT   r   	precisionrk   output_countrm   methodtarget_aligned_pixels	mem_limituse_highest_resrl   dst_pathdst_kwdsr   dataset_openerrC   dst
exit_stackr8   first_profile	first_crsbest_resfirst_nodataval	nodatavaldt	src_countfirst_colormapdst_wdst_sdst_edst_nxsysidatasetsrcsrc_transformleftbottomrighttopoutput_widthoutput_heightoutput_transforminranger   	nodata_dtdout_windowout_profile
max_pixelschunksnr`   chunkdestchunk_boundschunk_transformrh   idxiboundsswcwrowscolsregionregion_maskdatadwsG                                                                          r$   merger   b   s   l Z&	

 v&	&		>EE]//12
 	
 '!*sBKK011! 
	 
	 %
C	
GAJ'5!MMM		IyyH#..q1O'IaB!KK	GS))#	L	&!&!2! (( $L )/&E5% BB'0
7#G,$'MMM&#&$GG!B$ )77(P  %*(e  %*(j  03zz,D&%7 -: 		4-(		63-(? 1B *-R#b'3r7CG)K&E5% CW^^,,*CX]q63q6"C JJus1v~.Q7EIIec!fn-A6EJJus1v~.Q7EIIec!fn-A6E 5%%-3q6!9:;E55=CF":;<!--eU;fllFSVG?
 
 BLL"-ILL,i8 }}R,,xx|((i;;488;>>),,88B<D"hh)??txx?G " 2 29 =I%Ir(BBG"G?	{ K002t 4CC ,	LL-.I nnQ<G(M22+""6hn"6+;K((5H%'3G$'3G$')G$%,2K)mmHcA[A((-"U*bhhrl.C.Cl.RSJm+j8%JJtyy45";15!]F	., E)0?O)P&E5%88\5<<ERPD		)$ #>>%1ABL%//7GHOG$ !*' 2W#G, !CGG++.H	,RSS
!"3JJo# %00I'I3==I$00K'K?K #2B!#JD$!!T4-0F{{9--&(hhv&6]]6<<DD&(jj&C&,	&988#,bii"B '#!#- $ D #		!ZZZZK -, !3` s((I,I8HIr]		$r	*_ b ;uu))$	)F))I 
L ""1n5IIKQ 
$  &!%&# ('@ -,p '4 !@#szz !! -,! -,[ 
s   f1A8d9d&%>f1#Be0Sf1f	'Ae5C<f	1f1A!f13)f1&d62d95d66d99
e	f1
ef11ff	f1ff	
f.(	f11
f?)'__doc__
contextlibr   r   loggingrz   rK   r   rr   rI   numpyr   r|   rasterio.enumsr   rasterio.errorsr   r   r   r	   rasterio.ior
   r   rasterio.transformr   rasterio.windowsr   	getLogger__name__r   r%   r(   r-   r1   r5   r7   rt   nearestr   rA   r&   r$   <module>r      s    ; 0  	       %  &  % &			8	$CCCCC?  
!!!_r&   