# Path: mapchete/io/vector.py
# def read_vector_window(inp, tile, validity_check=True, clip_to_crs_bounds=False):
# def _read_vector_window(inp, tile, validity_check=True, clip_to_crs_bounds=False):
# def write_vector_window(
#     in_data=None,
#     out_driver="GeoJSON",
#     out_schema=None,
#     out_tile=None,
#     out_path=None,
#     bucket_resource=None,
#     allow_multipart_geometries=True,
# ):
#     def __init__(self, tile=None, features=None, schema=None, driver=None):
#     def __enter__(self):
#     def __exit__(self, *args):
# def _get_reprojected_features(
#     inp=None,
#     dst_bounds=None,
#     dst_crs=None,
#     validity_check=False,
#     clip_to_crs_bounds=False,
# ):
# def bounds_intersect(bounds1, bounds2):
#     def __init__(self):
#     def insert(self, id, bounds):
#     def intersection(self, bounds):
#     def __init__(self, features, index="rtree", allow_non_geo_objects=False, crs=None):
#     def __repr__(self):  # pragma: no cover
#     def __len__(self):
#     def __str__(self):  # pragma: no cover
#     def __getitem__(self, key):
#     def __iter__(self):
#     def items(self):
#     def keys(self):
#     def values(self):
#     def filter(self, bounds=None, bbox=None):
#     def _update_bounds(self, bounds):
#     def _get_feature_id(self, feature):
#     def _get_feature_bounds(self, feature, allow_non_geo_objects=False):
# def convert_vector(inp, out, overwrite=False, exists_ok=True, **kwargs):
# def read_vector(inp, index="rtree"):
# class VectorWindowMemoryFile:
# class FakeIndex:
# class IndexedFeatures:


import numpy as np
import numpy.ma as ma
from shapely.ops import unary_union
from rasterio.features import geometry_mask
from mapchete.io.vector import to_shape



def clip_array_with_vector(
    array, array_affine, geometries, inverted=False, clip_buffer=0
):
    """
    Clip input array with a vector list.

    Parameters
    ----------
    array : array
        input raster data
    array_affine : Affine
        Affine object describing the raster's geolocation
    geometries : iterable
        iterable of dictionaries, where every entry has a 'geometry' and
        'properties' key.
    inverted : bool
        invert clip (default: False)
    clip_buffer : integer
        buffer (in pixels) geometries before clipping

    Returns
    -------
    clipped array : array
    """
    # buffer input geometries and clean up
    buffered_geometries = []
    for feature in geometries:

# Path: mapchete/io/vector.py
# def read_vector_window(inp, tile, validity_check=True, clip_to_crs_bounds=False):
# def _read_vector_window(inp, tile, validity_check=True, clip_to_crs_bounds=False):
# def write_vector_window(
#     in_data=None,
#     out_driver="GeoJSON",
#     out_schema=None,
#     out_tile=None,
#     out_path=None,
#     bucket_resource=None,
#     allow_multipart_geometries=True,
# ):
#     def __init__(self, tile=None, features=None, schema=None, driver=None):
#     def __enter__(self):
#     def __exit__(self, *args):
# def _get_reprojected_features(
#     inp=None,
#     dst_bounds=None,
#     dst_crs=None,
#     validity_check=False,
#     clip_to_crs_bounds=False,
# ):
# def bounds_intersect(bounds1, bounds2):
#     def __init__(self):
#     def insert(self, id, bounds):
#     def intersection(self, bounds):
#     def __init__(self, features, index="rtree", allow_non_geo_objects=False, crs=None):
#     def __repr__(self):  # pragma: no cover
#     def __len__(self):
#     def __str__(self):  # pragma: no cover
#     def __getitem__(self, key):
#     def __iter__(self):
#     def items(self):
#     def keys(self):
#     def values(self):
#     def filter(self, bounds=None, bbox=None):
#     def _update_bounds(self, bounds):
#     def _get_feature_id(self, feature):
#     def _get_feature_bounds(self, feature, allow_non_geo_objects=False):
# def convert_vector(inp, out, overwrite=False, exists_ok=True, **kwargs):
# def read_vector(inp, index="rtree"):
# class VectorWindowMemoryFile:
# class FakeIndex:
# class IndexedFeatures:


# Path: mapchete/commons/clip.py
import numpy as np
import numpy.ma as ma
from shapely.ops import unary_union
from rasterio.features import geometry_mask
from mapchete.io.vector import to_shape




def clip_array_with_vector(
    array, array_affine, geometries, inverted=False, clip_buffer=0
):
    """
    Clip input array with a vector list.

    Parameters
    ----------
    array : array
        input raster data
    array_affine : Affine
        Affine object describing the raster's geolocation
    geometries : iterable
        iterable of dictionaries, where every entry has a 'geometry' and
        'properties' key.
    inverted : bool
        invert clip (default: False)
    clip_buffer : integer
        buffer (in pixels) geometries before clipping

    Returns
    -------
    clipped array : array
    """
    # buffer input geometries and clean up
    buffered_geometries = []
    for feature in geometries:

        feature_geom = to_shape(feature["geometry"])