I am trying to write a method in Java that transforms from one CRS to another using GDAL's Java Bindings. Specifically from 3857 to 4326 (and a few others will be common to my use cases).
Here is my code so far (one easy to read permutation of the hundreds of things I've tried). The source and dest strings are paths to shapefiles
public static void warp(String source, String dest) {
ogr.RegisterAll();
Vector<String> options = new Vector<>();
options.add("-s_srs");
options.add("3857");
options.add("-t_srs");
options.add("4326");
WarpOptions ops = new WarpOptions(options);
Dataset[] des = new Dataset[1];
des[0]=gdal.Open(dest);
Dataset src = gdal.OpenEx(source);
int Warp = gdal.Warp(src, des, ops);
}
This is all I get for an error/exception:
ERROR 1: Translating source or target SRS failed: 3857
epsg:3857
rather than just the numberERROR 1: Translating source or target SRS failed: 3857
but with EPSG:3857, right? Does it work with some other -s_srs? Or without -s_srs and -t_srs? What I wonder is if the Proj library is installed right. Without Proj gdalwarp cannot warp. Have you set the PROJ_LIB environment?