yocontra / node-gdal-next

Node.js bindings for GDAL (Geospatial Data Abstraction Library) [Fork]
https://contra.io/node-gdal-next/
Apache License 2.0
75 stars 36 forks source link

Best way to georeference an image? #11

Open JamesLMilner opened 4 years ago

JamesLMilner commented 4 years ago

Hello! Firstly thanks for continuing on this library great to see it being maintained.

I am looking to try and georeference an image using node-gdal-next. I have seen in the tests (https://github.com/contra/node-gdal-next/blob/a41e0328a4551c6ebdd983b934433388fbc6d902/test/api_warp.test.js#L76) some examples of warping and reprojecting images, but it seems to be from one CRS to another CRS, rather than from an pixel space to a CRS. Is there a way to do georeference an image which doesn't already have a coordinate reference system? Essentially I think I'm looking to do the equivalent of these two GDAL commands:

gdal_translate -of GTiff -a_ullr ullon ullat lrlon lrlat -a_srs EPSG:4269 input.tif output.tif
gdalwarp -of GTiff  -t_srs EPSG:3857 input.tif output.tif

Let me know if this makes sense or if I can clarify anything.

yocontra commented 4 years ago

@JamesLMilner I wish we could bind a lot of those CLI tools (gdalwarp/gdal_translate) and make them available as simple JS APIs, but they aren't built in a way that makes that possible. The only real way to use them as-is is to just execute them with child_process.

The good news though is all those tools are doing is using the same lower level native APIs that this binding exposes and piecing them together - what I would recommend doing is looking at the source code of the command line tool that works for you and see if you can recreate the behavior using the same APIs. We do have GTiff bindings so you should be able to read in the file - I'm not sure how reprojecting that works though so please let me know if you have any issues with it and I can dig into it more.

yocontra commented 4 years ago

For reference you can find the source code for all of the command line tools here: https://github.com/contra/node-gdal-next/tree/master/deps/libgdal/gdal/apps