Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i.signatures: Add imagery classifier signature management module #3008

Merged
merged 17 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ 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
)
self.data[win.UpdateItems] = {"element": sigtype.get("value", "")}


def UpdateDialog(parent, event, eventId, task):
Expand Down Expand Up @@ -1444,6 +1449,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 +1735,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
32 changes: 29 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,23 @@ 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"])

def GetValue(self):
value = super(SignatureTypeSelect, self).GetValue()
if value:
return f"signatures/{value}"
return value


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

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
46 changes: 46 additions & 0 deletions imagery/i.signatures/i.signatures.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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>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
marisn marked this conversation as resolved.
Show resolved Hide resolved
</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
Loading