Commit 82b098e4 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

smaller fixes

parent 9e76230e
......@@ -209,6 +209,12 @@
</layout>
</widget>
<widget class="QToolBar" name="mToolbar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Attribute Table Toolbar</string>
</property>
......
......@@ -1210,12 +1210,13 @@ def layerGeoTransform(rasterLayer:QgsRasterLayer) -> typing.Tuple[float, float,
0, -1 * rasterLayer.rasterUnitsPerPixelY())
return gt
def px2geo(px:QPoint, gt, pxCenter=True) -> QgsPointXY:
def px2geo(px:QPoint, gt, pxCenter: bool = True) -> QgsPointXY:
"""
Converts a pixel coordinate into a geo-coordinate
:param px: QPoint() with pixel coordinates
:param gt: geo-transformation
:param pxCenter: True to return geo-coordinate of pixel center, False to return upper-left edge
:param pxCenter: True (default) to return geo-coordinate of pixel center,
False to return the pixel's upper-left edge.
:return:
"""
......@@ -1427,7 +1428,7 @@ class SpatialExtent(QgsRectangle):
@staticmethod
def world():
crs = QgsCoordinateReferenceSystem('EPSG:4326')
ext = QgsRectangle(-180,-90,180,90)
ext = QgsRectangle(-180, -90, 180, 90)
return SpatialExtent(crs, ext)
@staticmethod
......@@ -1442,7 +1443,7 @@ class SpatialExtent(QgsRectangle):
yValues = []
for x in [0, ns]:
for y in [0, nl]:
px = px2geo(QPoint(x,y), gt)
px = px2geo(QPoint(x,y), gt, pxCenter=False)
xValues.append(px.x())
yValues.append(px.y())
......
......@@ -815,8 +815,6 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
if len(files) > 0:
self.addTimeSeriesImages(files)
def close(self):
self.ui.close()
......
......@@ -147,6 +147,7 @@ def geometryToPixel(ds:gdal.Dataset, geometry: QgsGeometry) -> typing.Tuple[list
else:
gt = ds.GetGeoTransform()
bounds = SpatialExtent.fromRasterSource(ds)
if geometry.boundingBoxIntersects(bounds):
if geometry.type() == QgsWkbTypes.PointGeometry:
px = geo2px(QgsPointXY(geometry.asQPointF()), gt)
......
......@@ -46,6 +46,12 @@ class TestQGISInteraction(EOTSVTestCase):
"""
def setUp(self):
eotsv = EOTimeSeriesViewer.instance()
if isinstance(eotsv, EOTimeSeriesViewer):
eotsv.close()
QApplication.processEvents()
def test_syncExtents(self):
......@@ -124,7 +130,6 @@ class TestQGISInteraction(EOTSVTestCase):
TSV.close()
if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'), buffer=False)
exit(0)
......
......@@ -31,10 +31,18 @@ import unittest, tempfile
from eotimeseriesviewer.stackedbandinput import *
from example.Images import Img_2014_06_16_LE72270652014167CUB00_BOA, Img_2014_05_07_LC82270652014127LGN00_BOA
from eotimeseriesviewer.main import EOTimeSeriesViewer
class TestStackedInputs(EOTSVTestCase):
def setUp(self):
eotsv = EOTimeSeriesViewer.instance()
if isinstance(eotsv, EOTimeSeriesViewer):
eotsv.close()
QApplication.processEvents()
def createTestDatasets(self):
vsiDir = '/vsimem/tmp'
......
......@@ -87,6 +87,7 @@ class TestTemporalProfiles(EOTSVTestCase):
ds = tss.asDataset()
px_size_x, px_size_y = tss.rasterUnitsPerPixelX(), tss.rasterUnitsPerPixelY()
# convert points to pixel coordinates
px, py = geometryToPixel(ds, center)
self.assertEqual(len(px), len(py))
......@@ -94,12 +95,14 @@ class TestTemporalProfiles(EOTSVTestCase):
self.assertEqual(py, [int(0.5 * ds.RasterYSize)])
# no pixel-coordinate for out of bounds points :
oobPoints = [
QgsPointXY(extent.xMinimum() - 0.5, center.y()),
QgsPointXY(center.x(), extent.yMaximum() + 0.5),
QgsPointXY(center.x(), extent.yMinimum() - 0.5),
QgsPointXY(extent.xMaximum() + 0.5, center.y())
QgsPointXY(extent.xMinimum() - 0.5 * px_size_x, center.y()),
QgsPointXY(center.x(), extent.yMaximum() + 0.5 * px_size_y),
QgsPointXY(center.x(), extent.yMinimum() - 0.5 * px_size_y),
QgsPointXY(extent.xMaximum() + 0.5 * px_size_x, center.y())
]
for oobPt in oobPoints:
px, py = geometryToPixel(ds, oobPt)
self.assertEqual(len(px), len(py))
......
Supports Markdown
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