Skip to main content
`Ctrl`+`K`

# ng911ok.lib.geomutils module

exception InvalidGeometryError(geometry: PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference)

  Bases: `ValueError`

  Class to store and return invalid geometry error messages received from :meth: _cast_single_geometry.

_bind_and_call(func: Callable[[_P], _T], /, arg_dict: dict[str, Any]) → _T

  Calls a function with a `dict` of arguments, handling cases like positional-only parameters and variable-length (`*args`/`**kwargs`) parameters.

_cast_single_geometry(geom_object: PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference, target_type: type[T_Geometry]) → T_Geometry

  Converts a single geom_object between corresponding `arcpy` and `arcgis.geometry` types.

_get_corresponding_geom_type(geom_type: type[PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference]) → type[PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference]

cast_geometry(match_type_of: str, /, **targets: type[PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference]) → Callable[[Callable[[...], PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference]], Callable[[...], PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference]]

  Similar to `cast_input_geometry()`, but also ensures that the return type of the decorated function matches that of the argument for the parameter named match_type_of.

cast_input_geometry(**targets: type[PointGeometry | Point | Multipoint | MultiPoint | Polyline | Polyline | Polygon | Polygon | SpatialReference | SpatialReference]) → Callable[[Callable[[_P], _T]], Callable[[_P], _T]]

  Decorator factory to allow decorated functions to take geometry objects from either the `arcpy` or `arcgis` packages while ensuring that parameters specified in targets will always be of one specific type.

  For example, consider these functions:

      def hopefully_arcpy_polygon(polygon_obj: arcpy.Polygon | arcgis.geometry.Polygon) -> None:
          assert isinstance(polygon, arcpy.Polygon)

      @cast_input_geometry(polygon_obj=arcpy.Polygon)
      def definitely_arcpy_polygon(polygon_obj: arcpy.Polygon | arcgis.geometry.Polygon) -> None:
          assert isinstance(polygon, arcpy.Polygon)

  The function `hopefully_arcpy_polygon` will only succeed if it is called with an instance of `arcpy.Polygon` as the `polygon_obj` argument. The function `definitely_arcpy_polygon`, however will succeed even if `polygon_obj` is an instance of `arcgis.geometry.Polygon` because of the decorator.

  Parameters:

    targets (type[arcpy.Geometry | arcpy.SpatialReference | arcgis.geometry.BaseGeometry]) – Mapping of parameter name(s) in the decorated function to the desired type of each argument

  Returns:

    A decorator

  Return type:

    Callable[[Callable], Callable]

get_end_from_curve(curve_dict: dict[Literal['a', 'b', 'c'], list]) → list[float | None]

  Given a curve dict, returns the endpoint of the curve.

get_midpoint(line_feature: Polyline | Polyline) → PointGeometry

  Returns an `arcpy.PointGeometry` at the midpoint of line_feature.

get_segment(line: T_Polyline, part: int, start_vertex: int, end_vertex: int) → T_Polyline

  Extracts and returns the portion of a line between two vertices. Supports true curves.

  Parameters:

    - line (T_Polyline) – The line feature

    - part (int) – Index of the part; should be 0 unless the feature is multipart

    - start_vertex (int) – Index of the first vertex to include in the returned segment

    - end_vertex (int) – Index of the last vertex to include in the returned segment; must be greater than start_vertex

  Returns:

    A single-part line feature

  Return type:

    T_Polyline

get_segments(line: T_Polyline, part: int) → list[T_Polyline]

  Splits a line feature at its vertices and returns a list of segments. If line is multipart, only one part’s worth of segments is returned. Supports true curves.

  Parameters:

    - line (T_Polyline) – The line feature

    - part (int) – Index of the part; should be 0 unless the feature is multipart

  Returns:

    List of the segments that comprise the specified part of line

  Return type:

    list[T_Polyline]

get_vertex(line: Polyline | Polyline, vertex_index: int) → PointGeometry
get_vertex(line: Polyline | Polyline, part_index: int, vertex_index: int) → PointGeometry

point_beside_line(line_feature: ~arcpy.arcobjects.geometries.Polyline | ~arcgis.geometry._types.Polyline, side: ~typing.Literal['LEFT', 'RIGHT'], distance_meters: float, segment: int = 0, part: int = 0, method: ~typing.Literal['GEODESIC', 'PLANAR', 'GREAT_ELLIPTIC', 'LOXODROME', 'PRESERVE_SHAPE'] = 'GEODESIC', return_as: type[~ng911ok.lib.geomutils.T_PointGeom] = <class 'arcpy.arcobjects.geometries.PointGeometry'>, messenger: ~ng911ok.lib.gdbsession.GPMessenger | None = None) → T_PointGeom

  Returns a point 90 degrees to either the left or the right of the input line_feature, offset by distance_meters.