0

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

3
  • 1
    Try epsg:3857 rather than just the number
    – Ian Turton
    Dec 17, 2022 at 13:34
  • thanks @IanTurton but no joy, same error Dec 17, 2022 at 14:36
  • 1
    I guess not exactly the same ERROR 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?
    – user30184
    Dec 18, 2022 at 16:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.