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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wkt_polygon | str | yes | - | A WKT (Well-Known Text) string representing a polygon |
geojson_path | str | no | '/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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wkt_polygon | str | yes | - | A WKT (Well-Known Text) string representing a polygon |
geojson_path | str | no | '/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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wkt_polygon | str | yes | - | A WKT (Well-Known Text) string representing a polygon |
geojson_path | str | no | '/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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | inferred from implementation | yes | - | inferred from implementation. |
contained | inferred from implementation | yes | - | 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
rectangle | dict | yes | - | 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
contained | list | yes | - | 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.