code: def rasterize(
      shapes,
      out_shape=None,
      fill=0,
      out=None,
      transform=IDENTITY,
      all_touched=False,
      merge_alg=MergeAlg.replace,
      default_value=1,
      dtype=None,
      skip_invalid=True,
  ):
      """Return an image array with input geometries burned in.
  
      Warnings will be raised for any invalid or empty geometries, and
      an exception will be raised if there are no valid shapes
      to rasterize.
  
      Parameters
      ----------
      shapes : iterable of (`geometry`, `value`) pairs or geometries
          The `geometry` can either be an object that implements the geo
          interface or GeoJSON-like object. If no `value` is provided
          the `default_value` will be used. If `value` is `None` the
          `fill` value will be used.
      out_shape : tuple or list with 2 integers
          Shape of output :class:`numpy.ndarray`.
      fill : int or float, optional
          Used as fill value for all areas not covered by input
          geometries.
      out : numpy.ndarray, optional
          Array in which to store results. If not provided, out_shape
          and dtype are required.
      transform : Affine transformation object, optional
          Transformation from pixel coordinates of `source` to the
          coordinate system of the input `shapes`. See the `transform`
          property of dataset objects.
      all_touched : boolean, optional
          If True, all pixels touched by geometries will be burned in.  If
          false, only pixels whose center is within the polygon or that
          are selected by Bresenham's line algorithm will be burned in.
      merge_alg : MergeAlg, optional
          Merge algorithm to use. One of:
              MergeAlg.replace (default):
                  the new value will overwrite the existing value.
              MergeAlg.add:
                  the new value will be added to the existing raster.
      default_value : int or float, optional
          Used as value for all geometries, if not provided in `shapes`.
      dtype : rasterio or numpy.dtype, optional
          Used as data type for results, if `out` is not provided.
      skip_invalid : bool, optional
          If True (default), invalid shapes will be skipped. If False,
          ValueError will be raised.
  
      Returns
      -------
      numpy.ndarray :
          If `out` was not None then `out` is returned, it will have been
          modified in-place. If `out` was None, this will be a new array.
  
      Notes
      -----
      Valid data types for `fill`, `default_value`, `out`, `dtype` and
      shape values are "int16", "int32", "uint8", "uint16", "uint32",
      "float32", and "float64".
  
      This function requires significant memory resources. The shapes
      iterator will be materialized to a Python list and another C copy of
      that list will be made. The `out` array will be copied and
      additional temporary raster memory equal to 2x the smaller of `out`
      data or GDAL's max cache size (controlled by GDAL_CACHEMAX, default
      is 5% of the computer's physical memory) is required.
  
      If GDAL max cache size is smaller than the output data, the array of
      shapes will be iterated multiple times. Performance is thus a linear
      function of buffer size. For maximum speed, ensure that
      GDAL_CACHEMAX is larger than the size of `out` or `out_shape`.
      """
      valid_dtypes = (
          "int16",
          "int32",
          "uint8",
          "uint16",
          "uint32",
          "float32",
          "float64",
      )
      if GDALVersion.runtime().at_least("3.5"):
          valid_dtypes += ("int64", "uint64")
      if GDALVersion.runtime().at_least("3.7"):
          valid_dtypes += ("int8",)
  
      # The output data type is determined by the output array or dtype
      # parameter.
      dtype = out.dtype.name if out is not None else dtype
  
      if dtype is not None and dtype not in valid_dtypes:
          raise ValueError(
              "Data type specified by out array or dtype parameter is not supported."
          )
  
      valid_shapes = []
      shape_values = []
  
      for index, item in enumerate(shapes):
          if isinstance(item, (tuple, list)):
              geom, value = item
              if value is None:
                  value = fill
          else:
              geom = item
              value = default_value
  
          geom = getattr(geom, "__geo_interface__", None) or geom
  
          if is_valid_geom(geom):
              shape_values.append(value)
              geom_type = geom["type"]
  
              if geom_type == "GeometryCollection":
                  # GeometryCollections need to be handled as individual parts to
                  # avoid holes in output:
                  # https://github.com/rasterio/rasterio/issues/1253.
                  # Only 1-level deep since GeoJSON spec discourages nested
                  # GeometryCollections
                  for part in geom["geometries"]:
                      valid_shapes.append((part, value))
  
              elif geom_type == "MultiPolygon":
                  # Same issue as above
                  for poly in geom["coordinates"]:
                      valid_shapes.append(
                          (
                              {"type": "Polygon", "coordinates": poly},
                              value,
                          )
                      )
  
              else:
                  valid_shapes.append((geom, value))
  
          else:
              if skip_invalid:
                  warnings.warn(
                      "Invalid or empty shape {} at index {} will not be rasterized.".format(
                          geom, index
                      ),
                      ShapeSkipWarning,
                  )
              else:
                  raise ValueError(
                      "Invalid or empty shape cannot be rasterized."
                  )
  
      # If neither an out array or dtype were given, we get the output
      # data type from the shapes values, including the default.
      if not dtype and valid_shapes:
          values_arr = np.array(shape_values)
          dtype = values_arr.dtype.name
          assert dtype in ("int64", "float64")
  
          # GDAL 3.5 doesn't support int64 output. We'll try int32.
          if dtype not in valid_dtypes and dtype.startswith("int"):
              lo, hi = values_arr.min(), values_arr.max()
              if -2147483648 <= lo and hi <= 2147483647:
                  dtype = "int32"
              elif 0 <= lo and hi <= 4294967295:
                  dtype = "uint32"
              else:
                  raise ValueError(
                      "GDAL versions < 3.6 cannot rasterize int64 values."
                  )
  
      if out is not None:
          pass
  
      elif out_shape is not None:
          if len(out_shape) != 2:
              raise ValueError("Invalid out_shape, must be 2D")
          out = np.empty(out_shape, dtype=dtype)
          out.fill(fill)
  
      else:
          raise ValueError(
              "Either an out_shape or image must be provided"
          )
  
      if min(out.shape) == 0:
          raise ValueError("width and height must be > 0")
  
      transform = guard_transform(transform)
  
      if valid_shapes:
          _rasterize(
              valid_shapes, out, transform, all_touched, merge_alg
          )
  
      return out
  
imports: import logging
  import math
  import os
  import warnings
  import numpy
  import rasterio
  from rasterio import warp
  from rasterio._base import DatasetBase
  from rasterio._features import _shapes, _sieve, _rasterize, _bounds
  from rasterio.enums import MergeAlg
  from rasterio.env import ensure_env, GDALVersion
  from rasterio.errors import ShapeSkipWarning
  from rasterio.rio.helpers import coords
  from rasterio.transform import Affine
  from rasterio.transform import IDENTITY, guard_transform
  from rasterio.windows import Window
label_desc: Use image node_id 4 for calling a global function with example usage: rasterize(shapes, out_shape, fill, out, transform, all_touched, merge_alg, default_value, dtype, skip_invalid) and returns: out