Download datacollection/separate_polygons.py from kabiriitb/rockglacierNET: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/kabiriitb/rockglacierNET/resolve/main/datacollection/separate_polygons.py
- Command line
-
hf download hf://kabiriitb/rockglacierNET/datacollection/separate_polygons.py
-
curl -L -o separate_polygons.py https://huggingface.co/kabiriitb/rockglacierNET/resolve/main/datacollection/separate_polygons.py
1.25 kB
| import os | |
| import yaml | |
| import geopandas as gpd | |
| def load_config(): | |
| config_path = os.path.join(os.path.dirname(__file__), 'config.yaml') | |
| with open(config_path, 'r') as f: | |
| return yaml.safe_load(f) | |
| def main(): | |
| config = load_config() | |
| feature_stack_shp = os.path.join(os.path.dirname(__file__), config['paths']['rock_glacier_boundary_shp']) | |
| output_dir = os.path.join(os.path.dirname(__file__), config['paths']['output_dir'], 'individual_polygons') | |
| os.makedirs(output_dir, exist_ok=True) | |
| print(f"Loading feature stack shapefile: {feature_stack_shp}") | |
| try: | |
| gdf = gpd.read_file(feature_stack_shp) | |
| except Exception as e: | |
| print(f"Error loading {feature_stack_shp}: {e}") | |
| print("Please ensure you have updated the 'feature_stack_shp' path in config.yaml.") | |
| return | |
| print(f"Separating {len(gdf)} feature stack polygons...") | |
| for idx, row in gdf.iterrows(): | |
| single_gdf = gpd.GeoDataFrame([row], crs=gdf.crs) | |
| out_json = os.path.join(output_dir, f"polygon_{idx:04d}.geojson") | |
| single_gdf.to_file(out_json, driver="GeoJSON") | |
| print(f"Done! Saved {len(gdf)} GeoJSON files to {output_dir}") | |
| if __name__ == "__main__": | |
| main() | |