From 66d2a6eb31786f776ccb5c4b8a08ed78140ec372 Mon Sep 17 00:00:00 2001 From: Alexey Pechnikov Date: Mon, 22 Jan 2024 22:53:28 +0700 Subject: [PATCH] Enhance DEM processing when AOI defined by GeoSeries --- pygmtsar/pygmtsar/Stack_dem.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pygmtsar/pygmtsar/Stack_dem.py b/pygmtsar/pygmtsar/Stack_dem.py index cb615b6e..50b1ec7f 100644 --- a/pygmtsar/pygmtsar/Stack_dem.py +++ b/pygmtsar/pygmtsar/Stack_dem.py @@ -201,7 +201,7 @@ def download_dem(self, geometry='auto', product='1s'): This method uses the GMT servers to download SRTM 1 or 3 arc-second DEM data. The downloaded data is then preprocessed by removing the EGM96 geoid to make the heights relative to the WGS84 ellipsoid. """ - import pandas as pd + import geopandas as gpd import xarray as xr import numpy as np import pygmt @@ -232,8 +232,10 @@ def download_dem(self, geometry='auto', product='1s'): if type(geometry) == str and geometry == 'auto': # apply scenes geometry geometry = self.get_extent().buffer(self.buffer_degrees) - elif isinstance(geometry, pd.DataFrame): + elif isinstance(geometry, gpd.GeoDataFrame): geometry = geometry.dissolve().envelope.item() + elif isinstance(geometry, gpd.GeoSeries): + geometry = geometry.unary_union.envelope minx, miny, maxx, maxy = np.round(geometry.bounds, 5) #print ('minx, miny, maxx, maxy', minx, miny, maxx, maxy) @@ -279,7 +281,7 @@ def load_dem(self, filename, geometry='auto'): import xarray as xr import numpy as np import rioxarray as rio - import pandas as pd + import geopandas as gpd import os dem_filename = os.path.join(self.basedir, 'DEM_WGS84.nc') @@ -305,7 +307,7 @@ def load_dem(self, filename, geometry='auto'): if type(geometry) == str and geometry == 'auto': # apply scenes geometry extent = self.get_extent().buffer(self.buffer_degrees) - elif isinstance(geometry, pd.DataFrame): + elif isinstance(geometry, gpd.GeoDataFrame): extent = geometry.dissolve().envelope.item() #minx, miny, maxx, maxy = np.round(geometry.bounds, 5) #print ('minx, miny, maxx, maxy', minx, miny, maxx, maxy)