Skip to content

Commit

Permalink
i.signatures: Add imagery classifier signature management module (OSG…
Browse files Browse the repository at this point in the history
…eo#3008)

This module allows to manage signature files created by various imagery classification modules such as i.gensig, i.gensigset. The module allows to list, copy, rename and delete signature files.

---------

Co-authored-by: Anna Petrasova <kratochanna@gmail.com>
  • Loading branch information
marisn and petrasovaa authored Oct 22, 2023
1 parent 37239ca commit 34d02cd
Show file tree
Hide file tree
Showing 11 changed files with 605 additions and 3 deletions.
30 changes: 30 additions & 0 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ def run(self):
if map:
self.data[win.GetParent().SetData] = {"vector": map, "layer": layer}
# TODO: table?
elif name == "SignatureSelect":
sigtype = self.task.get_param(
"sigtype", element="element", raiseError=False
)
value = sigtype.get("value", "")
if value:
value = f"signatures/{value}"
self.data[win.UpdateItems] = {"element": value}


def UpdateDialog(parent, event, eventId, task):
Expand Down Expand Up @@ -1444,6 +1452,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
"cats",
"subgroup",
"sigfile",
"sigtype",
"separator",
"dbdriver",
"dbname",
Expand Down Expand Up @@ -1729,6 +1738,27 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
| wx.TOP,
border=5,
)
# signature type
elif prompt == "sigtype":
win = gselect.SignatureTypeSelect(parent=which_panel)
value = self._getValue(p)
win.SetValue(value)
p["wxId"] = [win.GetId()]
if p.get("guidependency", ""):
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
win.Bind(wx.EVT_TEXT, self.OnSetValue)
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
which_sizer.Add(
win,
proportion=0,
flag=wx.ADJUST_MINSIZE
| wx.BOTTOM
| wx.LEFT
| wx.RIGHT
| wx.TOP,
border=5,
)

# separator
elif prompt == "separator":
Expand Down
26 changes: 23 additions & 3 deletions gui/wxpython/gui_core/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
- :class:`CoordinatesSelect`
- :class:`VectorCategorySelect`
- :class:`SignatureSelect`
- :class:`SignatureTypeSelect`
- :class:`SeparatorSelect`
- :class:`SqlWhereSelect`
(C) 2007-2018 by the GRASS Development Team
(C) 2007-2023 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
Expand Down Expand Up @@ -3090,10 +3091,18 @@ def __init__(
**kwargs,
):
super(SignatureSelect, self).__init__(parent, id, size=size, **kwargs)
self.SetName("SignatureSelect")
self.mapsets = mapsets
self.UpdateItems(element)

def UpdateItems(self, element):
"""Update list of signature files for given element
:param str element: signatures/sig or signatures/sigset
"""
items = []
if mapsets:
for mapset in mapsets:
if self.mapsets:
for mapset in self.mapsets:
self._append_mapset_signatures(mapset, element, items)
else:
self._append_mapset_signatures(None, element, items)
Expand Down Expand Up @@ -3136,6 +3145,17 @@ def _append_mapset_signatures(self, mapset, element, items):
I_free_signatures_list(count, ctypes.byref(sig_list))


class SignatureTypeSelect(wx.ComboBox):
"""Widget for selecting signature type"""

def __init__(
self, parent, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE, **kwargs
):
super(SignatureTypeSelect, self).__init__(parent, id, size=size, **kwargs)
self.SetName("SignatureTypeSelect")
self.SetItems(["sig", "sigset"])


class SeparatorSelect(wx.ComboBox):
"""Widget for selecting separator"""

Expand Down
4 changes: 4 additions & 0 deletions gui/wxpython/xml/toolboxes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,10 @@
<label>Sequential maximum a posteriori classification (SMAP)</label>
</module-item>
<separator/>
<module-item name="i.signatures">
<label>Manage signature files</label>
</module-item>
<separator/>
<module-item name="i.segment">
<label>Object segmentation</label>
</module-item>
Expand Down
1 change: 1 addition & 0 deletions imagery/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SUBDIRS = \
i.rectify \
i.rgb.his \
i.segment \
i.signatures \
i.smap \
i.target \
i.topo.corr \
Expand Down
4 changes: 4 additions & 0 deletions imagery/i.gensig/i.gensig.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ <h2>DESCRIPTION</h2>
<em><a href="i.maxlik.html">i.maxlik</a></em>
to actually create the final classified map.

<p>
This module generates signature files of type "sig". Use module
<a href="i.signatures.html">i.signatures</a> to manage generated signature files.

<p>
All raster maps used to generate signature file can have semantic label
set. Use <em><a href="r.support.html">r.support</a></em> to set
Expand Down
4 changes: 4 additions & 0 deletions imagery/i.gensigset/i.gensigset.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ <h2>DESCRIPTION</h2>
<a href="i.smap.html">i.smap</a></em> to create the
final classified map.

<p>
This module generates signature files of type "sigset". Use module
<a href="i.signatures.html">i.signatures</a> to manage generated signature files.

<p>
For all raster maps used to generate signature file it is recommended
to have semantic label set.
Expand Down
10 changes: 10 additions & 0 deletions imagery/i.signatures/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MODULE_TOPDIR = ../..

PGM = i.signatures

LIBES = $(GISLIB) $(IMAGERYLIB)
DEPENDENCIES = $(GISDEP) $(IMAGERYDEP)

include $(MODULE_TOPDIR)/include/Make/Module.make

default: cmd
57 changes: 57 additions & 0 deletions imagery/i.signatures/i.signatures.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<h2>DESCRIPTION</h2>

<em>i.signatures</em> module allows to manage signature files:
<ul>
<li>"sig" – generated by <a href="i.gensig.html">i.gensig</a>
for <a href="i.maxlik.html">i.maxlik</a></li>
<li>"sigset" – generated by <a href="i.gensigset.html">i.gensigset</a>
for <a href="i.smap.html">i.smap</a></li>
</ul>
The module can perform multiple actions per run. The order of execution
is "copy", "remove", "rename". When the print flag is specified without
specifying any type of signature files, it would print all signatures
grouped by type.

<h2 id="notes">NOTES</h2>

By default the module will list signature files from all mapsets in the
current search path. It is possible to limit listing only to a single
mapset by providing the "mapset" option. The mapset can be also not listed
in the current search path.<br>
Actions "remove" and "rename" operate only on the
current mapset (although accept fully qualified names). The "copy" action
will accept a signature file name from any mapset as its first argument
(source file to copy).

<h2>EXAMPLES</h2>

Print names of all signature files:
<div class="code"><pre>
i.signatures -p
</pre></div>

Print only signature files of certain type as a JSON:
<div class="code"><pre>
i.signatures -p type=sigset format=json
</pre></div>

Delete signature file called "foo" of type "sig" (i.gensig / i.maxlik).
<div class="code"><pre>
i.signatures remove=foo type=sig
</pre></div>

Copy signature file "bar" from mapset "baz" to current mapset
<div class="code"><pre>
i.signatures copy=bar@baz,best_version type=sigset
</pre></div>

<h2>SEE ALSO</h2>

<em>
<a href="i.gensig.html">i.gensig</a>
<a href="i.gensigset.html">i.gensigset</a>
</em>

<h2>AUTHOR</h2>

Maris Nartiss
Loading

0 comments on commit 34d02cd

Please sign in to comment.