Skip to content

Commit ce1abc4

Browse files
7.6.1
1 parent 595c85b commit ce1abc4

30 files changed

Lines changed: 27012 additions & 26889 deletions

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def description():
4242

4343

4444
def version():
45-
return 'Version 7.6.0 - Matera'
45+
return 'Version 7.6.1 - Matera'
4646

4747

4848
def icon():

core/messages.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def msg26(self):
134134
def msg27(self):
135135
self.msgBar(cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Information') + ' [27]', cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Signatures exported'))
136136

137+
def msg28(self):
138+
self.msgBar(cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Information') + ' [28]', cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Signatures imported'))
139+
137140
''' Errors '''
138141

139142
def msgErr2(self, SMTP = None):

core/signature_importer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def ASTERLibrary(self, libraryPath):
7171
if cfg.osSCP.path.isfile(libraryPath):
7272
f = open(libraryPath)
7373
file = f.readlines()
74-
if "Name" in file[0]:
74+
if 'Name' in file[0]:
7575
wl = []
7676
ref = []
7777
sD = []
@@ -182,5 +182,5 @@ def openShapefileI(self):
182182
cfg.ui.C_Info_combo.addItems(fields)
183183
cfg.ui.select_shapefile_label.setText(shpFile)
184184
# logger
185-
cfg.utls.logCondition(str(cfg.inspectSCP.stack()[0][3])+ " " + cfg.utls.lineOfCode(), " open Shapefile")
185+
cfg.utls.logCondition(str(cfg.inspectSCP.stack()[0][3])+ " " + cfg.utls.lineOfCode(), ' open Shapefile')
186186

core/utils.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6664,13 +6664,14 @@ def saveMemoryLayerToShapefile(self, memoryLayer, output, name = None, format =
66646664
tSS.dataProvider().createSpatialIndex()
66656665
tSS.updateExtents()
66666666
return tSS
6667-
6667+
66686668
# save features to shapefile
66696669
def featuresToShapefile(self, idList):
66706670
# create shapefile
66716671
crs = cfg.utls.getCrs(cfg.shpLay)
66726672
f = cfg.qgisCoreSCP.QgsFields()
66736673
# add Class ID, macroclass ID and Info fields
6674+
f.append(cfg.qgisCoreSCP.QgsField('fid', cfg.QVariantSCP.Int))
66746675
f.append(cfg.qgisCoreSCP.QgsField(cfg.fldMacroID_class, cfg.QVariantSCP.Int))
66756676
f.append(cfg.qgisCoreSCP.QgsField(cfg.fldROIMC_info, cfg.QVariantSCP.String))
66766677
f.append(cfg.qgisCoreSCP.QgsField(cfg.fldID_class, cfg.QVariantSCP.Int))
@@ -6686,7 +6687,7 @@ def featuresToShapefile(self, idList):
66866687
for f in cfg.shpLay.getFeatures():
66876688
SCP_UID = str(f[cfg.fldSCP_UID])
66886689
if SCP_UID in idList:
6689-
tSS.addFeature(f)
6690+
a = tSS.addFeature(f)
66906691
count = count + 1
66916692
if count == 0:
66926693
tSS.commitChanges()
@@ -6728,13 +6729,29 @@ def getCrsGDAL(self, layerPath):
67286729
if l is None:
67296730
crs = None
67306731
else:
6731-
# check projections
6732-
crs = l.GetProjection()
6732+
try:
6733+
# check projections
6734+
crs = l.GetProjection()
6735+
if len(crs) == 0:
6736+
crs = None
6737+
# in case of errors
6738+
except Exception as err:
6739+
crs = None
6740+
# logger
6741+
cfg.utls.logCondition(str(__name__) + '-' + (cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' ERROR exception: ' + str(err))
67336742
else:
67346743
gL = l.GetLayer()
67356744
# check projection
67366745
lP = gL.GetSpatialRef()
6737-
crs = lP.ExportToWkt()
6746+
try:
6747+
crs = lP.ExportToWkt()
6748+
if len(crs) == 0:
6749+
crs = None
6750+
# in case of errors
6751+
except Exception as err:
6752+
crs = None
6753+
# logger
6754+
cfg.utls.logCondition(str(__name__) + '-' + (cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' ERROR exception: ' + str(err))
67386755
# logger
67396756
cfg.utls.logCondition(str(__name__) + '-' + str(cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' lyr ' + str(layerPath) + ' crs: ' + str(crs))
67406757
return crs

dock/scpdock.py

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def openSignatureList(self, path = None):
254254
def openTrainingFile(self):
255255
scpPath = cfg.utls.getOpenFileName(None , cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Select a SCP training input'), '', 'SCP file (*.scp)')
256256
if len(scpPath) > 0:
257+
cfg.signList = {}
258+
cfg.signIDs = {}
257259
cfg.SCPD.openInput(scpPath)
258260

259261
# open input
@@ -799,20 +801,23 @@ def openLibraryFile(self, libraryFile):
799801
try:
800802
if cfg.bandSetsList[cfg.bndSetNumber][5] == cfg.noUnit:
801803
cfg.mx.msgWar8()
802-
libFile = cfg.utls.getOpenFileName(None , cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Select a library file'), '', 'SCP file (*.scp);;USGS library (*.asc);;ASTER library (*.txt);;CSV (*.csv)')
803-
if len(libFile) > 0:
804-
cfg.uiUtls.addProgressBar()
805-
if libFile.lower().endswith('.asc'):
806-
cfg.sigImport.USGSLibrary(libFile)
807-
elif libFile.lower().endswith('.txt'):
808-
cfg.sigImport.ASTERLibrary(libFile)
809-
elif libFile.lower().endswith('.csv'):
810-
cfg.sigImport.CSVLibrary(libFile)
811-
elif libFile.lower().endswith('.scp'):
812-
self.importSLCSignatureList(libFile, 'Yes')
813-
cfg.uiUtls.removeProgressBar()
814-
# logger
815-
cfg.utls.logCondition(str(__name__) + '-' + (cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' spectral library ' + str(libFile))
804+
libFileList = cfg.utls.getOpenFileNames(None , cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Select a library file'), '', 'SCP file (*.scp);;USGS library (*.zip);;ASTER library (*.txt);;CSV (*.csv)')
805+
if len(libFileList) > 0:
806+
for libFile in libFileList:
807+
cfg.uiUtls.addProgressBar()
808+
if libFile.lower().endswith('.zip'):
809+
libraryR, libraryW, libraryS = cfg.usgsLib.unzipLibrary(libFile)
810+
cfg.sigImport.USGSLibrary(libraryR, libraryW, libraryS)
811+
elif libFile.lower().endswith('.txt'):
812+
cfg.sigImport.ASTERLibrary(libFile)
813+
elif libFile.lower().endswith('.csv'):
814+
cfg.sigImport.CSVLibrary(libFile)
815+
elif libFile.lower().endswith('.scp'):
816+
self.importSLCSignatureList(libFile, 'Yes')
817+
cfg.uiUtls.removeProgressBar()
818+
# logger
819+
cfg.utls.logCondition(str(__name__) + '-' + (cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' spectral library ' + str(libFile))
820+
cfg.mx.msg28()
816821
except Exception as err:
817822
cfg.uiUtls.removeProgressBar()
818823
cfg.mx.msgWar8()
@@ -822,7 +827,7 @@ def openLibraryFile(self, libraryFile):
822827
# export signatures to CSV library
823828
def exportToCSVLibrary(self):
824829
tW = cfg.uidc.signature_list_treeWidget
825-
v = cfg.SCPD.getHighlightedIDs('Yes')
830+
v = cfg.SCPD.getHighlightedIDs('Yes', 'Yes')
826831
if len(v) > 0:
827832
d = cfg.utls.getExistingDirectory(None , cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Export the highlighted signatures to CSV library'))
828833
if len(d) > 0:
@@ -2093,24 +2098,30 @@ def resetInput(self):
20932098
# ask for confirm
20942099
a = cfg.utls.questionBox(cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Remove training input'), cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Are you sure you want to remove training input?'))
20952100
if a == 'Yes':
2096-
cfg.treeDockItm = {}
2097-
cfg.treeDockMCItm = {}
2098-
cfg.uidc.signature_list_treeWidget.clear()
2099-
try:
2100-
cfg.utls.removeLayerByLayer(cfg.shpLay)
2101-
cfg.cnvs.refresh()
2102-
except:
2103-
pass
2104-
# shape layer
2105-
cfg.shpLay = None
2106-
# training layer name
2107-
cfg.trnLay = None
2108-
# signature file path
2109-
cfg.sigFile = None
2110-
cfg.inptDir = None
2111-
cfg.scpFlPath = None
2112-
cfg.uidc.trainingFile_lineEdit.setText('')
2113-
cfg.utls.writeProjectVariable('trainingLayer', '')
2101+
cfg.SCPD.resetInputDock()
2102+
2103+
# reset input
2104+
def resetInputDock(self):
2105+
cfg.treeDockItm = {}
2106+
cfg.treeDockMCItm = {}
2107+
cfg.uidc.signature_list_treeWidget.clear()
2108+
try:
2109+
cfg.utls.removeLayerByLayer(cfg.shpLay)
2110+
cfg.cnvs.refresh()
2111+
except:
2112+
pass
2113+
# shape layer
2114+
cfg.shpLay = None
2115+
# training layer name
2116+
cfg.trnLay = None
2117+
# signature file path
2118+
cfg.sigFile = None
2119+
cfg.inptDir = None
2120+
cfg.scpFlPath = None
2121+
cfg.signList = {}
2122+
cfg.signIDs = {}
2123+
cfg.uidc.trainingFile_lineEdit.setText('')
2124+
cfg.utls.writeProjectVariable('trainingLayer', '')
21142125

21152126
# Create new input
21162127
def createInput(self):
@@ -2119,6 +2130,7 @@ def createInput(self):
21192130
try:
21202131
sL = cfg.utls.getSaveFileName(None , cfg.QtWidgetsSCP.QApplication.translate('semiautomaticclassificationplugin', 'Create SCP training input'), '', '*.scp', 'scp')
21212132
if sL is not False:
2133+
cfg.SCPD.resetInputDock()
21222134
try:
21232135
# band set
21242136
if cfg.bandSetsList[cfg.bndSetNumber][0] == 'Yes':
@@ -2127,12 +2139,22 @@ def createInput(self):
21272139
b = cfg.utls.selectLayerbyName(cfg.bandSetsList[cfg.bndSetNumber][3][0], 'Yes')
21282140
filePath = cfg.utls.layerSource(b)
21292141
crs = cfg.utls.getCrsGDAL(filePath)
2142+
if len(crs) == 0:
2143+
# logger
2144+
cfg.utls.logCondition(str(__name__) + '-' + str(cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' ERROR crs')
2145+
cfg.mx.msgErr61(cfg.bandSetsList[cfg.bndSetNumber][3][0])
2146+
return
21302147
else:
21312148
# crs of loaded raster
21322149
b = cfg.utls.selectLayerbyName(cfg.bandSetsList[cfg.bndSetNumber][8])
21332150
filePath = cfg.utls.layerSource(b)
21342151
crs = cfg.utls.getCrsGDAL(filePath)
21352152
iB = b.bandCount()
2153+
if len(crs) == 0:
2154+
# logger
2155+
cfg.utls.logCondition(str(__name__) + '-' + str(cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' ERROR crs')
2156+
cfg.mx.msgErr61(cfg.bandSetsList[cfg.bndSetNumber][8])
2157+
return
21362158
# shapefile
21372159
name = cfg.utls.fileNameNoExt(sL)
21382160
dT = cfg.utls.getTime()
@@ -2153,7 +2175,7 @@ def createInput(self):
21532175
except Exception as err:
21542176
# logger
21552177
cfg.utls.logCondition(str(__name__) + '-' + str(cfg.inspectSCP.stack()[0][3])+ ' ' + cfg.utls.lineOfCode(), ' ERROR exception: ' + str(err))
2156-
cfg.SCPD.refreshRasterLayer()
2178+
cfg.ipt.refreshRasterLayer()
21572179
cfg.mx.msg4()
21582180
except Exception as err:
21592181
# logger

docs/repository.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version = '1.0' encoding = 'UTF-8'?>
22
<plugins>
3-
<pyqgis_plugin name="Semi-Automatic Classification Plugin - master" version="7.6.0" plugin_id="284">
3+
<pyqgis_plugin name="Semi-Automatic Classification Plugin - master" version="7.6.1" plugin_id="284">
44
<description><![CDATA[The Semi-Automatic Classification Plugin (SCP) allows for the supervised classification of remote sensing images, providing tools for the download, the preprocessing and postprocessing of images.]]></description>
55
<about><![CDATA[Developed by Luca Congedo, the Semi-Automatic Classification Plugin (SCP) allows for the supervised classification of remote sensing images, providing tools for the download, the preprocessing and postprocessing of images. Search and download is available for ASTER, GOES, Landsat, MODIS, Sentinel-1, Sentinel-2, and Sentinel-3 images. Several algorithms are available for the land cover classification. This plugin requires the installation of GDAL, OGR, Numpy, SciPy, and Matplotlib. Some tools require also the installation of SNAP (ESA Sentinel Application Platform). For more information please visit https://fromgistors.blogspot.com .]]></about>
6-
<version>7.6.0</version>
6+
<version>7.6.1</version>
77
<qgis_minimum_version>3.0.0</qgis_minimum_version>
88
<qgis_maximum_version>3.99.0</qgis_maximum_version>
99
<homepage><![CDATA[https://fromgistors.blogspot.com/p/semi-automatic-classification-plugin.html]]></homepage>

0 commit comments

Comments
 (0)