
    !\i7J                        S r SSK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Jr  SS	KJrJr  SS
KJr  SSKJr  SSKJrJr  \R8                  " 5       r\R=                  5       r " S S5      r S r!S r"S r#S r$S r%S r&S"S jr'   S#S jr(S r) " S S5      r* " S S\*5      r+ " S S\*5      r, " S S\\+5      r- " S  S!\\+5      r.g)$zGeospatial transforms    )	ExitStack)partialN)Number)Affine)env_ctx_if_needed)_transform_from_gcpsRPCTransformerBaseGCPTransformerBase)TransformDirectionTransformMethod)GroundControlPoint)RPC)TransformErrorRasterioDeprecationWarningc                   b    \ rS rSrSrSS\R                  4S jrSSS\R                  4S jrSr	g)TransformMethodsMixin   a  Mixin providing methods for calculations related
to transforming between rows and columns of the raster
array and the coordinates.

These methods are wrappers for the functionality in
`rasterio.transform` module.

A subclass with this mixin MUST provide a `transform`
property.

Ncenterc                     [        XR                  5      nU[        R                  L a  US   nU(       d  [	        SU 35      e[        XqU4X4S.UD6$ )a  Get the coordinates x, y of a pixel at row, col.

The pixel's center is returned by default, but a corner can be returned
by setting `offset` to one of `ul, ur, ll, lr`.

Parameters
----------
row : int
    Pixel row.
col : int
    Pixel column.
z : float, optional
    Height associated with coordinates. Primarily used for RPC based
    coordinate transformations. Ignored for affine based
    transformations. Default: 0.
offset : str, optional
    Determines if the returned coordinates are for the center of the
    pixel or for a corner.
transform_method: TransformMethod, optional
    The coordinate transformation method. Default: `TransformMethod.affine`.
rpc_options: dict, optional
    Additional arguments passed to GDALCreateRPCTransformer

Returns
-------
tuple
    x, y

r   Dataset has no zsoffset)getattrvaluer   gcpsAttributeErrorxy)selfrowcolzr   transform_methodrpc_options	transforms           U/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/transform.pyr   TransformMethodsMixin.xy'   sZ    L D"8"89	333!!I ?3C2D!EFF)#J!JkJJ    c           	          Ub  [         R                  " S[        5        [        XR                  5      nU[
        R                  L a  US   nU(       d  [        SU 35      e[        S [        XU4X4S.UD6 5       5      $ )a  Get the (row, col) index of the pixel containing (x, y).

Parameters
----------
x : float
    x value in coordinate reference system
y : float
    y value in coordinate reference system
z : float, optional
    Height associated with coordinates. Primarily used for RPC
    based coordinate transformations. Ignored for affine based
    transformations. Default: 0.
op : function, optional (default: numpy.floor)
    Function to convert fractional pixels to whole numbers
    (floor, ceiling, round)
transform_method: TransformMethod, optional
    The coordinate transformation method. Default:
    `TransformMethod.affine`.
rpc_options: dict, optional
    Additional arguments passed to GDALCreateRPCTransformer
precision : int, optional
    This parameter is unused, deprecated in rasterio 1.3.0, and
    will be removed in version 2.0.0.

Returns
-------
tuple: int, int
    (row index, col index)

LThe precision parameter is unused, deprecated, and will be removed in 2.0.0.r   r   c              3   8   #    U  H  n[        U5      v   M     g 7fN)int).0vals     r&   	<genexpr>.TransformMethodsMixin.index.<locals>.<genexpr>   s     ])\#SXX)\s   r   op)
warningswarnr   r   r   r   r   r   tuplerowcol)	r   xyr"   r3   	precisionr#   r$   r%   s	            r&   indexTransformMethodsMixin.indexT   s    P  MM^*
 D"8"89	333!!I ?3C2D!EFF]	a)\A)\P[)\]]]r(    )
__name__
__module____qualname____firstlineno____doc__r   affiner   r;   __static_attributes__r=   r(   r&   r   r      s9    
  (//+Kb (//3^r(   r   c                     U c  [        S5      e[        U [        5      (       a  [        [        U 5      nU$ [        U [
        5      (       a  [        [        U 40 UD6nU$ [        [        U 5      nU$ )z(Return the appropriate transformer classzInvalid transform)
ValueError
isinstancer   r   AffineTransformerr   RPCTransformerGCPTransformer)r%   r$   transformer_clss      r&   get_transformerrL      sr    ,--)V$$!"3Y?
 	 
Is	#	#!.)K{K  ".)<r(   c                     [        U 5      [        :H  =(       d9    U S   U S   s=:H  =(       a    S:H  Os  =(       a    U S   S:  =(       a    U S   S:  $ )z;Return True if `seq` matches the GDAL geotransform pattern.      g           r      )r6   GDAL_IDENTITY)seqs    r&   tastes_like_gdalrT      sJ    :& ?A#a&C=CFQJ=3q6A:?r(   c                 v    [        U [        5      (       d#  [        U 5      (       a  [        S5      e[        U 6 n U $ )z)Return an Affine transformation instance.zGDAL-style transforms have been deprecated.  This exception will be raised for a period of time to highlight potentially confusing errors, but will eventually be removed.)rG   r   rT   	TypeError)r%   s    r&   guard_transformrW      sA    i((I&&PQ Q
 	*Ir(   c                 ^    [         R                  " X5      [         R                  " X#* 5      -  $ )zReturn an Affine transformation given upper left and pixel sizes.

Return an Affine transformation for a georeferenced raster given
the coordinates of its upper left corner `west`, `north` and pixel
sizes `xsize`, `ysize`.

r   translationscale)westnorthxsizeysizes       r&   from_originr`      s%     d*V\\%-HHHr(   c                 r    [         R                  " X5      [         R                  " X -
  U-  X-
  U-  5      -  $ )zReturn an Affine transformation given bounds, width and height.

Return an Affine transformation for a georeferenced raster given
its bounds `west`, `south`, `east`, `north` and its `width` and
`height` in number of pixels.

rY   )r\   southeastr]   widthheights         r&   from_boundsrf      s:     d*V\\	7.9 9 9r(   c           	         Uu	  p4pVpx    n	XFs=:X  a  S:X  a  O  OXXXp-  -   XSU-  -   U4u  ppOWXXpUSU 4-  u  nnX!U 4-  u  nnX!S4-  u  nnUUUU4nUUUU4n[        U5      [        U5      [        U5      [        U5      4u  ppXX4$ )zReturn the bounds of an array given height, width, and a transform.

Return the `west, south, east, north` bounds of an array given
its height, width, and an affine transform.

r   )minmax)re   rd   r%   abcdef_r\   rb   rc   r]   c0xc0yc1xc1yc2xc2yc3xc3yxsyss                           r&   array_boundsr{      s     !*A!aA{{#$!*nae)mQ#F T5S6{*Sv.Sqz)S3S!3S!#&r7CGSWc"g#E T##r(   c                 ~    [        U 40 UD6nU" 5        nUR                  XX4S9sSSS5        $ ! , (       d  f       g= f)al  Get the x and y coordinates of pixels at `rows` and `cols`.

The pixel's center is returned by default, but a corner can be returned
by setting `offset` to one of `ul, ur, ll, lr`.

Supports affine, Ground Control Point (GCP), or Rational Polynomial
Coefficients (RPC) based coordinate transformations.

Parameters
----------
transform : Affine or sequence of GroundControlPoint or RPC
    Transform suitable for input to AffineTransformer, GCPTransformer, or RPCTransformer.
rows : list or int
    Pixel rows.
cols : int or sequence of ints
    Pixel columns.
zs : list or float, optional
    Height associated with coordinates. Primarily used for RPC based
    coordinate transformations. Ignored for affine based
    transformations. Default: 0.
offset : str, optional
    Determines if the returned coordinates are for the center of the
    pixel or for a corner.
rpc_options : dict, optional
    Additional arguments passed to GDALCreateRPCTransformer.

Returns
-------
xs : float or list of floats
    x coordinates in coordinate reference system
ys : float or list of floats
    y coordinates in coordinate reference system

r   N)rL   r   )r%   rowscolsr   r   r$   rK   transformers           r&   r   r      s8    F &i?;?O		k~~dR~? 
		s   .
<c                     Ub  [         R                  " S[        5        [        U 40 UD6nU" 5        nUR	                  XX4S9sSSS5        $ ! , (       d  f       g= f)a:  Get rows and cols of the pixels containing (x, y).

Parameters
----------
transform : Affine or sequence of GroundControlPoint or RPC
    Transform suitable for input to AffineTransformer,
    GCPTransformer, or RPCTransformer.
xs : list or float
    x values in coordinate reference system.
ys : list or float
    y values in coordinate reference system.
zs : list or float, optional
    Height associated with coordinates. Primarily used for RPC based
    coordinate transformations. Ignored for affine based
    transformations. Default: 0.
op : function, optional (default: numpy.floor)
    Function to convert fractional pixels to whole numbers (floor,
    ceiling, round)
precision : int or float, optional
    This parameter is unused, deprecated in rasterio 1.3.0, and
    will be removed in version 2.0.0.
rpc_options : dict, optional
    Additional arguments passed to GDALCreateRPCTransformer.

Returns
-------
rows : array of ints or floats
cols : array of ints or floats
    Integers are the default. The numerical type is determined by
    the type returned by op().

Nr*   r2   )r4   r5   r   rL   r7   )	r%   ry   rz   r   r3   r:   r$   rK   r   s	            r&   r7   r7      sU    R Z&	

 &i?;?O		k!!"R!7 
		s   A
Ac                 :    [         R                  " [        U 5      6 $ )zMake an Affine transform from ground control points.

Parameters
----------
gcps : sequence of GroundControlPoint
    Such as the first item of a dataset's `gcps` property.

Returns
-------
Affine

)r   	from_gdalr   )r   s    r&   	from_gcpsr   3  s     1$788r(   c                   X    \ rS rSrSrS r\SS j5       rS rS r	SS jr
SS	 jrS
 rSrg)TransformerBaseiC  zGeneric GDAL transformer base class

Notes
-----
Subclasses must have a _transformer attribute and implement a `_transform` method.

c                     S U l         g r,   _transformerr   s    r&   __init__TransformerBase.__init__K  s
     r(   Nc                 ,   [         R                  " U 5      n [         R                  " U5      nUb  [         R                  " U5      nO[         R                  " S5      n [         R                  " XU5      nXU4$ ! [         a  n[        5       UeSnAff = f)zEnsure all input coordinates are mapped to array-like objects

Raises
------
TransformError
    If input coordinates are not all of the same length
NrP   )np
atleast_1dzeros	broadcastrF   r   )ry   rz   r   broadcastederrors        r&   _ensure_arr_input!TransformerBase._ensure_arr_inputN  s~     ]]2]]2>r"B!B	.,,rr2K rz  	. "-	.s   A9 9
BBBc                     U $ r,   r=   r   s    r&   	__enter__TransformerBase.__enter__e  s    r(   c                     g r,   r=   r   argss     r&   __exit__TransformerBase.__exit__h      r(   c                    Ub  [         R                  " S[        5        [        U[        5      =(       a    [        U[        5      nU R                  XUS9u  pn U R                  XU[        R                  S9u  pxUcG  [        R                  " U5      R                  SS9n[        R                  " U5      R                  SS9nO|[        U[        R                  5      (       a  U" XS9  U" XwS9  OP[        R                  " [        [        XH5      5      5      n[        R                  " [        [        XG5      5      5      nU(       a
  US   US   4$ X4$ ! [          a    [#        S5      ef = f)	a  Get rows and cols coordinates given geographic coordinates.

Parameters
----------
xs, ys : float or list of float
    Geographic coordinates
zs : float or list of float, optional
    Height associated with coordinates. Primarily used for RPC
    based coordinate transformations. Ignored for affine based
    transformations. Default: 0.
op : function, optional (default: numpy.floor)
    Function to convert fractional pixels to whole numbers
    (floor, ceiling, round)
precision : int, optional (default: None)
    This parameter is unused, deprecated in rasterio 1.3.0, and
    will be removed in version 2.0.0.

Raises
------
TypeError
    If coordinate transformation fails.
ValueError
    If input coordinates are not all equal length.

Returns
-------
tuple of numbers or array of numbers.
    Integers are the default. The numerical type is determined
    by the type returned by op().

r*   r   transform_directionint32dtypeoutr   Invalid inputs)r4   r5   r   rG   r   r   
_transformr   reverser   floorastypeufuncarraylistmaprV   r   )	r   ry   rz   r   r3   r:   	IS_SCALARnew_colsnew_rowss	            r&   r7   TransformerBase.rowcolk  sC   @  MM^*
 r6*Ez"f/E	++Br+:
	3!%0B0J0J "1 "H z88H-4474C88H-4474CB))8*8*88DR):$;<88DR):$;<{HQK//)) 	3 !122	3s   C7E E E+c                    [        U[        5      =(       a    [        U[        5      nU R                  XUS9u  pnUS:X  a  Su  pgO7US:X  a  Su  pgO,US:X  a  Su  pgO!US:X  a  S	u  pgOUS
:X  a  Su  pgO[        S5      e [        R                  Xg5      n[        U5      n	U	R                  X!U[        R                  S9u  pU R                  XU[        R                  S9u  pU(       a
  US   US   4$ X4$ ! [         a    [        S5      ef = f)a  
Returns geographic coordinates given dataset rows and cols coordinates

Parameters
----------
rows, cols : int or list of int
    Image pixel coordinates
zs : float or list of float, optional
    Height associated with coordinates. Primarily used for RPC based
    coordinate transformations. Ignored for affine based
    transformations. Default: 0.
offset : str, optional
    Determines if the returned coordinates are for the center of the
    pixel or for a corner. Available options include center, ul, ur, ll,
    lr.
Raises
------
ValueError
    If input coordinates are not all equal length

Returns
-------
tuple of float or list of float

r   r   )      ?r   ul)r   r   ur)rP   r   ll)r   rP   lr)rP   rP   zInvalid offsetr   r   r   )rG   r   r   r   IDENTITYrZ   rH   r   r   forwardrV   )r   r}   r~   r   r   r   coffroffTidentity_transformeroffset_colsoffset_rowsnew_xsnew_yss                 r&   r   TransformerBase.xy  s9   4 tV,ID&1I	//r/BBX#JD$t^JD$t^JD$t^JD$t^JD$ !122	3$$T0A#4Q#7 ';'F'FB4F4N4N (G ($K "__"BTB\B\ - NF ay&)++~% 	3 !122	3s   >A2C4 1C4 4D
c                     [         er,   )NotImplementedError)r   ry   rz   r   r   s        r&   r   TransformerBase._transform  s    !!r(   r   r,   NNNNr   )r>   r?   r@   rA   rB   r   staticmethodr   r   r   r7   r   r   rD   r=   r(   r&   r   r   C  s;    !  ,>3@:3x"r(   r   c                   :   ^  \ rS rSrU 4S jrS rS rS rSrU =r	$ )GDALTransformerBasei  c                 @   > [         TU ]  5         [        5       U l        g r,   )superr   r   _env)r   	__class__s    r&   r   GDALTransformerBase.__init__  s    K	r(   c                     g r,   r=   r   s    r&   closeGDALTransformerBase.close  r   r(   c                 L    U R                   R                  [        5       5        U $ r,   )r   enter_contextr   r   s    r&   r   GDALTransformerBase.__enter__  s    		 1 34r(   c                 X    U R                  5         U R                  R                  5         g r,   )r   r   r   s     r&   r   GDALTransformerBase.__exit__  s    

		r(   )r   )
r>   r?   r@   rA   r   r   r   r   rD   __classcell__r   s   @r&   r   r     s      r(   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )rH   i  zGA pure Python class related to affine based coordinate transformations.c                    > [         TU ]  5         [        U[        5      (       d  [	        S5      eXl        [        R                  " SSS9U l        g )NzNot an affine transform)   r   float64r   )	r   r   rG   r   rF   r   r   empty_transform_arr)r   affine_transformr   s     r&   r   AffineTransformer.__init__  sA    *F33677, hhvY?r(   c                    U R                   nU[        R                  L a  U R                  UR                  S S & O-U[        R
                  L a  U R                  ) UR                  S S & [        R                  " X5      n[        R                  " SUR                  45      nUR                  S   US'   UR                  S   US'   SUS'   UR                  XwS9  US   US   4$ )Nr   r   rP   rN   r   )r   r   r   r   flatr   r   r   r   sizeitersdot)r   ry   rz   r   r   r%   biinput_matrixs           r&   r   AffineTransformer._transform  s    ''	"4"<"<< $ 1 1INN1 $6$>$>>!%!2!2 2INN1\\"!xxBGG-((1+Q((1+QQl5AQ//r(   c                     g)Nz<AffineTransformer>r=   r   s    r&   __repr__AffineTransformer.__repr__  s    $r(   )r   r   )
r>   r?   r@   rA   rB   r   r   r   rD   r   r   s   @r&   rH   rH     s    Q@0 % %r(   rH   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )rI   i  a^  
Class related to Rational Polynomial Coeffecients (RPCs) based
coordinate transformations.

Uses GDALCreateRPCTransformer and GDALRPCTransform for computations. Options
for GDALCreateRPCTransformer may be passed using `rpc_options`.
Ensure that GDAL transformer objects are destroyed by calling `close()`
method or using context manager interface.

c                 t   > [        U[        [        45      (       d  [        S5      e[        TU ]  " U40 UD6  g )NzRPCTransformer requires RPC)rG   r   dictrF   r   r   )r   rpcsr$   r   s      r&   r   RPCTransformer.__init__$  s2    $d,,:;;--r(   c                 \    SR                  U R                  =(       a    S=(       d    S5      $ )Nz<{} RPCTransformer>closedopenformatr   r   s    r&   r   RPCTransformer.__repr__)  &    $++KK$H.0 	0r(   r=   	r>   r?   r@   rA   rB   r   r   rD   r   r   s   @r&   rI   rI     s    	.
0 0r(   rI   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )rJ   i.  a_  
Class related to Ground Control Point (GCPs) based
coordinate transformations.

Uses GDALCreateGCPTransformer and GDALGCPTransform for computations.
Ensure that GDAL transformer objects are destroyed by calling `close()`
method or using context manager interface. If `tps` is set to True,
uses GDALCreateTPSTransformer and GDALTPSTransform instead.

c                    > [        U5      (       a#  [        US   [        5      (       d  [        S5      e[        TU ]  X5        g )Nr   z6GCPTransformer requires sequence of GroundControlPoint)lenrG   r   rF   r   r   )r   r   tpsr   s      r&   r   GCPTransformer.__init__9  s6    t99ZQ1CDDUVV#r(   c                 \    SR                  U R                  =(       a    S=(       d    S5      $ )Nz<{} GCPTransformer>r   r   r   r   s    r&   r   GCPTransformer.__repr__>  r   r(   r=   )Fr   r   s   @r&   rJ   rJ   .  s    	$
0 0r(   rJ   r   r   )/rB   
contextlibr   	functoolsr   numpyr   r4   numbersr   rC   r   rasterio.envr   rasterio._transformr   r	   r
   rasterio.enumsr   r   rasterio.controlr   rasterio.rpcr   rasterio.errorsr   r   identityr   to_gdalrR   r   rL   rT   rW   r`   rf   r{   r   r7   r   r   r   rH   rI   rJ   r=   r(   r&   <module>r     s            * 
 ? /  F??  "m^ m^`
?
I	9$,%@X 18h9 e" e"P/ "% %:0')< 0*0')< 0r(   