Selaa lähdekoodia

TGIS: add semantic label to list of maps (#2231)

* add semantic label to list of maps as objects
Markus Metz 3 vuotta sitten
vanhempi
commit
8c4954ebfd
1 muutettua tiedostoa jossa 25 lisäystä ja 8 poistoa
  1. 25 8
      python/grass/temporal/abstract_space_time_dataset.py

+ 25 - 8
python/grass/temporal/abstract_space_time_dataset.py

@@ -1480,18 +1480,26 @@ class AbstractSpaceTimeDataset(AbstractDataset):
                 if row["key"] == "tgis_db_version":
                     db_version = int(float(row["value"]))
 
-        if db_version >= 1:
-            has_bt_columns = True
-            columns = "id,start_time,end_time, west,east,south,north,bottom,top"
-        else:
-            has_bt_columns = False
-            columns = "id,start_time,end_time, west,east,south,north"
-
-        rows = self.get_registered_maps(columns, where, order, dbif)
+        # use all columns
+        rows = self.get_registered_maps(None, where, order, dbif)
 
         if rows is not None:
+            has_bt_columns = False
+            has_semantic_label = False
+            first_row = True
             for row in rows:
+                if first_row:
+                    first_row = False
+                    # check keys in first row
+                    # note that 'if "bottom" in row' does not work
+                    # because row is not a dict but some db backend object
+                    if "bottom" in row.keys() and "top" in row.keys():
+                        has_bt_columns = True
+                    if "semantic_label" in row.keys():
+                        has_semantic_label = True
+
                 map = self.get_new_map_instance(row["id"])
+                # time
                 if self.is_time_absolute():
                     map.set_absolute_time(row["start_time"], row["end_time"])
                 elif self.is_time_relative():
@@ -1500,6 +1508,7 @@ class AbstractSpaceTimeDataset(AbstractDataset):
                         row["end_time"],
                         self.get_relative_time_unit(),
                     )
+                # space
                 # The fast way
                 if has_bt_columns:
                     map.set_spatial_extent_from_values(
@@ -1514,6 +1523,14 @@ class AbstractSpaceTimeDataset(AbstractDataset):
                 else:
                     map.spatial_extent.select(dbif)
 
+                # labels
+                if (
+                    has_semantic_label
+                    and row["semantic_label"] is not None
+                    and row["semantic_label"] != "None"
+                ):
+                    map.metadata.set_semantic_label(row["semantic_label"])
+
                 obj_list.append(copy.copy(map))
 
         if connection_state_changed: