package scripts; import java.util.*; import java.io.*; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.entities.*; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.IsisFishDAOHelper; import fr.ifremer.isisfish.map.GeoTools; /** * créer zone pop, importer les shapefiles depuis un dossier * nom fichier doit être le même avec les zones * * N.B. il y a une option pour supprimer tous les zones pop ! faire attention ! * * Auteur: PHAN Tuan Anh, 2022 * Adapted by Lehuta, 2023 */ public class AddCellsToZoneFromShp { String isisZoneName = "Sardine @ mai @ 10 @ zone low"; /** * mettre ici dossier de shapefile */ String shpZoneName = PTAtoolbox_DEFIPEL.DATA_FOLDER +"/zone pop/Sardine @ mai @ 15 @ zone low.shp"; /** * les objets pour manipuler objets isis */ TopiaContext myTX = RegionStorage.getRegion(PTAtoolbox_DEFIPEL.REGION_NAME).getStorage().beginTransaction(); FisheryRegion myRegion = IsisFishDAOHelper.getFisheryRegionDAO(myTX).findByName(PTAtoolbox_DEFIPEL.REGION_NAME); List listCells = myRegion.getCell(); Zone myIsisZone = IsisFishDAOHelper.getZoneDAO(myTX).findByName(isisZoneName); //appel public static void main(String[] args) throws Exception { System.out.println("~~~ Start: " + new Date() + " ~~~" + System.lineSeparator()); AddCellsToZoneFromShp myScript = new AddCellsToZoneFromShp(); myScript.addCellsFromShp(); System.out.println("~~~ Done: " + new Date() + " ~~~"); } // methode public void addCellsFromShp() throws Exception { File shpFile = new File(shpZoneName); Collection cellsFromFile = GeoTools.getCellFromShapefile(myRegion, listCells, shpFile); List listCellsFromFile = new ArrayList<>(cellsFromFile);//convert Collection to List List myZoneCells = myIsisZone.getCell(); // si ca doit être disjoint listCellsFromFile.removeAll(myZoneCells); // option 1 myZoneCells.addAll(listCellsFromFile); myIsisZone.setCell(myZoneCells); // alternative si ca n'ecrase pas l existant : //myIsisZone.addAllCell(new ArrayList<>(cellsFromFile)); myIsisZone.update(); } }