Commit 0a4aa4d2 authored by Benjamin Jakimow's avatar Benjamin Jakimow

qps update

fixed CRS writing to project file
Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow benjamin.jakimow@geo.hu-berlin.de <benjamin.jakimow@geo.hu-berlin.de>
parent d8c1fc9e
Pipeline #15198 failed with stage
in 1 minute and 19 seconds
......@@ -34,7 +34,7 @@ from qgis.gui import QgsMapLayerConfigWidgetFactory, QgisInterface
MIN_QGIS_VERSION = '3.14'
__version__ = '1.0'
__version__ = '1.2'
DIR_QPS = pathlib.Path(__file__).parent
DIR_UI_FILES = DIR_QPS / 'ui'
......
......@@ -1331,7 +1331,8 @@ class SpectralProfileRenderer(object):
customStyle = PlotStyle.readXml(customStyleNode)
if isinstance(customStyle, PlotStyle):
fids = customStyleNode.firstChildElement('keys').firstChild().nodeValue().split(',')
fids = [int(f) for f in fids]
rxInt = re.compile(r'\d+[ ]*')
fids = [int(f) for f in fids if re.match(rxInt)]
renderer.setProfilePlotStyle(customStyle, fids)
return renderer
......@@ -2776,8 +2777,13 @@ class SpectralLibrary(QgsVectorLayer):
dsDst.SetProjection(fakeProjection.ExportToWkt())
# north-up project, 1 px above equator, starting at 0°, n pixels = n profiles towards east
dsDst.SetGeoTransform([0.0, 1.0, 0.0, 1.0, 0.0, -1.0])
xvalue_string = ','.join(f'{v}' for v in xValues)
dsDst.SetMetadataItem('wavelength units', xUnit)
dsDst.SetMetadataItem('wavelength', ','.join(f'{v}' for v in xValues))
dsDst.SetMetadataItem('wavelength', xvalue_string)
# backward compatibility for stupid algorithms
dsDst.SetMetadataItem('wavelength units', xUnit, 'ENVI')
dsDst.SetMetadataItem('wavelength', f'{{{xvalue_string}}}', 'ENVI')
dsDst.FlushCache()
imageFiles.append(pathDst)
del dsDst
......
......@@ -2429,11 +2429,12 @@ class SpectralLibraryWidget(AttributeTableWidget):
self.actionShowProperties.setToolTip('Show Spectral Library Properties')
self.actionShowProperties.setIcon(QIcon(':/images/themes/default/propertyicons/system.svg'))
self.actionShowProperties.triggered.connect(self.showProperties)
self.btnShowProperties = QToolButton()
self.btnShowProperties.setAutoRaise(True)
self.btnShowProperties.setDefaultAction(self.actionShowProperties)
self.tbSpeclibAction.addAction(self.actionShowProperties)
self.centerBottomLayout.insertWidget(self.centerBottomLayout.indexOf(self.mAttributeViewButton),
self.btnShowProperties)
......
......@@ -1497,6 +1497,7 @@ def parseBadBandList(dataset) -> typing.List[int]:
try:
dataset = gdalDataset(dataset)
except:
return None
pass
if not isinstance(dataset, gdal.Dataset):
......@@ -1524,7 +1525,7 @@ def parseFWHM(dataset) -> typing.Tuple[np.ndarray]:
try:
dataset = gdalDataset(dataset)
except:
pass
return None
key_positions = [('fwhm', None),
('fwhm', 'ENVI')]
......@@ -1565,7 +1566,10 @@ def checkWavelength(key: str, values: str, expected: int = 1) -> np.ndarray:
else:
sep = ','
try:
wl = np.fromstring(values, count=expected, sep=sep)
wl = np.asarray(values.split(sep), dtype=np.float)
if len(wl) != expected:
wl = None
# wl = np.fromstring(values, count=expected, sep=sep)
except ValueError as exV:
pass
except Exception as ex:
......@@ -1613,13 +1617,11 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
def sort_domains(domains) -> typing.List[str]:
if not isinstance(domains, list):
domains = []
return sorted(domains, key=lambda n: n != ['ENVI'])
try:
dataset = gdalDataset(dataset)
except AssertionError:
except Exception:
return None, None
if isinstance(dataset, gdal.Dataset):
......@@ -1954,8 +1956,10 @@ class SpatialPoint(QgsPointXY):
@staticmethod
def readXml(node: QDomNode):
wkt = node.firstChildElement('SpatialPointCrs').text()
crs = QgsCoordinateReferenceSystem(wkt)
node_crs = node.firstChildElement('SpatialPointCrs')
crs = QgsCoordinateReferenceSystem()
if not node_crs.isNull():
crs.readXml(node_crs)
point = QgsGeometry.fromWkt(node.firstChildElement('SpatialPoint').text()).asPoint()
return SpatialPoint(crs, point)
......@@ -2021,10 +2025,7 @@ class SpatialPoint(QgsPointXY):
node_geom = doc.createElement('SpatialPoint')
node_geom.appendChild(doc.createTextNode(self.asWkt()))
node_crs = doc.createElement('SpatialPointCrs')
if QgsCoordinateReferenceSystem(self.crs().authid()) == self.crs():
node_crs.appendChild(doc.createTextNode(self.crs().authid()))
else:
node_crs.appendChild(doc.createTextNode(self.crs().toWkt()))
self.crs().writeXml(node_crs, doc)
node.appendChild(node_geom)
node.appendChild(node_crs)
......@@ -2147,8 +2148,10 @@ class SpatialExtent(QgsRectangle):
@staticmethod
def readXml(node: QDomNode):
wkt = node.firstChildElement('SpatialExtentCrs').text()
crs = QgsCoordinateReferenceSystem(wkt)
node_crs = node.firstChildElement('SpatialExtentCrs')
crs = QgsCoordinateReferenceSystem()
if not node_crs.isNull():
crs.readXml(node_crs)
rectangle = QgsRectangle.fromWkt(node.firstChildElement('SpatialExtent').text())
return SpatialExtent(crs, rectangle)
......@@ -2213,10 +2216,11 @@ class SpatialExtent(QgsRectangle):
node_geom = doc.createElement('SpatialExtent')
node_geom.appendChild(doc.createTextNode(self.asWktPolygon()))
node_crs = doc.createElement('SpatialExtentCrs')
if QgsCoordinateReferenceSystem(self.crs().authid()) == self.crs():
node_crs.appendChild(doc.createTextNode(self.crs().authid()))
else:
node_crs.appendChild(doc.createTextNode(self.crs().toWkt()))
self.crs().writeXml(node_crs, doc)
#if QgsCoordinateReferenceSystem(self.crs().authid()) == self.crs():
# node_crs.appendChild(doc.createTextNode(self.crs().authid()))
#else:
# node_crs.appendChild(doc.createTextNode(self.crs().toWkt()))
node.appendChild(node_geom)
node.appendChild(node_crs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment