@@ -3818,28 +3818,32 @@ def get_pc_collections(self) -> None:
3818
3818
setattr (self , "pc_collections" , get_pc_collections ())
3819
3819
3820
3820
def save_draw_features (
3821
- self , out_file : str , indent : int = 4 , crs : Optional [str ] = "epsg :4326" , ** kwargs
3821
+ self , out_file : str , crs : Optional [str ] = "EPSG :4326" , ** kwargs
3822
3822
) -> None :
3823
3823
"""Save the draw features to a file.
3824
3824
3825
3825
Args:
3826
3826
out_file (str): The output file path.
3827
- indent (int, optional): The indentation level when saving data as a GeoJSON. Defaults to 4.
3828
- crs (str, optional): The CRS of the output GeoJSON. Defaults to "epsg:4326".
3827
+ crs (str, optional): The CRS of the output GeoJSON. Defaults to "EPSG:4326".
3829
3828
"""
3830
- import geopandas as gpd
3831
3829
3832
- out_file = check_file_path (out_file )
3830
+ if self .user_rois is not None :
3831
+ import geopandas as gpd
3833
3832
3834
- self .update_draw_features ()
3835
- geojson = {
3836
- "type" : "FeatureCollection" ,
3837
- "features" : self .draw_features ,
3838
- }
3833
+ out_file = check_file_path (out_file )
3839
3834
3840
- gdf = gpd .GeoDataFrame .from_features (geojson )
3841
- gdf .crs = "epsg:4326"
3842
- gdf .to_crs (crs ).to_file (out_file , ** kwargs )
3835
+ self .update_draw_features ()
3836
+ geojson = {
3837
+ "type" : "FeatureCollection" ,
3838
+ "features" : self .draw_features ,
3839
+ }
3840
+
3841
+ gdf = gpd .GeoDataFrame .from_features (geojson , crs = "EPSG:4326" )
3842
+ if crs != "EPSG:4326" :
3843
+ gdf = gdf .to_crs (crs )
3844
+ gdf .to_file (out_file , ** kwargs )
3845
+ else :
3846
+ print ("No draw features to save." )
3843
3847
3844
3848
def update_draw_features (self ) -> None :
3845
3849
"""Update the draw features by removing features that have been edited and no longer exist."""
0 commit comments