diff --git a/docs/notebooks/99_wetlands.ipynb b/docs/notebooks/99_wetlands.ipynb index 45b98fb47f..54ce5a4538 100644 --- a/docs/notebooks/99_wetlands.ipynb +++ b/docs/notebooks/99_wetlands.ipynb @@ -233,7 +233,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/leafmap/leafmap.py b/leafmap/leafmap.py index b5669dfae1..a8d17594c0 100644 --- a/leafmap/leafmap.py +++ b/leafmap/leafmap.py @@ -3818,28 +3818,32 @@ def get_pc_collections(self) -> None: setattr(self, "pc_collections", get_pc_collections()) def save_draw_features( - self, out_file: str, indent: int = 4, crs: Optional[str] = "epsg:4326", **kwargs + self, out_file: str, crs: Optional[str] = "EPSG:4326", **kwargs ) -> None: """Save the draw features to a file. Args: out_file (str): The output file path. - indent (int, optional): The indentation level when saving data as a GeoJSON. Defaults to 4. - crs (str, optional): The CRS of the output GeoJSON. Defaults to "epsg:4326". + crs (str, optional): The CRS of the output GeoJSON. Defaults to "EPSG:4326". """ - import geopandas as gpd - out_file = check_file_path(out_file) + if self.user_rois is not None: + import geopandas as gpd - self.update_draw_features() - geojson = { - "type": "FeatureCollection", - "features": self.draw_features, - } + out_file = check_file_path(out_file) - gdf = gpd.GeoDataFrame.from_features(geojson) - gdf.crs = "epsg:4326" - gdf.to_crs(crs).to_file(out_file, **kwargs) + self.update_draw_features() + geojson = { + "type": "FeatureCollection", + "features": self.draw_features, + } + + gdf = gpd.GeoDataFrame.from_features(geojson, crs="EPSG:4326") + if crs != "EPSG:4326": + gdf = gdf.to_crs(crs) + gdf.to_file(out_file, **kwargs) + else: + print("No draw features to save.") def update_draw_features(self) -> None: """Update the draw features by removing features that have been edited and no longer exist.""" diff --git a/mkdocs.yml b/mkdocs.yml index 89e5d3c096..00bf87255c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -78,6 +78,7 @@ plugins: "notebooks/87_actinia.ipynb", "notebooks/88_nasa_earth_data.ipynb", "notebooks/94_mapbox.ipynb", + "notebooks/99_wetlands.ipynb", ] markdown_extensions: