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

vertical transform / grid files #36

Open
fr-an-k opened this issue May 22, 2024 · 6 comments
Open

vertical transform / grid files #36

fr-an-k opened this issue May 22, 2024 · 6 comments

Comments

@fr-an-k
Copy link

fr-an-k commented May 22, 2024

I'm trying to do a 3D coordinate transform like this:

import SPL from "./dist/spl-node.mjs";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

let spl = SPL().mount(__dirname + "/dist").db().read(
  "select InitSpatialMetaDataFull(1);select PROJ_SetDatabasePath('proj/proj.db')"
);
console.log(spl.exec("SELECT Transform(MakePointZ(4.88969, 52.37403, 50, 4937),7415)"));

but the height remains unaltered:

{
  'Transform(MakePointZ(4.88969,52.37403,50,4937),7415)':
    { type: 'Point', coordinates: [ 121120.297826, 487466.922163, 50 ] }
}

This is node but I also tried the browser.

I was expecting the full proj.db to include or automatically fetch the gridfiles (nl_nsgi_nlgeo2018.tif on official PROJ CDN), but it appears this is not the case or the vertical transformation is silently ignored for some other reason.

I also tried EPSG 9286, which would only convert the height of the desired CRS, but this also doesn't work.

Documentation on PROJ and spatialite and spl.js are rather sparse, especially on vertical transformation.

Any ideas on how to proceed?
Is TIFF supported at all in the default build?

An alternative way to do this in the browser without spatialite dependency would also be great, but I suspect this is not going to happen anytime soon and I'm under too much time pressure myself.

@fr-an-k
Copy link
Author

fr-an-k commented May 22, 2024

My bad, the height is virtually the same; I was confused with something else.

@fr-an-k fr-an-k closed this as completed May 22, 2024
@jvail
Copy link
Owner

jvail commented May 24, 2024

Hi @fr-an-k I have unfortunately no experience at all with those tif files to perform transformations. But indeed the fetching over the network by proj is currently disabled because (as far as I remember) it gave some headache and compile issues. I am using -DPROJ_NETWORK=OFF to is disable it.

Maybe there is a way to fetch the file, then mount it in spl.js and pass the path to proj?

@fr-an-k
Copy link
Author

fr-an-k commented May 24, 2024

Thanks @jvail. Looking in the proj db I couldn't find a reference to the gridfiles, but for anyone reading this it's easy to do vertical datum transformation in the browser using the example of the npm geotiff library (and proj4.js for 2D CRS transformation).

@jvail
Copy link
Owner

jvail commented May 24, 2024

using the example of the npm geotiff library (and proj4.js for 2D CRS transformation).

Could you point me to an example to do this with geotiff/proj4.js? I think it would be interesting to experiment how this could be done in spl.js.

@fr-an-k
Copy link
Author

fr-an-k commented May 24, 2024

It's actually called geotiff.js: https://github.com/geotiffjs/geotiff.js/
The "Example Usage" shows how to extract the height correction for a certain lat/lon.
If the source data is in a different coordinate system you can use proj4js first: https://github.com/proj4js/proj4js.
Note that generally, lat lon refers to artificially stabilized locations per geographic area as if the continental plates don't move.
Note that grid files can be horizontal, vertical or both; I suppose the pixel values have to be interpreted differently according to specifications that should be somewhere.
I'm not familiar with vertical CRS WKT strings; it's possible that additional steps have to be taken in certain systems.

The geotiff gridfiles are maintained at https://github.com/OSGeo/PROJ-data and hosted on CDN and referred in the proj.db.
In a browser environment you could extract the wkt strings per epsg from spatial_ref_sys in a proj.db to a JSON/CSV, or use a general SQLite library to access it.

Spatialite should be able to handle this already, but I don't know if it attempts it at all in the current spl.js or fails silently.
In my case above, the height probably simply has correction 0, but I was trying to deal with a WSG84 height (ellipsoid to ETRS89 geoid and then adding Dutch land height) and the proj.db doesn't seem to know the CRS for that transformation, at least not directly. So above I only tried adding Dutch land height but that appears to be 0 for Amsterdam. In the end I just extracted the MSL height from the GPS (NMEA-0183 GGA) so that should have the ellipsoid to geoid correction already.

@jvail
Copy link
Owner

jvail commented May 24, 2024

Thank you for the detailed explanation. I am not sure about the automatic download of grids but if I can also compile/add libtiff then it should be doable if the grid file is downloaded in the main thread and then mounted in the worker filesystem. I will experiment a bit with it.

@jvail jvail reopened this May 24, 2024
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