Commit d953800f authored by Daniel Scheffler's avatar Daniel Scheffler

Merge branch 'bugfix/fix_get_coordarray' into 'master'

Fixed issue #15 (boxObj.get_coordArray_MapXY() returns faulty y-coordinate...

Closes #15

See merge request !26
parents 9391dfbc 38b9f0ec
Pipeline #16469 canceled with stages
in 2 minutes and 48 seconds
......@@ -2,6 +2,13 @@
History
=======
0.16.4 (2020-12-07)
-------------------
* Fixed issue #15 (boxObj.get_coordArray_MapXY() returns faulty y-coordinate array).
* Test_boxObj.test_get_coordArray_MapXY() now also validates the output of boxObj.get_coordArray_MapXY().
0.16.3 (2020-12-03)
-------------------
......
......@@ -220,7 +220,7 @@ class boxObj(object):
xmin, xmax, ymin, ymax = self.boundsMap
Xarr, Yarr = np.meshgrid(np.arange(xmin, xmax, abs(self.gt[1])),
np.arange(ymin, ymax, abs(self.gt[5])))
np.arange(ymax, ymin, -abs(self.gt[5])))
if prj and not prj_equal(self.prj, prj):
Xarr, Yarr = transform_coordArray(self.prj, prj, Xarr, Yarr)
......
......@@ -29,6 +29,7 @@ test_geometry
Tests for `py_tools_ds.geo.vector.geometry` module.
"""
import numpy as np
from unittest import TestCase, main
from py_tools_ds.geo.vector.geometry import boxObj, get_winPoly
......@@ -173,38 +174,51 @@ class Test_boxObj(TestCase):
self.assertEqual((x_larger, y_larger), (False, True))
def test_get_coordArray_MapXY(self):
self.box.get_coordArray_MapXY()
# test for correct output
coords_x, coords_y = self.box.get_coordArray_MapXY()
self.assertIsInstance(coords_x, np.ndarray)
self.assertTupleEqual(coords_x.shape, self.box.imDimsYX)
self.assertTupleEqual(coords_y.shape, self.box.imDimsYX)
self.assertEqual(coords_x[0, 0], self.box.boundsMap[0]) # ULx == xmin
self.assertEqual(coords_y[0, 0], self.box.boundsMap[3]) # ULy == ymax
self.assertTrue(np.isclose(coords_x[-1, -1] + self.box.gt[1],
self.box.boundsMap[1])) # LRx + xGSD == xmax
self.assertTrue(np.isclose(coords_y[-1, -1] - abs(self.box.gt[5]),
self.box.boundsMap[2])) # LRy - yGSD == ymin
# test to return coords array in another projection
self.box.get_coordArray_MapXY(prj=' '.join("""
PROJCS["WGS 84 / UTM zone 33N",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84", 6378137, 298.257223563,
AUTHORITY["EPSG", "7030"]],
AUTHORITY["EPSG", "6326"]],
PRIMEM["Greenwich", 0,
AUTHORITY["EPSG", "8901"]],
UNIT["degree", 0.0174532925199433,
AUTHORITY["EPSG", "9122"]],
AUTHORITY["EPSG", "4326"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin", 0],
PARAMETER["central_meridian", 15],
PARAMETER["scale_factor", 0.9996],
PARAMETER["false_easting", 500000],
PARAMETER["false_northing", 0],
UNIT["metre", 1,
AUTHORITY["EPSG", "9001"]],
AXIS["Easting", EAST],
AXIS["Northing", NORTH],
AUTHORITY["EPSG", "32633"]]
""".split())
)
self.box.get_coordArray_MapXY(
prj=' '.join("""
PROJCS["WGS 84 / UTM zone 33N",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84", 6378137, 298.257223563,
AUTHORITY["EPSG", "7030"]],
AUTHORITY["EPSG", "6326"]],
PRIMEM["Greenwich", 0,
AUTHORITY["EPSG", "8901"]],
UNIT["degree", 0.0174532925199433,
AUTHORITY["EPSG", "9122"]],
AUTHORITY["EPSG", "4326"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin", 0],
PARAMETER["central_meridian", 15],
PARAMETER["scale_factor", 0.9996],
PARAMETER["false_easting", 500000],
PARAMETER["false_northing", 0],
UNIT["metre", 1,
AUTHORITY["EPSG", "9001"]],
AXIS["Easting", EAST],
AXIS["Northing", NORTH],
AUTHORITY["EPSG", "32633"]]
""".split())
)
# test input validation
box = self.box
box.prj = None
with self.assertRaises(ValueError):
with self.assertRaisesRegex(
ValueError, 'geotransform and projection must both be available for computing coordinate array.'):
self.box.get_coordArray_MapXY()
......
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