'How is the gdal.Translate function used in the GDAL Java bindings?

I am trying to preform some processing (i.e. applying a function to the contents of each cell of a raster, and then writing that out as a new raster), where the SRS of the input dataset is different (and has a different extent) from the target SRS.

To sole this, I attempted to use the gdal.Translate function from the gdal Java bindings, to translate the input data set into the proper SRS and extent before processing it, however -- I can not for the life of me figure out how this function is actually meant to be called. This function takes a TranslateOptions as input, which takes a vector of options, as documented here -- but what are those options? Do I pass in strings? Pairs? Is there an TranslateOption class I missed somewhere?

When I hover over the argument in my IDE, it tells me that TranslateOption takes a Vector<Any>, so I am at a complete loss as to how to use this function, since the SWIG generated java bindings do not have any helpful javadocs added.

I assume that the TranslateOptions probably correspond to the options of the command line gdal_translate utility (I can't shell out to this directly for my application for various reasons), but again, how are these options passed into the vector that gets passed into TranslateOptions? I cannot find any documentation on this or usage examples online.



Solution 1:[1]

This is my code, it seems like work.

Dataset dataset = gdal.Open(rasterPath);
Vector<String> vector = new Vector<>();
vector.add("-projwin");
vector.add("116.142551771");
vector.add("40.159559805");
vector.add("116.298301771");
vector.add("40.054859805");

TranslateOptions options = new TranslateOptions(vector);
gdal.Translate(rasterCutPath, dataset, options);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jackspring