Skip to content

Commit

Permalink
Merge branch 'main' into 841-db.out.ogr
Browse files Browse the repository at this point in the history
  • Loading branch information
arohanajit authored Oct 31, 2024
2 parents 1f150ac + ba0a495 commit 2001602
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 90 deletions.
7 changes: 3 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ per-file-ignores =
doc/python/m.distance.py: E501
gui/scripts/d.wms.py: E501
gui/wxpython/image2target/g.gui.image2target.py: E501
gui/wxpython/nviz/*: E722
gui/wxpython/photo2image/g.gui.photo2image.py: E501
gui/wxpython/psmap/*: E501, E722
gui/wxpython/vdigit/*: F841, E722, F405, F403
Expand Down Expand Up @@ -93,9 +92,9 @@ per-file-ignores =
scripts/r.in.wms/wms_drv.py: E402, E722
scripts/r.in.wms/srs.py: E722
scripts/r.semantic.label/r.semantic.label.py: E501
scripts/v.report/v.report.py: E721
scripts/g.extension/g.extension.py: F841, E722, E501
scripts/v.unpack/v.unpack.py: E722, E501
scripts/db.out.ogr/db.out.ogr.py: F841
scripts/g.extension/g.extension.py: E501
scripts/v.unpack/v.unpack.py: E501n
scripts/v.import/v.import.py: E501
scripts/db.univar/db.univar.py: E501
scripts/i.pansharpen/i.pansharpen.py: E501
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/nviz/mapwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ def LoadDataLayers(self):
GError(parent=self, message=e.value)
# when nviz.tools is not yet ready
# during opening 3D view 2nd time
except:
except Exception:
pass

stop = gs.clock()
Expand Down
62 changes: 18 additions & 44 deletions gui/wxpython/nviz/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def SetInitialMaps(self):
else:
try:
selection = layers[0].GetName()
except:
except (AttributeError, IndexError):
continue
if ltype == "raster":
self.FindWindowById(self.win["surface"]["map"]).SetValue(selection)
Expand Down Expand Up @@ -734,24 +734,11 @@ def _createDataPage(self):
self.mainPanelData = SP.ScrolledPanel(parent=self)
self.mainPanelData.SetupScrolling(scroll_x=False)
self.mainPanelData.AlwaysShowScrollbars(hflag=False)
try: # wxpython <= 2.8.10
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData,
id=wx.ID_ANY,
style=fpb.FPB_DEFAULT_STYLE,
extraStyle=fpb.FPB_SINGLE_FOLD,
)
except:
try: # wxpython >= 2.8.11
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData,
id=wx.ID_ANY,
agwStyle=fpb.FPB_SINGLE_FOLD,
)
except: # to be sure
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData, id=wx.ID_ANY, style=fpb.FPB_SINGLE_FOLD
)
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData,
id=wx.ID_ANY,
agwStyle=fpb.FPB_SINGLE_FOLD,
)

self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)

Expand Down Expand Up @@ -814,24 +801,11 @@ def _createAppearancePage(self):
self.mainPanelAppear = SP.ScrolledPanel(parent=self)
self.mainPanelAppear.SetupScrolling(scroll_x=False)
self.mainPanelAppear.AlwaysShowScrollbars(hflag=False)
try: # wxpython <= 2.8.10
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear,
id=wx.ID_ANY,
style=fpb.FPB_DEFAULT_STYLE,
extraStyle=fpb.FPB_SINGLE_FOLD,
)
except:
try: # wxpython >= 2.8.11
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear,
id=wx.ID_ANY,
agwStyle=fpb.FPB_SINGLE_FOLD,
)
except: # to be sure
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear, id=wx.ID_ANY, style=fpb.FPB_SINGLE_FOLD
)
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear,
id=wx.ID_ANY,
agwStyle=fpb.FPB_SINGLE_FOLD,
)

self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
# light page
Expand Down Expand Up @@ -3360,7 +3334,7 @@ def OnSetSurface(self, event):
name = event.GetString()
try:
self._getLayerPropertiesByName(name, mapType="raster")["surface"]
except:
except (AttributeError, TypeError, KeyError):
self.EnablePage("fringe", False)
return

Expand All @@ -3384,7 +3358,7 @@ def OnSetVector(self, event):
name = event.GetString()
try:
data = self._getLayerPropertiesByName(name, mapType="vector")["vector"]
except:
except (AttributeError, TypeError, KeyError):
self.EnablePage("vector", False)
return
layer = self._getMapLayerByName(name, mapType="vector")
Expand All @@ -3396,7 +3370,7 @@ def OnSetRaster3D(self, event):
name = event.GetString()
try:
data = self._getLayerPropertiesByName(name, mapType="raster_3d")["volume"]
except:
except (AttributeError, TypeError, KeyError):
self.EnablePage("volume", False)
return

Expand Down Expand Up @@ -4925,7 +4899,7 @@ def OnCPlaneSelection(self, event):
try:
planeIndex = int(plane.split()[-1]) - 1
self.EnablePage("cplane", enabled=True)
except:
except (ValueError, IndexError):
planeIndex = -1
self.EnablePage("cplane", enabled=False)
self.mapWindow.SelectCPlane(planeIndex)
Expand All @@ -4942,7 +4916,7 @@ def OnCPlaneChanging(self, event):
plane = self.FindWindowById(self.win["cplane"]["planes"]).GetStringSelection()
try:
planeIndex = int(plane.split()[-1]) - 1
except: # TODO disabled page
except (ValueError, IndexError): # TODO disabled page
planeIndex = -1

if event.GetId() in (
Expand Down Expand Up @@ -4984,7 +4958,7 @@ def OnCPlaneShading(self, event):
plane = self.FindWindowById(self.win["cplane"]["planes"]).GetStringSelection()
try:
planeIndex = int(plane.split()[-1]) - 1
except: # TODO disabled page
except (ValueError, IndexError): # TODO disabled page
planeIndex = -1

self.mapWindow.cplanes[planeIndex]["shading"] = shading
Expand All @@ -4999,7 +4973,7 @@ def OnCPlaneReset(self, event):
plane = self.FindWindowById(self.win["cplane"]["planes"]).GetStringSelection()
try:
planeIndex = int(plane.split()[-1]) - 1
except: # TODO disabled page
except (ValueError, IndexError): # TODO disabled page
planeIndex = -1

self.mapWindow.cplanes[planeIndex] = copy.deepcopy(
Expand Down
1 change: 1 addition & 0 deletions include/grass/defs/raster.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ int Rast_option_to_interp_type(const struct Option *);

/* mask_info.c */
char *Rast_mask_info(void);
char *Rast_mask_name(void);
bool Rast_mask_status(char *, char *, bool *, char *, char *);
int Rast__mask_info(char *, char *);
bool Rast_mask_is_present(void);
Expand Down
12 changes: 9 additions & 3 deletions lib/ogsf/gvl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,16 @@ void GVL_get_dims(int id, int *rows, int *cols, int *depths)
*rows = gvl->rows;
*cols = gvl->cols;
*depths = gvl->depths;
}

G_debug(3, "GVL_get_dims() id=%d, rows=%d, cols=%d, depths=%d",
gvl->gvol_id, gvl->rows, gvl->cols, gvl->depths);
G_debug(3, "GVL_get_dims() id=%d, rows=%d, cols=%d, depths=%d",
gvl->gvol_id, gvl->rows, gvl->cols, gvl->depths);
}
else {
G_debug(2,
"GVL_get_dims(): Attempted to access a null volume structure "
"for id=%d",
id);
}

return;
}
Expand Down
21 changes: 21 additions & 0 deletions lib/raster/mask_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ char *Rast_mask_info(void)
return G_store(text);
}

/**
* @brief Retrieves the name of the raster mask to use.
*
* The returned raster map name is fully qualified, i.e., in the form
% "name@mapset".
*
* The mask name is "MASK@<mapset>", where <mapset> is the current
* mapset.
*
* The memory for the returned mask name is dynamically allocated using
* G_store(). It is the caller's responsibility to free the memory with
* G_free() when it is no longer needed.
*
* @returns A dynamically allocated string containing the mask name.
*/
char *Rast_mask_name(void)
{
// Mask name is always "MASK@<current mapset>".
return G_fully_qualified_name("MASK", G_mapset());
}

/**
* @brief Get raster mask status information
*
Expand Down
34 changes: 13 additions & 21 deletions raster/r.mask.status/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int report_status(struct Parameters *params)
}

// Mask raster
char *full_mask = G_fully_qualified_name(name, mapset);
char *full_mask = Rast_mask_name();
// Underlying raster if applicable
char *full_underlying = NULL;
if (is_mask_reclass)
Expand All @@ -99,10 +99,7 @@ int report_status(struct Parameters *params)
JSON_Value *root_value = json_value_init_object();
JSON_Object *root_object = json_object(root_value);
json_object_set_boolean(root_object, "present", present);
if (present)
json_object_set_string(root_object, "full_name", full_mask);
else
json_object_set_null(root_object, "full_name");
json_object_set_string(root_object, "name", full_mask);
if (is_mask_reclass)
json_object_set_string(root_object, "is_reclass_of",
full_underlying);
Expand All @@ -121,9 +118,7 @@ int report_status(struct Parameters *params)
printf("1");
else
printf("0");
printf("\nfull_name=");
if (present)
printf("%s", full_mask);
printf("\nname=%s", full_mask);
printf("\nis_reclass_of=");
if (is_mask_reclass)
printf("%s", full_underlying);
Expand All @@ -135,34 +130,31 @@ int report_status(struct Parameters *params)
printf("true");
else
printf("false");
printf("\nfull_name: ");
if (present)
printf("|-\n %s", full_mask);
else
printf("null");
// Null values in YAML can be an empty (no) value (rather than null),
// so we could use that, but using the explicit null as a reasonable
// starting point.
printf("\nname: ");
printf("|-\n %s", full_mask);
printf("\nis_reclass_of: ");
// Using block scalar with |- to avoid need for escaping.
// Alternatively, we could check mapset naming limits against YAML
// escaping needs for different types of strings and do the necessary
// escaping here.
// Null values in YAML can be an empty (no) value (rather than null),
// so we could use that, but using the explicit null as a reasonable
// starting point.
if (is_mask_reclass)
printf("|-\n %s", full_underlying);
else
printf("null");
printf("\n");
}
else {
if (present)
printf(_("Mask is active"));
else
printf(_("Mask is not present"));
if (present) {
printf("\n");
printf(_("Mask is active"));
printf(_("Mask name: %s"), full_mask);
}
else {
printf(_("Mask is not present"));
printf(_("If activated, mask name will be: %s"), full_mask);
}
if (is_mask_reclass) {
printf("\n");
printf(_("Mask is a raster reclassified from: %s"),
Expand Down
20 changes: 15 additions & 5 deletions raster/r.mask.status/r.mask.status.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<h2>DESCRIPTION</h2>

The <em>r.mask.status</em> reports information about the 2D raster mask and its
status. If the mask is present, the tool reports a full name of the raster (name
including the mapset) which represents the mask. It can also report full name of
the underlying raster if the mask is reclassified from another raster.

<p></p>
status. The tool reports whether the mask is present or not. For both active
and inactive mask, the tool reports a full name of the raster (name including
the mapset) which represents or would represent the mask.
It can also report full name of the underlying raster if the mask is
reclassified from another raster.

The tool can be used to check if the mask is currently set
(<code>present</code> boolean in JSON), what is raster name used to represent
the mask (<code>name</code> string in JSON), and whether the raster is
reclassifed from another (<code>is_reclass_of</code> string or null in JSON).
YAML and shell script style outputs are following the JSON output if possible.
The plain text format outputs multi-line human-readable information in natural
language.

<p>
With the <b>-t</b> flag, no output is printed, instead a return code is used to
indicate presence or absence. The convention is the same same the POSIX
<em>test</em> utility, so <em>r.mask.status</em> returns 0 when the mask is
Expand Down
Loading

0 comments on commit 2001602

Please sign in to comment.