Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis order not correctly extracted from EPSG:4326 #28

Open
SimonBin opened this issue Aug 10, 2024 · 3 comments
Open

Axis order not correctly extracted from EPSG:4326 #28

SimonBin opened this issue Aug 10, 2024 · 3 comments

Comments

@SimonBin
Copy link

using this definition from gdalsrsinfo:

gdalsrsinfo -o wkt1 EPSG:4326

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"]],
    AXIS["Latitude",NORTH],
    AXIS["Longitude",EAST],
    AUTHORITY["EPSG","4326"]]

we can see the axis order is NE (lat/long) however wkt-parser fails to extract it:

wkt(epsg4326)

{
  type: 'GEOGCS',
  name: 'WGS 84',
  DATUM: {
    name: 'WGS_1984',
    SPHEROID: {
      name: 'WGS 84',
      a: 6378137,
      rf: 298.257223563,
      AUTHORITY: [Object]
    },
    AUTHORITY: { EPSG: '6326' }
  },
  PRIMEM: { name: 'greenwich', convert: 0, AUTHORITY: { EPSG: '8901' } },
  UNIT: {
    name: 'degree',
    convert: 0.0174532925199433,
    AUTHORITY: { EPSG: '9122' }
  },
  AXIS: [ [ 'Latitude', 'NORTH' ], [ 'Longitude', 'EAST' ] ],
  AUTHORITY: { EPSG: '4326' },
  projName: 'longlat',
  units: 'degree',
  to_meter: 111319.4907932736,
  datumCode: 'wgs84',
  ellps: 'WGS 84',
  a: 6378137,
  rf: 298.257223563,
  srsCode: 'WGS 84'
}

the missing axis key then later on lets proj4js set axis: 'enu'

https://github.com/proj4js/proj4js/blob/a8bdc85b7c5804d0c05d99c95a8c165287c3c362/lib/Proj.js#L38

  json.axis = json.axis || 'enu';

resulting in a mess

@ahocevar
Copy link
Member

proj4js does not really make use of the axis property, unless you use it like described here. Is that what you're doing? If so, would you be able to sumit a pull request to add support for axis in wkt-parser?

@SimonBin
Copy link
Author

I can do it by relaxing the check like this:

diff --git a/index.js b/index.js
index 7cd2316..bc186b2 100644
--- a/index.js
+++ b/index.js
@@ -36,13 +36,13 @@ function cleanWKT(wkt) {
       var axisOrder = '';
     for (var i = 0, ii = wkt.AXIS.length; i < ii; ++i) {
        var axis = [wkt.AXIS[i][0].toLowerCase(), wkt.AXIS[i][1].toLowerCase()];
-      if (axis[0].indexOf('north') !== -1 || ((axis[0] === 'y' || axis[0] === 'lat') && axis[1] === 'north')) {
+       if (axis[0].indexOf('north') !== -1 || ((axis[0] === 'y' || axis[0].indexOf('lat') !== -1) && axis[1] === 'north')) {
           axisOrder += 'n';
-      } else if (axis[0].indexOf('south') !== -1 || ((axis[0] === 'y' || axis[0] === 'lat') && axis[1] === 'south')) {
+      } else if (axis[0].indexOf('south') !== -1 || ((axis[0] === 'y' || axis[0].indexOf('lat') !== -1) && axis[1] === 'south')) {
         axisOrder += 's';
-      } else if (axis[0].indexOf('east') !== -1 || ((axis[0] === 'x' || axis[0] === 'lon') && axis[1] === 'east')) {
+      } else if (axis[0].indexOf('east') !== -1 || ((axis[0] === 'x' || axis[0].indexOf('lon') !== -1) && axis[1] === 'east')) {
         axisOrder += 'e';
-      } else if (axis[0].indexOf('west') !== -1 || ((axis[0] === 'x' || axis[0] === 'lon') && axis[1] === 'west')) {
+      } else if (axis[0].indexOf('west') !== -1 || ((axis[0] === 'x' || axis[0].indexOf('lon') !== -1) && axis[1] === 'west')) {
         axisOrder += 'w';
       }
     }

or by entirely removing the ((axis[0] === '?' || axis[0] === '???') && check

but the question is why the code is done like it is now

@ahocevar
Copy link
Member

I'd rather do axis[0].startsWith('lat') instead of axis[0].indexOf('lat') !== -1, but other than that the change makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants