Skip to content

Commit

Permalink
Address gdal warning
Browse files Browse the repository at this point in the history
  • Loading branch information
acpaquette committed Nov 25, 2024
1 parent 5605b49 commit 4b431f6
Showing 1 changed file with 31 additions and 39 deletions.
70 changes: 31 additions & 39 deletions ale/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,45 +422,51 @@ def short_mission_name(self):
"""
return self.__module__.split('.')[-1].split('_')[0]

@property
def projection(self):
"""
Return projection information generated by osgeo.
Returns
-------
str
A string representation of the projection information.
"""
if not hasattr(self, "_projection"):
@property
def read_geodata(self):
if not hasattr(self, "_geodata"):
try:
from osgeo import gdal
from osgeo import gdal
gdal.UseExceptions()
except:
self._projection = ""
return self._projection

geodata = None
self._geodata = None
if isinstance(self._file, pvl.PVLModule):
# save it to a temp folder
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(pvl.dumps(self._file))

geodata = gdal.Open(tempfile.name)
self._geodata = gdal.Open(tempfile.name)
else:
# should be a path
if not os.path.exists(self._file):
self._projection = ""
self._geodata = None
else:
geodata = gdal.Open(self._file)

self._geodata = gdal.Open(self._file)

return self._geodata

@property
def projection(self):
"""
Return projection information generated by osgeo.
Returns
-------
str
A string representation of the projection information.
"""
if not hasattr(self, "_projection"):
# Try to get the projection, if we are unsuccessful set it
# to empty
try:
self._projection = geodata.GetSpatialRef().ExportToProj4()
self._projection = self.read_geodata.GetSpatialRef().ExportToProj4()
except:
self._projection = ""
self._projection = ""

return self._projection

@property
Expand All @@ -475,25 +481,11 @@ def geotransform(self):
"""
if not hasattr(self, "_geotransform"):
try:
from osgeo import gdal
except:
# Try to get the geotransform, if we are unsuccessful set it
# to the identity
try:
self._geotransform = self.read_geodata.GetGeoTransform()
except:
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
return self._geotransform

if isinstance(self._file, pvl.PVLModule):
# save it to a temp folder
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(pvl.dumps(self._file))

geodata = gdal.Open(tempfile.name)
self._geotransform = geodata.GetGeoTransform()
else:
# should be a path
if not os.path.exists(self._file):
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
else:
geodata = gdal.Open(self._file)
self._geotransform = geodata.GetGeoTransform()

return self._geotransform

0 comments on commit 4b431f6

Please sign in to comment.