All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgrasstools.gears.modules.r.mosaic.OmsMosaic12 Maven / Gradle / Ivy

The newest version!
/*
 * This file is part of JGrasstools (http://www.jgrasstools.org)
 * (C) HydroloGIS - www.hydrologis.com 
 * 
 * JGrasstools is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.jgrasstools.gears.modules.r.mosaic;

import static org.jgrasstools.gears.libs.modules.Variables.BICUBIC;
import static org.jgrasstools.gears.libs.modules.Variables.BILINEAR;
import static org.jgrasstools.gears.libs.modules.Variables.NEAREST_NEIGHTBOUR;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import oms3.annotations.Author;
import oms3.annotations.Description;
import oms3.annotations.Documentation;
import oms3.annotations.Execute;
import oms3.annotations.In;
import oms3.annotations.Keywords;
import oms3.annotations.Label;
import oms3.annotations.License;
import oms3.annotations.Name;
import oms3.annotations.Status;
import oms3.annotations.UI;

import org.geotools.coverage.grid.GridCoverage2D;
import org.jgrasstools.gears.io.rasterwriter.OmsRasterWriter;
import org.jgrasstools.gears.libs.exceptions.ModelsIllegalargumentException;
import org.jgrasstools.gears.libs.modules.JGTConstants;
import org.jgrasstools.gears.libs.modules.JGTModel;

import static org.jgrasstools.gears.i18n.GearsMessages.*;

@Description(OMSMOSAIC12_DESCRIPTION)
@Documentation(OMSMOSAIC12_DOCUMENTATION)
@Author(name = OMSMOSAIC12_AUTHORNAMES, contact = OMSMOSAIC12_AUTHORCONTACTS)
@Keywords(OMSMOSAIC12_KEYWORDS)
@Label(OMSMOSAIC12_LABEL)
@Name(OMSMOSAIC12_NAME)
@Status(OMSMOSAIC12_STATUS)
@License(OMSMOSAIC12_LICENSE)
public class OmsMosaic12 extends JGTModel {

    @Description(OMSMOSAIC12_IN_MAP1_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap1;

    @Description(OMSMOSAIC12_IN_MAP2_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap2;

    @Description(OMSMOSAIC12_IN_MAP3_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap3;

    @Description(OMSMOSAIC12_IN_MAP4_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap4;

    @Description(OMSMOSAIC12_IN_MAP5_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap5;

    @Description(OMSMOSAIC12_IN_MAP6_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap6;

    @Description(OMSMOSAIC12_IN_MAP7_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap7;

    @Description(OMSMOSAIC12_IN_MAP8_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap8;

    @Description(OMSMOSAIC12_IN_MAP9_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap9;

    @Description(OMSMOSAIC12_IN_MAP10_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap10;

    @Description(OMSMOSAIC12_IN_MAP11_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap11;

    @Description(OMSMOSAIC12_IN_MAP12_DESCRIPTION)
    @UI(JGTConstants.FILEIN_UI_HINT)
    @In
    public String inMap12;

    @Description(OMSMOSAIC12_P_INTERPOLATION_DESCRIPTION)
    @UI("combo:" + NEAREST_NEIGHTBOUR + "," + BILINEAR + "," + BICUBIC)
    @In
    public String pInterpolation = NEAREST_NEIGHTBOUR;

    @Description(OMSMOSAIC12_OUT_MAP_DESCRIPTION)
    @UI(JGTConstants.FILEOUT_UI_HINT)
    @In
    public String outMap = null;

    public GridCoverage2D outRaster;

    public boolean testmode = false;

    @Execute
    public void process() throws Exception {
        if (!testmode)
            checkNull(outMap);

        List filesList = new ArrayList();
        checkMap(filesList, inMap1);
        checkMap(filesList, inMap2);
        checkMap(filesList, inMap3);
        checkMap(filesList, inMap4);
        checkMap(filesList, inMap5);
        checkMap(filesList, inMap6);
        checkMap(filesList, inMap7);
        checkMap(filesList, inMap8);
        checkMap(filesList, inMap9);
        checkMap(filesList, inMap10);
        checkMap(filesList, inMap11);
        checkMap(filesList, inMap12);

        if (filesList.size() < 2) {
            throw new ModelsIllegalargumentException("The patching module needs at least two maps to be patched.", this, pm);
        }

        OmsMosaic mosaic = new OmsMosaic();
        mosaic.inFiles = filesList;
        mosaic.pm = pm;
        mosaic.process();

        outRaster = mosaic.outRaster;
        if (!testmode)
            OmsRasterWriter.writeRaster(outMap, outRaster);
    }

    private void checkMap( List filesList, String inMap ) {
        if (inMap != null) {
            File tmp = new File(inMap);
            if (tmp.exists()) {
                filesList.add(tmp);
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy