Developing operator in java, how to add and use external data?

when I’m developing snap operator referred your snap code about snap engine operator, I have some curious things.

  1. If I want load other external files or data (made for me) except files in zip file, how can I do that?

  2. If I can solve putting the files (or data) in the zip file, how can I access the files(or data)?
    should I make the files to xml file or other format?

  3. if It can’t solve in developing snap operator, what is alternative solutions???

With zip file you mean the nbm file, right?
If you put your files into src/main/resources/* you can load them as usual in Java by

    getClass().getResource("path");
    getClass().getResourceAsStream("path");

If you simply want to let the user access and edit the data you can use ResourceInstaller.
Look for usages of this class in the SNAP code base.

This is one example:

    Path auxdataDirectory = SystemUtils.getAuxDataPath().resolve("olci/smile/");
    final Path sourceDirPath = ResourceInstaller.findModuleCodeBasePath(SmileCorrectionAuxdata.class).resolve("auxdata/smile");
    final ResourceInstaller resourceInstaller = new ResourceInstaller(sourceDirPath, auxdataDirectory);
    resourceInstaller.install(".*", ProgressMonitor.NULL);

The format of the data is up to you.

oh thank you.
the zip file means including xml(calibration, noise and etc) and geotiff file.
I make a operator needed extra data besides the zip file.
so when I add the external operator in snap, how to access the extra data? (it’s my problem!! sorry!)
I’m ok to make some format file saved the data.
but if I put the data files into src/main/resources/*, I can’t correspond to many zip files.(the data change depending on the zip file.)
can I use file input methods in java in snap operator???

Of course, you can access the files as you need it. You can read the file in the init part of the operator for example, or only the part you currently need in the computeTile method.
You can also have a parameter to let the user point to the file which shall be loaded.

thank you!!
I have a question.
is computeTile method called after init is called???

Yes. This is ensured.

1 Like