proj4js / wkt-parser

parse all the wkt
Other
20 stars 15 forks source link

Support GEOGCRS #19

Open kylebarron opened 3 years ago

kylebarron commented 3 years ago

Attempted fix for https://github.com/proj4js/proj4js/issues/370. I don't know WKT very well, so looking forward to a review.

var parser = require('./wkt.build')
var wkt = `\
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["unknown"],
        AREA["World"],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]
`
var out = parser(wkt)
console.log(JSON.stringify(out))
{
  "type": "GEOGCRS",
  "name": "WGS 84",
  "DATUM": {
    "name": "World Geodetic System 1984",
    "ELLIPSOID": {
      "name": "WGS 84",
      "a": 6378137,
      "rf": 298.257223563,
      "LENGTHUNIT": { "metre": 1 }
    }
  },
  "PRIMEM": {
    "name": "greenwich",
    "convert": 0,
    "ANGLEUNIT": { "degree": 0.0174532925199433 }
  },
  "CS": { "ellipsoidal": 2 },
  "AXIS": [
    [
      "geodetic latitude (Lat)",
      "north",
      ["ORDER", 1],
      ["ANGLEUNIT", "degree", 0.0174532925199433]
    ],
    [
      "geodetic longitude (Lon)",
      "east",
      ["ORDER", 2],
      ["ANGLEUNIT", "degree", 0.0174532925199433]
    ]
  ],
  "USAGE": {
    "SCOPE": "unknown",
    "AREA": "World",
    "BBOX": { "-90": { "-180": { "90": 180 } } }
  },
  "ID": { "EPSG": 4326 },
  "projName": "longlat",
  "datumCode": "wgs84",
  "srsCode": "WGS 84"
}
kylebarron commented 3 years ago

I tried to test this locally with proj4js but it didn't seem to fix the problem.

kudlav commented 1 year ago

GEOGCRS keyword needs to be added also into codeWords array in the proj4js/lib/parseCode.js:

var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS','GEOCCS','PROJCS','LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'];
function testWKT(code){
  return codeWords.some(function (word) {
    return code.indexOf(word) > -1;
  });
}
kylebarron commented 1 year ago

@kudlav I don't have the bandwidth right now to work on this PR; you're welcome to make a new one based off of this