Search in sources :

Example 1 with ExecutorProgressGui

use of org.hortonmachine.gui.utils.executor.ExecutorProgressGui in project hortonmachine by TheHortonMachine.

the class LasInfoController method exportAction.

private void exportAction(File saveFile) {
    String outputFilePath = saveFile.getAbsolutePath();
    if (!outputFilePath.toLowerCase().endsWith(".las") && !outputFilePath.toLowerCase().endsWith(".shp")) {
        JOptionPane.showMessageDialog(LasInfoController.this, "Only conversion to las and shp is supported.", "ERROR", JOptionPane.ERROR_MESSAGE);
        return;
    }
    ILasHeader header = lasReader.getHeader();
    long recordsCount = header.getRecordsCount();
    int work = (int) (recordsCount / 1000);
    new ExecutorProgressGui(work * 2) {

        @Override
        public void backGroundWork() throws Exception {
            constraints.applyConstraints(lasReader, true, this);
            List<LasRecord> filteredPoints = constraints.getFilteredPoints();
            publish(new ProgressUpdate("Now writing to file...", work + work / 2));
            if (outputFilePath.toLowerCase().endsWith(".las")) {
                ALasWriter lasWriter = Las.getWriter(new File(outputFilePath), header.getCrs());
                Envelope fEnv = constraints.getFilteredEnvelope();
                double[] stats = constraints.getStats();
                lasWriter.setBounds(lasReader.getHeader());
                lasWriter.setBounds(fEnv.getMinX(), fEnv.getMaxX(), fEnv.getMinY(), fEnv.getMaxY(), stats[0], stats[1]);
                lasWriter.open();
                filteredPoints.stream().forEach(lr -> {
                    try {
                        lasWriter.addPoint(lr);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                lasWriter.close();
            } else if (outputFilePath.toLowerCase().endsWith(".shp")) {
                DefaultFeatureCollection fc = new DefaultFeatureCollection();
                int count = 0;
                for (LasRecord lr : filteredPoints) {
                    SimpleFeature feature = LasUtils.tofeature(lr, count++, header.getCrs());
                    fc.add(feature);
                }
                OmsVectorWriter.writeVector(outputFilePath, fc);
            }
            done();
        }
    }.execute();
}
Also used : Color(java.awt.Color) Las(org.hortonmachine.gears.io.las.core.Las) ActionWithProgress(org.hortonmachine.gui.utils.monitor.ActionWithProgress) Point2D(java.awt.geom.Point2D) RandomIter(javax.media.jai.iterator.RandomIter) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) Coordinate(org.locationtech.jts.geom.Coordinate) DatabaseViewer(org.hortonmachine.database.DatabaseViewer) ColorInterpolator(org.hortonmachine.gears.utils.colors.ColorInterpolator) ProgressUpdate(org.hortonmachine.gears.ui.progress.ProgressUpdate) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LasUtils(org.hortonmachine.gears.io.las.utils.LasUtils) PreferencesHandler(org.hortonmachine.gears.utils.PreferencesHandler) ImageIO(javax.imageio.ImageIO) ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) HMConstants(org.hortonmachine.gears.libs.modules.HMConstants) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JFrame(javax.swing.JFrame) MouseListener(java.awt.event.MouseListener) ExecutorProgressGui(org.hortonmachine.gui.utils.executor.ExecutorProgressGui) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) BufferedImage(java.awt.image.BufferedImage) DefaultTableModel(javax.swing.table.DefaultTableModel) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Point(org.locationtech.jts.geom.Point) KeyEvent(java.awt.event.KeyEvent) AffineTransform(java.awt.geom.AffineTransform) Collectors(java.util.stream.Collectors) CoverageUtilities(org.hortonmachine.gears.utils.coverage.CoverageUtilities) OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) Dimension(java.awt.Dimension) List(java.util.List) TransformationUtils(org.hortonmachine.gears.utils.TransformationUtils) OmsVectorWriter(org.hortonmachine.gears.io.vectorwriter.OmsVectorWriter) Polygon(org.locationtech.jts.geom.Polygon) Geometry(org.locationtech.jts.geom.Geometry) BasicStroke(java.awt.BasicStroke) DefaultEngineeringCRS(org.geotools.referencing.crs.DefaultEngineeringCRS) GeneralPath(java.awt.geom.GeneralPath) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader) Rectangle(java.awt.Rectangle) GuiUtilities(org.hortonmachine.gui.utils.GuiUtilities) KeyListener(java.awt.event.KeyListener) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) HoughCircles(org.hortonmachine.gears.modules.r.houghes.HoughCircles) OmsHoughCirclesRaster(org.hortonmachine.gears.modules.r.houghes.OmsHoughCirclesRaster) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashMap(java.util.HashMap) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) BitMatrix(org.hortonmachine.gears.utils.BitMatrix) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProgressMonitor(org.hortonmachine.gui.utils.monitor.ProgressMonitor) SwingUtilities(javax.swing.SwingUtilities) IOnCloseListener(org.hortonmachine.gui.utils.GuiUtilities.IOnCloseListener) ALasWriter(org.hortonmachine.gears.io.las.core.ALasWriter) Graphics2D(java.awt.Graphics2D) ImageIcon(javax.swing.ImageIcon) GeometryUtilities(org.hortonmachine.gears.utils.geometry.GeometryUtilities) JComponent(javax.swing.JComponent) RandomIterFactory(javax.media.jai.iterator.RandomIterFactory) FileUtilities(org.hortonmachine.gears.utils.files.FileUtilities) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) ExecutorIndeterminateGui(org.hortonmachine.gui.utils.executor.ExecutorIndeterminateGui) JOptionPane(javax.swing.JOptionPane) FileFilter(javax.swing.filechooser.FileFilter) OmsVectorReader(org.hortonmachine.gears.io.vectorreader.OmsVectorReader) FeatureUtilities(org.hortonmachine.gears.utils.features.FeatureUtilities) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) OmsRasterReader(org.hortonmachine.gears.io.rasterreader.OmsRasterReader) LasConstraints(org.hortonmachine.gears.io.las.utils.LasConstraints) RegionMap(org.hortonmachine.gears.utils.RegionMap) WritableRaster(java.awt.image.WritableRaster) DefaultGuiBridgeImpl(org.hortonmachine.gui.utils.DefaultGuiBridgeImpl) Envelope(org.locationtech.jts.geom.Envelope) ProgressUpdate(org.hortonmachine.gears.ui.progress.ProgressUpdate) IOException(java.io.IOException) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) Point(org.locationtech.jts.geom.Point) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ExecutorProgressGui(org.hortonmachine.gui.utils.executor.ExecutorProgressGui) ALasWriter(org.hortonmachine.gears.io.las.core.ALasWriter) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection)

Example 2 with ExecutorProgressGui

use of org.hortonmachine.gui.utils.executor.ExecutorProgressGui in project hortonmachine by TheHortonMachine.

the class LasInfoController method loadDataAction.

private void loadDataAction() {
    ILasHeader header = lasReader.getHeader();
    long recordsCount = header.getRecordsCount();
    int work = (int) (recordsCount / 1000);
    new ExecutorProgressGui(work) {

        @Override
        public void backGroundWork() throws Exception {
            constraints.applyConstraints(lasReader, true, this);
        // done();
        }
    }.execute();
}
Also used : ExecutorProgressGui(org.hortonmachine.gui.utils.executor.ExecutorProgressGui) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) Point(org.locationtech.jts.geom.Point) IOException(java.io.IOException)

Example 3 with ExecutorProgressGui

use of org.hortonmachine.gui.utils.executor.ExecutorProgressGui in project hortonmachine by TheHortonMachine.

the class LasInfoController method createOverviewAction.

private void createOverviewAction(File saveFile) {
    String outputFilePath = saveFile.getAbsolutePath();
    ILasHeader header = lasReader.getHeader();
    long recordsCount = header.getRecordsCount();
    int work = (int) (recordsCount / 1000);
    new ExecutorProgressGui(work * 2) {

        @Override
        public void backGroundWork() throws Exception {
            constraints.applyConstraints(lasReader, true, this);
            publish(new ProgressUpdate("Getting bounds...", work + work / 2));
            Envelope filteredEnvelope = constraints.getFilteredEnvelope();
            Polygon polygon = GeometryUtilities.createPolygonFromEnvelope(filteredEnvelope);
            polygon.setUserData("Overview for " + lasReader.getLasFile().getName());
            SimpleFeatureCollection fc = FeatureUtilities.featureCollectionFromGeometry(header.getCrs(), polygon);
            String f = outputFilePath;
            if (!f.toLowerCase().endsWith(".shp"))
                f = f + ".shp";
            OmsVectorWriter.writeVector(f, fc);
            done();
        }
    }.execute();
}
Also used : ExecutorProgressGui(org.hortonmachine.gui.utils.executor.ExecutorProgressGui) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) ProgressUpdate(org.hortonmachine.gears.ui.progress.ProgressUpdate) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) Polygon(org.locationtech.jts.geom.Polygon) Point(org.locationtech.jts.geom.Point) IOException(java.io.IOException) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection)

Aggregations

IOException (java.io.IOException)3 ILasHeader (org.hortonmachine.gears.io.las.core.ILasHeader)3 ExecutorProgressGui (org.hortonmachine.gui.utils.executor.ExecutorProgressGui)3 Point (org.locationtech.jts.geom.Point)3 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)2 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)2 ProgressUpdate (org.hortonmachine.gears.ui.progress.ProgressUpdate)2 Envelope (org.locationtech.jts.geom.Envelope)2 Polygon (org.locationtech.jts.geom.Polygon)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 AffineTransform (java.awt.geom.AffineTransform)1 GeneralPath (java.awt.geom.GeneralPath)1