
    !\iS                     p   S r SSKJrJr  SSKJr  SSKrSSK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	KJrJr  SS
KJr  SSKJrJrJrJrJr  \SS j5       r\\" SSS/SSS9   SS j5       5       r SS jr\SSSSSSSSSSSSS\R@                  SSSS4S j5       r!S r"\          SS j5       r#g)z Raster warping and reprojection.    )ceilfloor)AffineN)
_transform)CRS)
Resampling)
ensure_envrequire_gdal_version)TransformErrorRPCError)array_bounds)_calculate_default_transform
_reproject_transform_bounds_transform_geomSUPPORTED_RESAMPLINGc                     [        U5      [        U5      :w  a  [        S5      eUb#  [        U5      [        U5      :w  a  [        S5      e[        U5      S:X  a  Ub  / / / 4$ / / 4$ [        XX#U5      $ )a  Transform vectors from source to target coordinate reference system.

Transform vectors of x, y and optionally z from source
coordinate reference system into target.

Parameters
------------
src_crs: CRS or dict
    Source coordinate reference system, as a rasterio CRS object.
    Example: CRS({'init': 'EPSG:4326'})
dst_crs: CRS or dict
    Target coordinate reference system.
xs: array_like
    Contains x values.  Will be cast to double floating point values.
ys:  array_like
    Contains y values.
zs: array_like, optional
    Contains z values.  Assumed to be all 0 if absent.

Returns
---------
out: tuple of array_like, (xs, ys, [zs])
    Tuple of x, y, and optionally z vectors, transformed into the target
    coordinate reference system.

z(xs and ys arrays must be the same lengthz-zs, xs, and ys arrays must be the same lengthr   )lenr   r   )src_crsdst_crsxsyszss        P/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/warp.py	transformr      ss    : 2w#b'GHH	CGs2w.LMM
2w!|!~B|;B8;'BB77    z2.1antimeridian_cuttingFTz5Antimeridian cutting is always enabled on GDAL >= 2.2)paramvaluesis_max_versionreasonc                 "    [        U UUUUU5      $ )ah  Transform geometry from source coordinate reference system into target.

Parameters
------------
src_crs: CRS or dict
    Source coordinate reference system, in rasterio dict format.
    Example: CRS({'init': 'EPSG:4326'})
dst_crs: CRS or dict
    Target coordinate reference system.
geom: GeoJSON like dict object or iterable of GeoJSON like objects.
antimeridian_cutting: bool, optional
    If True, cut geometries at the antimeridian, otherwise geometries
    will not be cut (default).  If False and GDAL is 2.2.0 or newer
    an exception is raised.  Antimeridian cutting is always on as of
    GDAL 2.2.0 but this could produce an unexpected geometry.
antimeridian_offset: float
    Offset from the antimeridian in degrees (default: 10) within which
    any geometries will be split.
precision: float
    If >= 0, geometry coordinates will be rounded to this number of decimal
    places after the transform operation, otherwise original coordinate
    values will be preserved (default).

Returns
---------
out: GeoJSON like dict object or list of GeoJSON like objects.
    Transformed geometry(s) in GeoJSON dict format
)r   )r   r   geomr   antimeridian_offset	precisions         r   transform_geomr&   ?   s$    R  r   c           	      |    [         R                  " U 5      n [         R                  " U5      n[        U UUUUUU5      $ )aj  Transform bounds from src_crs to dst_crs.

Optionally densifying the edges (to account for nonlinear transformations
along these edges) and extracting the outermost bounds.

Note: antimeridian support added in version 1.3.0

Parameters
----------
src_crs: CRS or dict
    Source coordinate reference system, in rasterio dict format.
    Example: CRS({'init': 'EPSG:4326'})
dst_crs: CRS or dict
    Target coordinate reference system.
left, bottom, right, top: float
    Bounding coordinates in src_crs, from the bounds property of a raster.
densify_pts: uint, optional
    Number of points to add to each edge to account for nonlinear
    edges produced by the transform process.  Large numbers will produce
    worse performance.  Default: 21 (gdal default).

Returns
-------
left, bottom, right, top: float
    Outermost coordinates in target coordinate reference system.
)r   from_user_inputr   )r   r   leftbottomrighttopdensify_ptss          r   transform_boundsr.   q   sG    D !!'*G!!'*G r      c                    [        S X#UU4 5       5      S:  a  [        S5      e US:X  a  [        S5      e[        U5        Uc  Ub  [        S
5      eUGc  Ub   [        U[        R                  5      (       Gax  [        S	/S-  5      n[        U [        R                  5      (       aO  U R                  S:X  a  U R                  u  nnnOSnU R                  u  nnU(       d  U(       d  [        UUU5      nGOU u  nnnnUR                  R                  (       a  UR                   b  UR"                  nU=(       d    UR                   nU(       ac  [        U[$        5      (       a*  [&        R                   R(                  R+                  U5      nOUnUb  UR-                  5       S:w  a  [/        S5      e[        U[0        5      (       a  U/n[3        U5      nUu  nnUR4                  S   (       a  U(       d  UR4                  S   OS	nS	nS	nUn [        U[        R                  5      (       a2  UR                  S:X  a  UR                  u  n nnOSn UR                  u  nnUu  n!n"n#n$[7        UUUUU!U"U#U$UUUUUU
S9u  nnnUcr  [        R8                  " [1        U 5      [1        U5      [1        U5      4U R:                  S9nU(       a.  [        R<                  R?                  U5      RA                  U	5      n[C        U U4UUUUUUUU	UUUUUUUS.UD6n%U%U4$ ! [         aR    [        SR                  SR	                  [
         Vs/ s H  nSUR                   3PM     Os  snf sn5      5      5      ef = f)a2  Reproject a source raster to a destination raster.

If the source and destination are ndarrays, coordinate reference
system definitions and geolocation parameters are required for
reprojection. Only one of src_transform, gcps, rpcs, or
src_geoloc_array can be used.

If the source and destination are rasterio Bands, shorthand for
bands of datasets on disk, the coordinate reference systems and
transforms will be read from the appropriate datasets.

Parameters
------------
source: ndarray or Band
    The source is a 2 or 3-D ndarray, or a single or a multiple
    Rasterio Band object. The dimensionality of source
    and destination must match, i.e., for multiband reprojection
    the lengths of the first axes of the source and destination
    must be the same.
destination: ndarray or Band, optional
    The destination is a 2 or 3-D ndarray, or a single or a multiple
    Rasterio Band object. The dimensionality of source
    and destination must match, i.e., for multiband reprojection
    the lengths of the first axes of the source and destination
    must be the same.
src_transform: affine.Affine(), optional
    Source affine transformation. Required if source and
    destination are ndarrays. Will be derived from source if it is
    a rasterio Band. An error will be raised if this parameter is
    defined together with gcps.
gcps: sequence of GroundControlPoint, optional
    Ground control points for the source. An error will be raised
    if this parameter is defined together with src_transform or rpcs.
rpcs: RPC or dict, optional
    Rational polynomial coefficients for the source. An error will
    be raised if this parameter is defined together with src_transform
    or gcps.
src_geoloc_array : array-like, optional
    A pair of 2D arrays holding x and y coordinates, like
    a dense array of ground control points that may be used in place
    of src_transform.
src_crs: CRS or dict, optional
    Source coordinate reference system, in rasterio dict format.
    Required if source and destination are ndarrays.
    Will be derived from source if it is a rasterio Band.
    Example: CRS({'init': 'EPSG:4326'})
src_nodata: int or float, optional
    The source nodata value. Pixels with this value will not be
    used for interpolation. If not set, it will default to the
    nodata value of the source image if a masked ndarray or
    rasterio band, if available.
dst_transform: affine.Affine(), optional
    Target affine transformation. Required if source and
    destination are ndarrays. Will be derived from target if it is
    a rasterio Band.
dst_crs: CRS or dict, optional
    Target coordinate reference system. Required if source and
    destination are ndarrays. Will be derived from target if it
    is a rasterio Band.
dst_nodata: int or float, optional
    The nodata value used to initialize the destination; it will
    remain in all areas not covered by the reprojected source.
    Defaults to the nodata value of the destination image (if set),
    the value of src_nodata, or 0 (GDAL default).
dst_resolution: tuple (x resolution, y resolution) or float, optional
    Target resolution, in units of target coordinate reference
    system.
src_alpha : int, optional
    Index of a band to use as the alpha band when warping.
dst_alpha : int, optional
    Index of a band to use as the alpha band when warping.
masked: bool, optional
    If True and destination is None, return a masked array.
resampling: int, rasterio.enums.Resampling
    Resampling method to use.
    Default is :attr:`rasterio.enums.Resampling.nearest`.
    An exception will be raised for a method not supported by the running
    version of GDAL.
num_threads : int, optional
    The number of warp worker threads. Default: 1.
init_dest_nodata: bool
    Flag to specify initialization of nodata in destination;
    prevents overwrite of previous warps. Defaults to True.
warp_mem_limit : int, optional
    The warp operation memory limit in MB. Larger values allow the
    warp operation to be carried out in fewer chunks. The amount of
    memory required to warp a 3-band uint8 2000 row x 2000 col
    raster to a destination of the same size is approximately
    56 MB. The default (0) means 64 MB with GDAL 2.2.
kwargs:  dict, optional
    Additional arguments passed to both the image to image
    transformer :cpp:func:`GDALCreateGenImgProjTransformer2` (for example,
    MAX_GCP_ORDER=2) and the :cpp:struct:`GDALWarpOptions` (for example,
    INIT_DEST=NO_DATA).

Returns
---------
destination: ndarray or Band
    The transformed narray or Band.
dst_transform: Affine
    THe affine transformation matrix of the destination.
c              3   (   #    U  H  oS Lv   M
     g 7fN .0r   s     r   	<genexpr>reproject.<locals>.<genexpr>  s      
+X%+X   r/   zosrc_transform, gcps, rpcs, and src_geoloc_array are mutually exclusive parameters and may not be used together.   z!Gauss resampling is not supportedzresampling must be one of: {}z, zResampling.Nz6Must provide destination if dst_transform is provided.      i  zXReprojecting with rational polynomial coefficients using source CRS other than EPSG:4326r   )r   r   widthheightr)   r*   r+   r,   gcpsrpcssrc_geoloc_array	dst_width
dst_height
resolution)dtype)src_transformr>   r?   r   
src_nodatadst_transformr   
dst_nodata	dst_alpha	src_alpha
resamplinginit_dest_nodatanum_threadswarp_mem_limitr@   )"sum
ValueErrorr   formatjoinr   name
isinstancenpndarraytuplendimshaper   r   is_identitycrsboundsstrrasterior   from_stringto_epsgr   intr   r>   calculate_default_transformemptyrD   mamasked_arrayfilledr   )&sourcedestinationrE   r>   r?   r   rF   rG   r   rH   dst_resolutionrJ   rI   maskedrK   rM   rL   rN   r@   kwargsr
src_bounds	src_count
src_height	src_widthsrc_rdrsrc_bidx_	src_shapesrc_crs_objrB   rA   	dst_countr)   r*   r+   r,   dests&                                         r   	reprojectrx      sy   ~ 	 
,9GW+X
 	
 	
 A
 	
	
?@AA: }8QRR +"5KQSQ[Q[9\9\D6A:&
fbjj)){{a39<<0	:y	(.%
I D)*iO
.4+GXq) %%11gkk6I$^^
,G gs++"*,,"2"2">">w"GK")K&;+>+>+@D+H"#}~~(C(($:HI$-!J	&-ll1od7<<?D
		k2::..1$3>3D3D0	:y	(3(9(9%
I#- feS/J-!%0
,y*" ((YZ#i.AK  ee00=DDZP $#)%)#$ %D* U  
+22		;OP;Oa[1;OPQ
 	

s   L -M/ MM/c           	         [        U[        [        45      (       a  [        U5      [        U5      4nOUnU R                  nU R                  X R
                  -  -   nU R                  XR                  -  -   nU R                  n[        XTS   -  5      US   -  n[        XtS   -  5      US   -  n[        XdS   -  5      US   -  n[        XS   -  5      US   -  n[        US   SUSUS   * U5      n	[        [        [        Xu-
  US   -  5      5      S5      n
[        [        [        X-
  US   -  5      5      S5      nXU4$ )a  Aligns target to specified resolution

Parameters
----------
transform : Affine
    Input affine transformation matrix
width, height: int
    Input dimensions
resolution: tuple (x resolution, y resolution) or float
    Target resolution, in units of target coordinate reference
    system.

Returns
-------
transform: Affine
    Output affine transformation matrix
width, height: int
    Output dimensions

r   r/   )rT   floatra   xoffyoffear   r   r   max)r   r<   r=   rC   resxminyminxmaxymaxrG   rA   rB   s               r   aligned_targetr     s9   * *ucl++Z %
"34>>D>>F[[00D>>EKK//D>>DA#a&(D1vQ'DA#a&(D1vQ'D3q61dAAw=MCdkSV345q9ISt{c!f456:JZ//r   c                    [        S XHX4 5       5      S:  a  [        S5      e[        S XHX4 5       5      S:  a  [        S5      eUSL USL :w  a  [        S5      e[        S X4 5       5      (       a  X4nOSnU
(       a  U(       a  [        S	5      e[        U UUU4UUUUUU	US
.UD6u  npU
(       a   [	        U
5      [	        U
5      4nUS   nUS   * nUR                  U-  nUR                  U-  n[        UUR                  UR                  UR                  UUR                  5      n[        UU-  5      n[        UU-  5      nU(       aj  XS   -  nXS   -  nUS   nUS   n[        UR                  U-  UR                  UR                  UR                  UR                  U-  UR                  5      nUX4$ ! [
         a"    [        U
5      S:X  a
  U
S   U
S   4OU
SS n GNf = f)a  Computes the default dimensions and transform for a reprojection.

Destination width and height (and resolution if not provided), are
calculated using GDAL's method for suggest warp output.  The
destination transform is anchored at the left, top coordinate.

Source georeferencing can be specified using either ground control
points (GCPs), rational polynomial coefficients (RPCs), geolocation
arrays, or spatial bounds (left, bottom, right, top). These forms of
georeferencing are mutually exclusive.

Source and destination coordinate reference systems and source
width and height are the first four, required, parameters.

Parameters
----------
src_crs : CRS or dict
    Source coordinate reference system, in rasterio dict format.
    Example: CRS({'init': 'EPSG:4326'})
dst_crs : CRS or dict
    Target coordinate reference system.
width, height : int
    Source raster width and height.
left, bottom, right, top : float, optional
    Bounding coordinates in src_crs, from the bounds property of a
    raster. Required unless using gcps.
gcps : sequence of GroundControlPoint, optional
    Instead of a bounding box for the source, a sequence of ground
    control points may be provided.
rpcs : RPC or dict, optional
    Instead of a bounding box for the source, rational polynomial
    coefficients may be provided.
src_geoloc_array : array-like, optional
    A pair of 2D arrays holding x and y coordinates, like a like
    a dense array of ground control points that may be used in place
    of src_transform.
resolution : tuple (x resolution, y resolution) or float, optional
    Target resolution, in units of target coordinate reference
    system.
dst_width, dst_height : int, optional
    Output file size in pixels and lines. Cannot be used together
    with resolution.
kwargs :  dict, optional
    Additional arguments passed to transformation function.

Returns
-------
transform: Affine
    Output affine transformation matrix
width, height: int
    Output dimensions

Notes
-----
Some behavior of this function is determined by the
CHECK_WITH_INVERT_PROJ environment variable:

    YES
        constrain output raster to extents that can be inverted
        avoids visual artifacts and coordinate discontinuties.
    NO
        reproject coordinates beyond valid bound limits
c              3   (   #    U  H  oS Lv   M
     g 7fr2   r3   r4   s     r   r6   .calculate_default_transform.<locals>.<genexpr>  s     
O*N*Nr8   r/   z5Bounds, gcps, rpcs, or src_geoloc_array are required.c              3   (   #    U  H  oS Lv   M
     g 7fr2   r3   r4   s     r   r6   r     s     Q,P5$,Pr8   zhBounds, gcps, rpcs, and src_geoloc_array are mutually exclusive parameters and may not be used together.NzBEither dst_width and dst_height must be specified or none of them.c              3   (   #    U  H  oS Lv   M
     g 7fr2   r3   )r5   xs     r   r6   r   $  s     
:"9QD="9r8   z8Resolution cannot be used with dst_width and dst_height.)r)   r*   r+   r,   r>   r?   r@   r      )rO   rP   allr   rz   	TypeErrorr   r~   r}   r   bcdfr   )r   r   r<   r=   r)   r*   r+   r,   r>   r?   rC   rA   rB   r@   rk   
dimensions
dst_affiner   xresyresxratioyratios                         r   rb   rb     s=   b 
O4t*N
OORSSPQQ 
QT,PQ	QTU	UA
 	

 	TzT12 , - 	- 
:9"9
:::,

jSTT(D	)
 )) )%J	$ 	$eJ&78C 1vAw$$D*,,
&LL$
>
 V+,	*v-.
]*m+qM	]
JLL61:<<&LL*,,*?O
 y,,?  	 z?a' A
1.!_ 	s   5F= =(G)(G)r2   )Tg      $@)   )
NNNNNNNNNN)$__doc__mathr   r   affiner   numpyrU   r^   rasterio._baser   rasterio.crsr   rasterio.enumsr   rasterio.envr	   r
   rasterio.errorsr   r   rasterio.transformr   rasterio._warpr   r   r   r   r   r   r&   r.   nearestrx   r   rb   r3   r   r   <module>r      s   &     %  % 9 4 +  #8 #8L e#95'%)+, " *	, 
*h ,^  		!!'w wt'0T  

		[- [-r   