Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
it, instead of raising `IndexError`. The native library ignores the key.
- `DfsFile.WriteItemTimeStepNext` reports data shorter than the item with its
size, instead of raising `AttributeError`.
- `DfsuBuilder` writes the `X-coord` and `Y-coord` static items of a file with
a geographic projection, such as `LONG/LAT`, as `eumILatLong` in degrees.
They were `eumIGeographicalCoordinate` in metres whatever the projection.
Files with a projected coordinate system are unchanged
([#47](https://github.com/DHI/mikecore-python/issues/47)).

[Unreleased]: https://github.com/DHI/mikecore-python/compare/v0.3.a1...HEAD
10 changes: 5 additions & 5 deletions mikecore/DfsuBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DfsuUtil,
)
from mikecore.eum import eumUnit, eumQuantity, eumItem
from mikecore.Projections import MapProjection


# / <summary>
Expand Down Expand Up @@ -703,11 +704,10 @@ def CreateDfsu(self, dfsBuilder, elementType, nodesPerElmt, connectivityArray):
nodes, connectivity = self.__NodesAndElements()
intCode = eumQuantity(eumItem.eumIIntegerCode, eumUnit.eumUintCode)
xyQuantity = eumQuantity(eumItem.eumIGeographicalCoordinate, eumUnit.eumUmeter)

# TODO: reenable:
# if (MapProjection.IsValid(self.__dfsProjection.WKTString)):
# if (MapProjection.IsGeographical(self.__dfsProjection.WKTString)):
# xyQuantity = eumQuantity(eumItem.eumILatLong, eumUnit.eumUdegree)
if self.__dfsProjection is not None:
wkt = self.__dfsProjection.WKTString
if MapProjection.IsValid(wkt) and MapProjection.IsGeographical(wkt):
xyQuantity = eumQuantity(eumItem.eumILatLong, eumUnit.eumUdegree)

# Node id
nodeIdItem = dfsBuilder.AddCreateStaticItem("Node id", intCode, self.__nodeIds)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_dfsu_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from numpy.testing import assert_array_equal

from mikecore.DfsFactory import DfsFactory
from mikecore.DfsFileFactory import DfsFileFactory
from mikecore.DfsuBuilder import DfsuBuilder
from mikecore.DfsuFile import DfsuFile, DfsuFileType
from mikecore.eum import eumItem, eumQuantity, eumUnit
Expand Down Expand Up @@ -102,6 +103,31 @@ def test_z_unit_is_written(tmp_path):
dfsu.Close()


@pytest.mark.parametrize(
"projection, xyQuantity",
[
("LONG/LAT", (eumItem.eumILatLong, eumUnit.eumUdegree)),
("UTM-33", (eumItem.eumIGeographicalCoordinate, eumUnit.eumUmeter)),
("NON-UTM", (eumItem.eumIGeographicalCoordinate, eumUnit.eumUmeter)),
],
)
def test_xy_quantity_follows_projection(tmp_path, projection, xyQuantity):
filename = str(tmp_path / "xyquantity.dfsu")
builder = _builder()
builder.SetProjection(DfsFactory().CreateProjection(projection))
builder.SetNodes(X, Y, Z, CODE)
builder.SetElements(ELEMENTS)
builder.CreateFile(filename).Close()

dfs = DfsFileFactory.DfsGenericOpen(filename)
dfs.ReadStaticItemNext() # Node id
for name in ["X-coord", "Y-coord"]:
staticItem = dfs.ReadStaticItemNext()
assert name == staticItem.Name
assert xyQuantity == (staticItem.Quantity.Item, staticItem.Quantity.Unit)
dfs.Close()


def test_z_unit_must_be_meter_or_feet():
builder = _builder()

Expand Down
Loading