Skip to content

PROJJSON prime_meridian as a value+unit object gives NaN from_greenwich #50

Description

@jiayuasu

I may be constructing this wrong, but when a PROJJSON prime_meridian.longitude is given as a value-with-unit object (the shape PROJ seems to emit for non-degree meridians) rather than a plain number, from_greenwich comes out NaN and the meridian offset seems to get dropped.

const proj4 = require('proj4'); // 2.20.9, wkt-parser 1.5.5
const json = {type:"GeographicCRS",name:"NTF (Paris)",datum:{type:"GeodeticReferenceFrame",name:"NTF (Paris)",ellipsoid:{name:"Clarke 1880 (IGN)",semi_major_axis:6378249.2,inverse_flattening:293.4660212936269},prime_meridian:{name:"Paris",longitude:{value:2.5969213,unit:{type:"AngularUnit",name:"grad",conversion_factor:0.015707963267949}}}},coordinate_system:{subtype:"ellipsoidal",axis:[{name:"Longitude",abbreviation:"lon",direction:"east",unit:"degree"},{name:"Latitude",abbreviation:"lat",direction:"north",unit:"degree"}]}};
console.log(new proj4.Proj(json).from_greenwich);        // NaN
console.log(proj4('EPSG:4326', json, [2.5, 48.5]));      // [2.5, 48.5]  (unchanged)

pyproj parses the same object and applies the shift:

from pyproj import CRS, Transformer
Transformer.from_crs("EPSG:4326", CRS.from_json_dict(json), always_xy=True).transform(2.5, 48.5)
# (0.16348, 48.50007)

A plain-number longitude (in degrees) seems to work fine, so it might be specific to the {value, unit} object form. At a glance transformPROJJSON.js (~lines 105/115) looks like it multiplies longitude by Math.PI/180 directly, which would explain the NaN if it's an object — but I'm not certain that's the right place. Is the value-with-unit form meant to be supported?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions