Skip to content

Commit

Permalink
TGIS: add list of band names to t.info (OSGeo#1862)
Browse files Browse the repository at this point in the history
* TGIS: add list of distinct band names to `t.info`
  • Loading branch information
metzm authored Sep 14, 2021
1 parent 9b95bc1 commit 1b24c10
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
42 changes: 42 additions & 0 deletions python/grass/temporal/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""
from __future__ import print_function
from .base import SQLDatabaseInterface
from .core import SQLDatabaseInterfaceConnection

###############################################################################

Expand Down Expand Up @@ -1396,8 +1397,47 @@ def get_number_of_bands(self):
else:
return None

def get_band_names(self):
"""Get the distinct names of registered bands
The distinct band names are not stored in the metadata table
and fetched on-the-fly
:return: None if not found
"""

sql = "SELECT distinct band_reference FROM %s WHERE %s.id " % (
"raster_metadata",
"raster_metadata",
)

sql += "IN (SELECT id FROM %s)" % (str(self.get_raster_register()))

dbif = SQLDatabaseInterfaceConnection()
dbif.connect()
dbif.execute(sql, mapset=self.mapset)
rows = dbif.fetchall(mapset=self.mapset)
dbif.close()

if rows:
string = ""
count = 0
for row in rows:
if row["band_reference"]:
if count == 0:
string += row["band_reference"]
else:
string += ",%s" % row["band_reference"]
count += 1

if count > 0:
return string
else:
return None
else:
return None

raster_register = property(fget=get_raster_register, fset=set_raster_register)
number_of_bands = property(fget=get_number_of_bands)
band_names = property(fget=get_band_names)

def _print_info_body(self, shell=False):
"""Print information about this class (body part).
Expand All @@ -1411,8 +1451,10 @@ def _print_info_body(self, shell=False):
super()._print_info_body(shell)
if shell:
print("number_of_bands=" + str(self.get_number_of_bands()))
print("band_names=" + str(self.get_band_names()))
else:
print(" | Number of registered bands:. " + str(self.get_number_of_bands()))
print(" | Band names:................. " + str(self.get_band_names()))


###############################################################################
Expand Down
5 changes: 2 additions & 3 deletions python/grass/temporal/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ def register_maps_in_space_time_dataset(

if band_reference_in_file:
idx = 3 if end_time_in_file else 2
row["band_reference"] = (
line_list[idx].strip().upper()
) # case-insensitive
# case-sensitive, the user decides on the band name
row["band_reference"] = line_list[idx].strip()

row["id"] = AbstractMapDataset.build_id(mapname, mapset)

Expand Down

0 comments on commit 1b24c10

Please sign in to comment.