Module: sarpyx.utils.geos

File: sarpyx/utils/geos.py

Point containment checker for grid points within WKT polygons.

Exported Symbols (__all__)

No explicit __all__ list. Public symbols inferred from implementation.

Public Functions (6)

check_points_in_polygon function

Check which points from the GeoJSON file are contained within the given WKT polygon.

File location: sarpyx/utils/geos.py:11

Signature

check_points_in_polygon(wkt_polygon: str, geojson_path: str='/Data_large/SARGFM/grid_10km.geojson') -> List[Dict[str, Any]]

Parameters

ParameterTypeRequiredDefaultDescription
wkt_polygonstryes-A WKT (Well-Known Text) string representing a polygon
geojson_pathstrno'/Data_large/SARGFM/grid_10km.geojson'Path to the GeoJSON file containing point features

Return Type

List[Dict[str, Any]]

List of feature dictionaries containing points that fall within the polygon. Each feature includes properties (name, row, col, row_idx, col_idx, utm_zone, epsg) and geometry (coordinates). Example: >>> wkt_poly = "POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))" >>> contained_points = check_points_in_polygon(wkt_poly) >>> print(f"Found {len(contained_points)} points")

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • filesystem

Example Usage

from sarpyx.utils.geos import check_points_in_polygon

result = check_points_in_polygon(wkt_polygon=<wkt_polygon>)

Edge Cases

Includes optional parameters with implementation-defined fallback behavior.

get_point_names function

Get the names of points contained within the given WKT polygon.

File location: sarpyx/utils/geos.py:48

Signature

get_point_names(wkt_polygon: str, geojson_path: str='/Data_large/SARGFM/grid_10km.geojson') -> List[str]

Parameters

ParameterTypeRequiredDefaultDescription
wkt_polygonstryes-A WKT (Well-Known Text) string representing a polygon
geojson_pathstrno'/Data_large/SARGFM/grid_10km.geojson'Path to the GeoJSON file containing point features

Return Type

List[str]

List of point names (e.g., ["946D_176L", "946D_175L", ...])

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import get_point_names

result = get_point_names(wkt_polygon=<wkt_polygon>)

Edge Cases

Includes optional parameters with implementation-defined fallback behavior.

get_point_coordinates function

Get the coordinates of points contained within the given WKT polygon.

File location: sarpyx/utils/geos.py:66

Signature

get_point_coordinates(wkt_polygon: str, geojson_path: str='/Data_large/SARGFM/grid_10km.geojson') -> List[tuple]

Parameters

ParameterTypeRequiredDefaultDescription
wkt_polygonstryes-A WKT (Well-Known Text) string representing a polygon
geojson_pathstrno'/Data_large/SARGFM/grid_10km.geojson'Path to the GeoJSON file containing point features

Return Type

List[tuple]

List of coordinate tuples [(lon, lat), ...]

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import get_point_coordinates

result = get_point_coordinates(wkt_polygon=<wkt_polygon>)

Edge Cases

Includes optional parameters with implementation-defined fallback behavior.

is_point_in_contained function

inferred from implementation.

File location: sarpyx/utils/geos.py:350

Signature

is_point_in_contained(name, contained)

Parameters

ParameterTypeRequiredDefaultDescription
nameinferred from implementationyes-inferred from implementation.
containedinferred from implementationyes-inferred from implementation.

Return Type

inferred from implementation

inferred from implementation.

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import is_point_in_contained

result = is_point_in_contained(name=<name>, contained=<contained>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

rectangle_to_wkt function

Convert a rectangle dictionary to WKT POLYGON format.

File location: sarpyx/utils/geos.py:358

Signature

rectangle_to_wkt(rectangle: dict) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rectangledictyes-Dictionary with keys 'TL', 'TR', 'BR', 'BL', each containing a GeoJSON Feature with geometry.coordinates [lon, lat].

Return Type

str

WKT POLYGON string in format 'POLYGON ((lon lat, lon lat, ...))' Example: >>> rect = { ... 'TL': {'geometry': {'coordinates': [32.37, -26.68]}}, ... 'TR': {'geometry': {'coordinates': [32.47, -26.68]}}, ... 'BR': {'geometry': {'coordinates': [32.49, -26.77]}}, ... 'BL': {'geometry': {'coordinates': [32.39, -26.77]}} ... } >>> rectangle_to_wkt(rect) 'POLYGON ((32.37 -26.68, 32.47 -26.68, 32.49 -26.77, 32.39 -26.77, 32.37 -26.68))'

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import rectangle_to_wkt

result = rectangle_to_wkt(rectangle=<rectangle>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

rectanglify function

Build rectangles for cutting based on contained points.

File location: sarpyx/utils/geos.py:396

Signature

rectanglify(contained: list) -> list | None

Parameters

ParameterTypeRequiredDefaultDescription
containedlistyes-A list of GeoJSON-like features, where each feature contains properties (e.g., 'row', 'col', 'name') and geometry (e.g., coordinates).

Return Type

list | None

list | None: A list of rectangles, where each rectangle is represented as a dictionary with keys 'TL', 'TR', 'BR', 'BL' (top-left, top-right, bottom-right, bottom-left). Returns None if no rectangles are found. Example: >>> contained_points = [ ... {'properties': {'name': '1U_1R', 'row': '1U', 'col': '1R'}, 'geometry': {'coordinates': [0, 0]}}, ... {'properties': {'name': '1U_2R', 'row': '1U', 'col': '2R'}, 'geometry': {'coordinates': [1, 0]}}, ... {'properties': {'name': '2U_1R', 'row': '2U', 'col': '1R'}, 'geometry': {'coordinates': [0, 1]}}, ... {'properties': {'name': '2U_2R', 'row': '2U', 'col': '2R'}, 'geometry': {'coordinates': [1, 1]}} ... ] >>> rectangles = rectanglify(contained_points) >>> print(rectangles)

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • io

Example Usage

from sarpyx.utils.geos import rectanglify

result = rectanglify(contained=<contained>)

Edge Cases

Documented return may be None for some execution paths.

Public Classes (1)

GridNavigator class

Grid navigation utilities for moving between adjacent grid points. This module provides GridNavigator which navigates using only point names without requiring the Grid object. The grid naming convention: - Rows: XD (south of equator), 0U (equator), XU (north of equator) - Columns: XL (west of prime meridian), 0R (prime meridian), XR (east of prime meridian) Navigation: - North (up): Row number decreases in D hemisphere, increases in U hemisphere - South (down): Row number increases in D hemisphere, decreases in U hemisphere - East (right): Column number increases in R hemisphere, decreases in L hemisphere - West (left): Column number decreases in R hemisphere, increases in L hemisphere

File location: sarpyx/utils/geos.py:86

Class Signature

class GridNavigator

Constructor Parameters

Return Type

GridNavigator instances.

Exceptions

Construction/runtime exceptions are inferred from implementation and method-level documentation.

Side Effects

See method-level side effects below.

Example Usage

from sarpyx.utils.geos import GridNavigator

obj = GridNavigator(...)  # inferred from implementation

Edge Cases

No class-level edge-case section is explicitly documented; rely on method-level checks and raised exceptions.

Public Methods (8)

GridNavigator.move_up method

Get the name of the point immediately above (northward).

File location: sarpyx/utils/geos.py:167

Signature

move_up(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the upper point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_up(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_down method

Get the name of the point immediately below (southward).

File location: sarpyx/utils/geos.py:197

Signature

move_down(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the lower point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_down(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_right method

Get the name of the point immediately to the right (eastward).

File location: sarpyx/utils/geos.py:230

Signature

move_right(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the right point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_right(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_left method

Get the name of the point immediately to the left (westward).

File location: sarpyx/utils/geos.py:260

Signature

move_left(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the left point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_left(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_up_right method

Get the name of the point diagonally upper-right (north-east).

File location: sarpyx/utils/geos.py:290

Signature

move_up_right(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the upper-right point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_up_right(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_up_left method

Get the name of the point diagonally upper-left (north-west).

File location: sarpyx/utils/geos.py:307

Signature

move_up_left(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the upper-left point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_up_left(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_down_right method

Get the name of the point diagonally lower-right (south-east).

File location: sarpyx/utils/geos.py:321

Signature

move_down_right(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the lower-right point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_down_right(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.

GridNavigator.move_down_left method

Get the name of the point diagonally lower-left (south-west).

File location: sarpyx/utils/geos.py:335

Signature

move_down_left(self, row: str, col: str) -> str

Parameters

ParameterTypeRequiredDefaultDescription
rowstryes-Current row (e.g., '298D', '5U')
colstryes-Current column (e.g., '323R', '10L')

Return Type

str

Name of the lower-left point

Exceptions

None explicitly documented; inferred from implementation.

Side Effects

  • inferred from implementation

Example Usage

from sarpyx.utils.geos import GridNavigator

# Constructor arguments are inferred from implementation.
obj = GridNavigator(...)  # inferred from implementation
result = obj.move_down_left(row=<row>, col=<col>)

Edge Cases

No explicit edge-case section found; behavior is inferred from implementation.