Skip to content

Commit

Permalink
fix: allow 2 minutes for server connection & add add available ga ser…
Browse files Browse the repository at this point in the history
…ver link
  • Loading branch information
AngRodrigues committed May 31, 2024
1 parent a20fb2a commit 900a50d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions map2loop/mapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def open_http_query(url: str):
"""
try:
request = urllib.Request(url, headers={"Accept-Encoding": "gzip"})
response = urllib.request.urlopen(request, timeout=30)
response = urllib.request.urlopen(request, timeout=120)
if response.info().get("Content-Encoding") == "gzip":
return GzipFile(fileobj=BytesIO(response.read()))
else:
Expand Down Expand Up @@ -495,12 +495,14 @@ def __retrieve_tif(self, filename: str):
_type_: The open geotiff in a gdal handler
"""
self.__check_and_create_tmp_path()

# For gdal debugging use exceptions
gdal.UseExceptions()
bb_ll = tuple(self.bounding_box_polygon.to_crs("EPSG:4326").geometry.total_bounds)
# try:

if filename.lower() == "aus" or filename.lower() == "au":
url = "http://services.ga.gov.au/gis/services/DEM_SRTM_1Second_over_Bathymetry_Topography/MapServer/WCSServer?"
url = "http://gaservices.ga.gov.au/site_9/services/DEM_SRTM_1Second_over_Bathymetry_Topography/MapServer/WCSServer?"
# previous link version: "http://services.ga.gov.au/gis/services/DEM_SRTM_1Second_over_Bathymetry_Topography/MapServer/WCSServer?"
wcs = WebCoverageService(url, version="1.0.0")
coverage = wcs.getCoverage(
identifier="1", bbox=bb_ll, format="GeoTIFF", crs=4326, width=2048, height=2048
Expand All @@ -512,12 +514,14 @@ def __retrieve_tif(self, filename: str):
with open(tmp_file, "wb") as fh:
fh.write(coverage.read())
tif = gdal.Open(tmp_file)

elif filename == "hawaii":
import netCDF4

bbox_str = (
f"[({str(bb_ll[1])}):1:({str(bb_ll[3])})][({str(bb_ll[0])}):1:({str(bb_ll[2])})]"
)

filename = f"https://pae-paha.pacioos.hawaii.edu/erddap/griddap/srtm30plus_v11_land.nc?elev{bbox_str}"
f = urllib.request.urlopen(filename)
ds = netCDF4.Dataset("in-mem-file", mode="r", memory=f.read())
Expand Down

0 comments on commit 900a50d

Please sign in to comment.