Axis order not correctly extracted from EPSG:4326
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
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?
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
I'd rather do axis[0].startsWith('lat') instead of axis[0].indexOf('lat') !== -1, but other than that the change makes sense.