
    !\i                     |    S 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	  \R                  " \5      r  SS jr  SS jrg)	z7Mask the area outside of the input shapes with no data.    N)WindowError)geometry_maskgeometry_windowc                 >   U(       a  U(       a  UnUnOSnSn [        XXxS9n	U(       a<  U R                  U	5      n[        U	R                  5      [        U	R                  5      4nO8Sn	U R                  n[        U R                  5      [        U R                  5      4n[        XUXS	9n
XU	4$ ! [         ae    U(       a  [        S5      e[        R                  " S5        [
        R                  " U R                  SS SS9n
U(       a  U
) n
XR                  S4s $ f = f)
aj  Create a mask from shapes, transform, and optional window within original
raster.

By default, mask is intended for use as a numpy mask, where pixels that
overlap shapes are False.

If shapes do not overlap the raster and crop=True, a ValueError is
raised.  Otherwise, a warning is raised, and a completely True mask
is returned (if invert is False).

Parameters
----------
dataset : a dataset object opened in 'r' mode
    Raster for which the mask will be created.
shapes : iterable object
    The values must be a GeoJSON-like dict or an object that implements
    the Python geo interface protocol (such as a Shapely Polygon).
all_touched : bool (opt)
    Include a pixel in the mask if it touches any of the shapes.
    If False (default), include a pixel only if its center is within one of
    the shapes, or if it is selected by Bresenham's line algorithm.
invert : bool (opt)
    Determines whether to mask pixels outside or inside the shapes.
    The default (False) is to mask pixels outside shapes.
    When invert is used with crop, the area outside the cropping window is
    considered selected and should be processed accordingly by the user.
crop : bool (opt)
    Crop the dataset to the extent of the shapes. Useful for
    processing rasters where shapes cover only a relatively small area.
    Defaults to False.
pad : bool (opt)
    If True, the features will be padded in each direction by
    one half of a pixel prior to cropping dataset. Defaults to False.
pad_width : float (opt)
    If pad is set (to maintain back-compatibility), then this will be the
    pixel-size width of the padding around the mask.

Returns
-------
tuple

    Three elements:

        mask : np.ndarray of type 'bool'
            Mask suitable for use in a MaskedArray where valid pixels are
            marked `False` and invalid pixels are marked `True`.

        out_transform : affine.Affine()
            Information for mapping pixel coordinates in `masked` to another
            coordinate system.

        window: rasterio.windows.Window instance
            Window within original raster covered by shapes.  None if crop
            is False.
r   )pad_xpad_yz#Input shapes do not overlap raster.zXshapes are outside bounds of raster. Are they in different coordinate reference systems?Nbool)shapedtype)	transforminvert	out_shapeall_touched)r   r   
ValueErrorwarningswarnnponesr   r   window_transformintheightwidthr   )datasetshapesr   r   croppad	pad_widthr   r   windowmaskr   r   s                P/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/mask.pyraster_geometry_maskr"      s   r - K" ,,V4	'V\\):;	 %%	(#gmm*<=	V#,GD F""7  - BCCMM P Q wwW]]23/v>5D&&,,-s   
B- -A,DDc
           
         Uc  U R                   b  U R                   nOSn[        XX#UXxS9u  pnU	c  U R                  4U
R                  -   nO;[	        U	[
        5      (       a  U
R                  nO[        U	5      4U
R                  -   nU R                  XSU	S9nUR                  U
-  Ul        U(       a  UR                  U5      nX4$ )a	  Creates a masked or filled array using input shapes.
Pixels are masked or set to nodata outside the input shapes, unless
`invert` is `True`.

If shapes do not overlap the raster and crop=True, a ValueError is
raised.  Otherwise, a warning is raised.

Parameters
----------
dataset : a dataset object opened in 'r' mode
    Raster to which the mask will be applied.
shapes : iterable object
    The values must be a GeoJSON-like dict or an object that implements
    the Python geo interface protocol (such as a Shapely Polygon).
all_touched : bool (opt)
    Include a pixel in the mask if it touches any of the shapes.
    If False (default), include a pixel only if its center is within one of
    the shapes, or if it is selected by Bresenham's line algorithm.
invert : bool (opt)
    If False (default) pixels outside shapes will be masked.  If True,
    pixels inside shape will be masked.
nodata : int or float (opt)
    Value representing nodata within each raster band. If not set,
    defaults to the nodata value for the input raster. If there is no
    set nodata value for the raster, it defaults to 0.
filled : bool (opt)
    If True, the pixels outside the features will be set to nodata.
    If False, the output array will contain the original pixel data,
    and only the mask will be based on shapes.  Defaults to True.
crop : bool (opt)
    Whether to crop the raster to the extent of the shapes. Defaults to
    False.
pad : bool (opt)
    If True, the features will be padded in each direction by
    one half of a pixel prior to cropping raster. Defaults to False.
indexes : list of ints or a single int (opt)
    If `indexes` is a list, the result is a 3D array, but is
    a 2D array if it is a band index number.

Returns
-------
tuple

    Two elements:

        masked : numpy.ndarray or numpy.ma.MaskedArray
            Data contained in the raster after applying the mask. If
            `filled` is `True` and `invert` is `False`, the return will be
            an array where pixels outside shapes are set to the nodata value
            (or nodata inside shapes if `invert` is `True`).

            If `filled` is `False`, the return will be a MaskedArray in
            which pixels outside shapes are `True` (or `False` if `invert`
            is `True`).

        out_transform : affine.Affine()
            Information for mapping pixel coordinates in `masked` to another
            coordinate system.
r   )r   r   r   r   r   T)r   r   maskedindexes)
nodatar"   countr   
isinstancer   lenreadr    filled)r   r   r   r   r&   r+   r   r   r   r%   
shape_maskr   r   r   	out_images                  r!   r    r    p   s    | ~>>%^^FF$8[d%&!J6 ]]%
(8(88		GS	!	!$$	\$z'7'77	4  JI ^^j0IN$$V,	    )FFFF      ?)FFNTFFr/   N)__doc__loggingr   numpyr   rasterio.errorsr   rasterio.featuresr   r   	getLogger__name__loggerr"   r     r.   r!   <module>r9      sJ    =    ' < 
		8	$ EJ:=^#B CGDHW r.   