Search in sources :

Example 1 with EggClock

use of org.hortonmachine.gears.utils.time.EggClock in project hortonmachine by TheHortonMachine.

the class Mapurl2MbtilesConverter method process.

@Execute
public void process() throws Exception {
    checkNull(inFile);
    File mapurlFile = new File(inFile);
    HashMap<String, String> metadataMap = FileUtilities.readFileToHashMap(inFile, "=", false);
    String url = metadataMap.get("url");
    if (url == null) {
        throw new ModelsIllegalargumentException("The supplied file doesn't seem to be a valid HortonMachine mapurl file.", this, pm);
    }
    if (url.endsWith("jpg")) {
        format = "jpg";
    } else {
        format = "png";
    }
    File dbFile = FileUtilities.substituteExtention(mapurlFile, "mbtiles");
    String tilesetName = FileUtilities.getNameWithoutExtention(mapurlFile);
    File folderFile = new File(mapurlFile.getParentFile(), tilesetName);
    mbtilesHelper = new MBTilesHelper();
    mbtilesHelper.open(dbFile);
    mbtilesHelper.createTables(false);
    File[] zFolders = folderFile.listFiles();
    List<File> xFolder = new ArrayList<File>();
    for (File zFolder : zFolders) {
        File[] xFiles = zFolder.listFiles();
        for (File xFile : xFiles) {
            if (xFile.isDirectory()) {
                xFolder.add(xFile);
            }
        }
    }
    final GlobalMercator mercator = new GlobalMercator();
    int minZ = 1000;
    int maxZ = -1000;
    EggClock clock = new EggClock("Time check: ", " sec");
    clock.startAndPrint(System.out);
    for (File xFile : xFolder) {
        String zStr = xFile.getParentFile().getName();
        final int z = Integer.parseInt(zStr);
        minZ = min(minZ, z);
        maxZ = max(maxZ, z);
        String xStr = xFile.getName();
        final int x = Integer.parseInt(xStr);
        final File[] yFiles = xFile.listFiles(new FilenameFilter() {

            public boolean accept(File arg0, String name) {
                boolean endsWithPng = name.endsWith("png");
                boolean endsWithJpg = name.endsWith("jpg");
                if (endsWithPng || endsWithJpg) {
                    return true;
                }
                return false;
            }
        });
        for (File yFile : yFiles) {
            String yStr = FileUtilities.getNameWithoutExtention(yFile);
            int y = Integer.parseInt(yStr);
            Envelope wsen = mercator.TileLatLonBounds(x, y, z);
            n = max(n, wsen.getMaxY());
            e = max(e, wsen.getMaxX());
            s = max(s, wsen.getMinY());
            w = max(w, wsen.getMinX());
            try {
                BufferedImage image = ImageIO.read(yFile);
                mbtilesHelper.addTile(x, y, z, image, format);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            if (imageIndex % 1000 == 0) {
                pm.message("Images inserted in db: " + imageIndex);
                clock.printTimePassedInSeconds(System.out);
            }
            imageIndex++;
        }
    }
    mbtilesHelper.fillMetadata((float) n, (float) s, (float) w, (float) e, "tilesetName", format, minZ, maxZ);
    mbtilesHelper.createIndexes();
    mbtilesHelper.close();
}
Also used : ArrayList(java.util.ArrayList) Envelope(org.locationtech.jts.geom.Envelope) BufferedImage(java.awt.image.BufferedImage) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) EggClock(org.hortonmachine.gears.utils.time.EggClock) FilenameFilter(java.io.FilenameFilter) File(java.io.File) Execute(oms3.annotations.Execute)

Example 2 with EggClock

use of org.hortonmachine.gears.utils.time.EggClock in project hortonmachine by TheHortonMachine.

the class DatabaseLasWriter method main.

public static void main(String[] args) throws Exception {
    EggClock egg = new EggClock("DATABASE**************** ", "");
    egg.startAndPrint(System.out);
    DatabaseLasWriter w = new DatabaseLasWriter();
    w = new DatabaseLasWriter();
    w.pDbType = EDb.SPATIALITE.name();
    w.pLevels = 4;
    w.pCellsize = 1;
    w.inFolder = "/media/hydrologis/Samsung_T3/UNIBZ/monticolo_tls";
    w.inDatabasePath = "/media/hydrologis/Samsung_T3/UNIBZ/monticolo_tls/monticolo2018_point_cloud_02.sqlite";
    w.process();
    egg.printTimePassedInSeconds(System.out);
}
Also used : EggClock(org.hortonmachine.gears.utils.time.EggClock)

Aggregations

EggClock (org.hortonmachine.gears.utils.time.EggClock)2 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 ArrayList (java.util.ArrayList)1 Execute (oms3.annotations.Execute)1 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)1 Envelope (org.locationtech.jts.geom.Envelope)1