DHI / mikecore-python

MIKE Core in Python
5 stars 0 forks source link

CreateProjOrigin and axis order of projection #22

Open Achton-Boel opened 2 years ago

Achton-Boel commented 2 years ago

CreateProjOrigin is not working correctly when the axis order of the local coordinate system is (north, east) instead of (east, north).

To reproduce in Python:

from mikecore.Projections import Cartography projectionString = 'PROJCS["SWEREF99 13 30",GEOGCS["SWEREF99",DATUM["SWEREF99",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6619"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4619"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",13.5],PARAMETER["scale_factor",1],PARAMETER["false_easting",150000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Northing",NORTH],AXIS["Easting",EAST],AUTHORITY["EPSG","3008"]]' cart = Cartography.CreateProjOrigin(projectionString = projectionString, east = 100007.0, north = 6215293.0, orientationProj = 0) print(cart.LonOrigin, cart.LatOrigin)

Expected behavior Expected to get lon/lat coordinates close to Helsingborg. Got lon/lat coordinates in the Indian Ocean.

ecomodeller commented 2 years ago

As if projections wasn't complicated already...

image

We will pass this onto the mikecore team.

JesperGr commented 2 years ago

This is actually working as designed. The arguments to CreateProjOrigin contains argument for two axis values. For a NorthEast oriented coordinate system, the first one will then be northing, and the second will be easting. And that works similarly for all the axis types, as e.g. also the SouthWest oriented axis.

That then clashes with the fact that the arguments in the code are named east and north. Maybe they should have been named x and y, or at least something more generic.

There are similar issues in the other classes, as e.g. the MapProjection.Proj2Geo and Cartography.Proj2Xy. The latter converts from projection-(x,y) to a local-grid-(x,y), and the projection-(x,y) is then called (east, north) in the code.

An option could be to rename arguments in the entire code, replacing (east, north) with e.g. (projX, projY).

However, that may break a significant amount of code. Is that worth that?

ecomodeller commented 2 years ago

No, probably not.