iduedu.get_4326_boundary

iduedu.get_4326_boundary(*, osm_id=None, territory=None)[source]

Normalize a territory boundary to a single EPSG:4326 Polygon.

Accepts either an osm_id (relation id) to fetch the boundary from OSM, a direct Polygon/MultiPolygon, or a GeoDataFrame. Returns a single Polygon in lon/lat. For MultiPolygon, the function returns its convex hull as a Polygon.

Parameters:
  • osm_id (int | None) – OSM relation id. If provided, boundary is fetched via Overpass.

  • territory (Polygon | MultiPolygon | gpd.GeoDataFrame | None) – Existing boundary geometry or a GeoDataFrame containing it. If GeoDataFrame is given, it is reprojected to 4326 and unioned (.union_all()).

Returns:

Boundary polygon in EPSG:4326.

Return type:

(shapely.Polygon)

Notes

  • Input Polygon is returned as-is (assumed already in EPSG:4326 by caller).

  • For MultiPolygon, a convex hull is returned (may slightly expand the area and fill gaps between parts).

  • For GeoDataFrame, the geometry is first reprojected to 4326 and dissolved via .union_all(); the result is then normalized to a Polygon (convex hull if needed).

Examples

>>> get_4326_boundary(osm_id=1114252)             # fetch by OSM id
>>> get_4326_boundary(territory=poly4326)         # keep polygon
>>> get_4326_boundary(territory=multi_poly_4326)  # convex hull of multipart
>>> get_4326_boundary(territory=territory_gdf)    # GDF -> to_crs(4326) -> union_all -> Polygon