Search in sources :

Example 1 with ILasHeader

use of org.hortonmachine.gears.io.las.core.ILasHeader in project hortonmachine by TheHortonMachine.

the class LasInfoController method init.

private void init() {
    _inputPathField.setEditable(false);
    GuiUtilities.setFileBrowsingOnWidgets(_inputPathField, _loadButton, new String[] { "las", "laz" }, () -> {
        new ExecutorIndeterminateGui() {

            @Override
            public void backGroundWork() throws Exception {
                loadNewFile();
            }
        }.execute();
    });
    _dtmInputPathField.setEditable(false);
    GuiUtilities.setFileBrowsingOnWidgets(_dtmInputPathField, _loadDtmButton, new String[] { "asc", "tiff" }, () -> {
        new ExecutorIndeterminateGui() {

            @Override
            public void backGroundWork() throws Exception {
                loadDtm();
            }
        }.execute();
    });
    _boundsLoadButton.addActionListener(e -> {
        File[] shpFile = GuiUtilities.showOpenFilesDialog(_boundsLoadButton, "Select bounds file...", false, PreferencesHandler.getLastFile(), new GuiUtilities.ShpFileFilter());
        if (shpFile != null) {
            new ExecutorIndeterminateGui() {

                @Override
                public void backGroundWork() throws Exception {
                    loadBoundsFromFile(shpFile[0]);
                }
            }.execute();
        }
    });
    _samplingField.setText("1000");
    constraints.setSampling(1000);
    _samplingField.addKeyListener(this);
    _classesField.addKeyListener(this);
    _impulsesField.addKeyListener(this);
    _intensityRangeField.addKeyListener(this);
    _westField.addKeyListener(this);
    _eastField.addKeyListener(this);
    _southField.addKeyListener(this);
    _northField.addKeyListener(this);
    _minZField.addKeyListener(this);
    _maxZField.addKeyListener(this);
    _lowerThresField.addKeyListener(this);
    _upperThresField.addKeyListener(this);
    _elevationRadio.setSelected(true);
    _convertButton.addActionListener(e -> {
        if (checkReader()) {
            File saveFile = GuiUtilities.showSaveFileDialog(this, "Save to file", PreferencesHandler.getLastFile());
            if (saveFile != null) {
                exportAction(saveFile);
            }
        }
    });
    _createOverviewButton.addActionListener(e -> {
        if (checkReader()) {
            File saveFile = GuiUtilities.showSaveFileDialog(this, "Save to file", PreferencesHandler.getLastFile());
            if (saveFile != null) {
                createOverviewAction(saveFile);
            }
        }
    });
    _previewImageLabel.addMouseListener(new MouseListener() {

        private boolean oneTwo = true;

        @Override
        public void mouseReleased(MouseEvent e) {
            if (pixelToWorld != null) {
                int px = e.getX();
                int py = e.getY();
                Point2D fromPoint = new Point2D.Double(px, py);
                Point2D toPoint = new Point2D.Double();
                pixelToWorld.transform(fromPoint, toPoint);
                if (SwingUtilities.isMiddleMouseButton(e)) {
                    Envelope env = constraints.getFilteredEnvelope();
                    double expX = env.getWidth() * 0.2 / 2.0;
                    double expY = env.getHeight() * 0.2 / 2.0;
                    Envelope newEnv = new Envelope(env);
                    newEnv.expandBy(expX, expY);
                    constraints.setWest(newEnv.getMinX());
                    constraints.setEast(newEnv.getMaxX());
                    constraints.setSouth(newEnv.getMinY());
                    constraints.setNorth(newEnv.getMaxY());
                // drawPreview();
                } else {
                    if (SwingUtilities.isLeftMouseButton(e)) {
                        double x = toPoint.getX();
                        double y = toPoint.getY();
                        if (oneTwo) {
                            constraints.setWest(x);
                            constraints.setSouth(y);
                        } else {
                            constraints.setEast(x);
                            constraints.setNorth(y);
                        }
                        oneTwo = !oneTwo;
                    } else if (SwingUtilities.isRightMouseButton(e)) {
                        constraints.setEast(null);
                        constraints.setNorth(null);
                        constraints.setWest(null);
                        constraints.setSouth(null);
                    }
                    Double[] propBounds = constraints.checkBounds();
                    _westField.setText(propBounds[0] != null ? propBounds[0].toString() : "");
                    _eastField.setText(propBounds[1] != null ? propBounds[1].toString() : "");
                    _southField.setText(propBounds[2] != null ? propBounds[2].toString() : "");
                    _northField.setText(propBounds[3] != null ? propBounds[3].toString() : "");
                    drawWithMouseBounds();
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    _loadPreviewButton.addActionListener(e -> {
        if (checkReader()) {
            new ExecutorIndeterminateGui() {

                @Override
                public void backGroundWork() throws Exception {
                    constraints.applyConstraints(lasReader, false, null);
                    List<LasRecord> filteredPoints = constraints.getFilteredPoints();
                    drawPreview(filteredPoints);
                }
            }.execute();
        }
    });
    _loadDataButton.addActionListener(e -> {
        if (checkReader()) {
            loadDataAction();
        }
    });
    _load3DButton.setVisible(false);
    // _load3DButton.addActionListener(e -> {
    // if (checkReader()) {
    // AbstractAnalysis abstractAnalysis = new AbstractAnalysis(){
    // @Override
    // public void init() throws Exception {
    // constraints.applyConstraints(lasReader, false, null);
    // List<LasRecord> filteredPoints = constraints.getFilteredPoints();
    // List<Coord3d> points = new ArrayList<>();
    // List<org.jzy3d.colors.Color> colors = new ArrayList<>();
    // for( LasRecord dot : filteredPoints ) {
    // float x = (float) dot.x;
    // float y = (float) dot.y;
    // float z = (float) dot.z;
    // if (!Double.isNaN(dot.groundElevation)) {
    // z = (float) dot.groundElevation;
    // }
    // points.add(new Coord3d(x, y, z));
    // short[] c = dot.color;
    // colors.add(new org.jzy3d.colors.Color((int) c[0], (int) c[1], (int) c[2]));
    // }
    // Coord3d[] coord3ds = points.toArray(new Coord3d[points.size()]);
    // org.jzy3d.colors.Color[] colorsArray = colors.toArray(new org.jzy3d.colors.Color[colors.size()]);
    // Scatter scatterLas = new Scatter(coord3ds, colorsArray, 7f);
    // String text = _pointSizeField.getText();
    // int pointSize = 1;
    // try {
    // pointSize = Integer.parseInt(text.trim());
    // } catch (Exception e) {
    // // ignore
    // }
    // scatterLas.setWidth(pointSize);
    // chart = AWTChartComponentFactory.chart(Quality.Fastest, "newt");
    // chart.getScene().getGraph().add(scatterLas);
    // //                    chart.setAxeDisplayed(false);
    // chart.getView().setSquared(false);
    // }
    // };
    // try {
    // AnalysisLauncher.open(abstractAnalysis);
    // } catch (Exception e1) {
    // GuiUtilities.handleError(_boundsLoadButton, e1);
    // }
    // }
    // });
    _sliceIntervalField.setText("1");
    _sliceWidthField.setText("0.2");
    _slicingModeCheck.addActionListener(e -> {
        if (checkReader()) {
            sliceModeIsOn = _slicingModeCheck.isSelected();
            _loadSlicedataButton.setEnabled(sliceModeIsOn);
            _slicesCombo.setEnabled(sliceModeIsOn);
        }
    });
    _loadSlicedataButton.addActionListener(e -> {
        if (checkReader()) {
            new ExecutorIndeterminateGui() {

                @Override
                public void backGroundWork() throws Exception {
                    loadSliceData();
                }
            }.execute();
        }
    });
    _slicesCombo.addActionListener(e -> {
        String slice = _slicesCombo.getSelectedItem().toString();
        if (slicesMap != null) {
            List<LasRecord> lrList = slicesMap.get(slice);
            if (lrList != null) {
                new ExecutorIndeterminateGui() {

                    @Override
                    public void backGroundWork() throws Exception {
                        drawPreview(lrList);
                    }
                }.execute();
                return;
            }
        }
        GuiUtilities.showWarningMessage(this, "No slice data available. ");
    });
    _circlesMinCellCountField.setText("50");
    _circlesExtractButton.addActionListener(e -> {
        if (checkReader()) {
            new ExecutorIndeterminateGui() {

                @Override
                public void backGroundWork() throws Exception {
                    try {
                        List<Geometry> circles = getCircleGeometries();
                        BufferedImage withCirclesImage = new BufferedImage(lastDrawnImage.getWidth(), lastDrawnImage.getHeight(), BufferedImage.TYPE_INT_RGB);
                        Graphics2D g2d = (Graphics2D) withCirclesImage.getGraphics();
                        g2d.drawImage(lastDrawnImage, 0, 0, null);
                        GeneralPath gp = new GeneralPath();
                        for (Geometry g : circles) {
                            Coordinate[] coords = g.getCoordinates();
                            boolean isNew = true;
                            for (Coordinate coordinate : coords) {
                                Coordinate newCoord = TransformationUtils.transformCoordinate(worldToPixel, coordinate);
                                if (isNew) {
                                    gp.moveTo(newCoord.x, newCoord.y);
                                    isNew = false;
                                } else {
                                    gp.lineTo(newCoord.x, newCoord.y);
                                }
                            }
                        }
                        g2d.setColor(Color.red);
                        g2d.setStroke(new BasicStroke(3));
                        g2d.draw(gp);
                        g2d.dispose();
                        _previewImageLabel.setIcon(new ImageIcon(withCirclesImage));
                    } catch (Exception e1) {
                        GuiUtilities.showErrorMessage(LasInfoController.this, null, e1.getMessage());
                    }
                }
            }.execute();
        }
    });
    _circlesSaveShpButton.addActionListener(e -> {
        if (checkReader()) {
            File saveFile = GuiUtilities.showSaveFileDialog(this, "Save circles to shp", PreferencesHandler.getLastFile());
            if (saveFile != null) {
                new ExecutorIndeterminateGui() {

                    @Override
                    public void backGroundWork() throws Exception {
                        try {
                            List<Geometry> circles = getCircleGeometries();
                            ILasHeader header = lasReader.getHeader();
                            CoordinateReferenceSystem crs = header.getCrs();
                            if (crs == null) {
                                crs = DEFAULT_GENERIC;
                            }
                            SimpleFeatureCollection fc = FeatureUtilities.featureCollectionFromGeometry(crs, circles.toArray(new Geometry[0]));
                            OmsVectorWriter.writeVector(saveFile.getAbsolutePath(), fc);
                        } catch (Exception e1) {
                            GuiUtilities.showErrorMessage(LasInfoController.this, null, e1.getMessage());
                        }
                    }
                }.execute();
            }
        }
    });
}
Also used : BasicStroke(java.awt.BasicStroke) ImageIcon(javax.swing.ImageIcon) GeneralPath(java.awt.geom.GeneralPath) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) GuiUtilities(org.hortonmachine.gui.utils.GuiUtilities) BufferedImage(java.awt.image.BufferedImage) MouseListener(java.awt.event.MouseListener) Point2D(java.awt.geom.Point2D) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) List(java.util.List) ArrayList(java.util.ArrayList) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ExecutorIndeterminateGui(org.hortonmachine.gui.utils.executor.ExecutorIndeterminateGui) MouseEvent(java.awt.event.MouseEvent) IOException(java.io.IOException) Graphics2D(java.awt.Graphics2D) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) File(java.io.File)

Example 2 with ILasHeader

use of org.hortonmachine.gears.io.las.core.ILasHeader in project hortonmachine by TheHortonMachine.

the class FlightLinesIntensityNormalizer method process.

@Execute
public void process() throws Exception {
    checkNull(inLas, inFlightpoints, pDateTimePattern);
    int timeType = -1;
    if (pGpsTimeType.equals(FlightLinesExtractor.ADJUSTED_STANDARD_GPS_TIME)) {
        timeType = 1;
    }
    if (pGpsTimeType.equals(FlightLinesExtractor.WEEK_SECONDS_TIME)) {
        timeType = 0;
    }
    SimpleFeatureCollection flightPointsFC = OmsVectorReader.readVector(inFlightpoints);
    List<SimpleFeature> flightPointsList = FeatureUtilities.featureCollectionToList(flightPointsFC);
    SimpleFeatureType schema = flightPointsFC.getSchema();
    String dateName = FeatureUtilities.findAttributeName(schema, "date");
    String timeName = FeatureUtilities.findAttributeName(schema, "time");
    String elevName = FeatureUtilities.findAttributeName(schema, "elev");
    if (dateName == null || timeName == null || elevName == null) {
        throw new ModelsIllegalargumentException("The shapefile has to contain the fields date time and elev.", this);
    }
    pm.beginTask("Defining flight intervals and positions...", flightPointsList.size());
    DateTimeFormatter formatter = DateTimeFormat.forPattern(pDateTimePattern).withZone(DateTimeZone.UTC);
    TreeMap<DateTime, Coordinate> date2pointsMap = new TreeMap<DateTime, Coordinate>();
    TreeMap<Coordinate, DateTime> points2dateMap = new TreeMap<Coordinate, DateTime>();
    for (int i = 0; i < flightPointsList.size(); i++) {
        SimpleFeature flightPoint = flightPointsList.get(i);
        Geometry g1 = (Geometry) flightPoint.getDefaultGeometry();
        Coordinate c1 = g1.getCoordinate();
        double elev1 = ((Number) flightPoint.getAttribute(elevName)).doubleValue();
        c1.z = elev1;
        String date1 = flightPoint.getAttribute(dateName).toString();
        String time1 = flightPoint.getAttribute(timeName).toString();
        String dateTime1 = date1 + " " + time1;
        DateTime d1 = formatter.parseDateTime(dateTime1);
        date2pointsMap.put(d1, c1);
        points2dateMap.put(c1, d1);
        pm.worked(1);
    }
    pm.done();
    pm.beginTask("Create time index...", flightPointsList.size() - 1);
    DateTime minDate = null;
    DateTime maxDate = null;
    long minLong = Long.MAX_VALUE;
    long maxLong = -Long.MAX_VALUE;
    STRtree tree = new STRtree(flightPointsList.size());
    Set<Entry<DateTime, Coordinate>> pointsSet = date2pointsMap.entrySet();
    Entry[] array = pointsSet.toArray(new Entry[0]);
    for (int i = 0; i < array.length - 1; i++) {
        DateTime d1 = (DateTime) array[i].getKey();
        Coordinate c1 = (Coordinate) array[i].getValue();
        DateTime d2 = (DateTime) array[i + 1].getKey();
        Coordinate c2 = (Coordinate) array[i + 1].getValue();
        long millis1 = d1.getMillis();
        long millis2 = d2.getMillis();
        Envelope timeEnv = new Envelope(millis1, millis2, millis1, millis2);
        tree.insert(timeEnv, new Coordinate[] { c1, c2 });
        if (millis1 < minLong) {
            minLong = millis1;
            minDate = d1;
        }
        if (millis2 > maxLong) {
            maxLong = millis2;
            maxDate = d2;
        }
        pm.worked(1);
    }
    pm.done();
    StringBuilder sb = new StringBuilder();
    sb.append("Flight data interval: ");
    sb.append(minDate.toString(HMConstants.dateTimeFormatterYYYYMMDDHHMMSS));
    sb.append(" to ");
    sb.append(maxDate.toString(HMConstants.dateTimeFormatterYYYYMMDDHHMMSS));
    pm.message(sb.toString());
    CoordinateReferenceSystem crs = null;
    File lasFile = new File(inLas);
    File outLasFile = new File(outLas);
    try (// 
    ALasReader reader = ALasReader.getReader(lasFile, crs);
        ALasWriter writer = ALasWriter.getWriter(outLasFile, crs)) {
        reader.setOverrideGpsTimeType(timeType);
        ILasHeader header = reader.getHeader();
        int gpsTimeType = header.getGpsTimeType();
        writer.setBounds(header);
        writer.open();
        pm.beginTask("Interpolating flight points and normalizing...", (int) header.getRecordsCount());
        while (reader.hasNextPoint()) {
            LasRecord r = reader.getNextPoint();
            DateTime gpsTimeToDateTime;
            if (timeType == 0) {
                gpsTimeToDateTime = GpsTimeConverter.gpsWeekTime2DateTime(r.gpsTime);
            } else {
                gpsTimeToDateTime = LasUtils.adjustedStandardGpsTime2DateTime(r.gpsTime);
            }
            long gpsMillis = gpsTimeToDateTime.getMillis();
            Coordinate lasCoordinate = new Coordinate(r.x, r.y, r.z);
            Envelope pEnv = new Envelope(new Coordinate(gpsMillis, gpsMillis));
            List points = tree.query(pEnv);
            Coordinate[] flightCoords = (Coordinate[]) points.get(0);
            long d1 = points2dateMap.get(flightCoords[0]).getMillis();
            long d2 = points2dateMap.get(flightCoords[1]).getMillis();
            LineSegment line = new LineSegment(flightCoords[0], flightCoords[1]);
            double fraction = (gpsMillis - d1) / (d2 - d1);
            Coordinate interpolatedFlightPoint = line.pointAlong(fraction);
            // calculate interpolated elevation
            double distX = interpolatedFlightPoint.distance(flightCoords[0]);
            double dist12 = flightCoords[1].distance(flightCoords[0]);
            double interpolatedElev = distX / dist12 * (flightCoords[1].z - flightCoords[0].z) + flightCoords[0].z;
            interpolatedFlightPoint.z = interpolatedElev;
            double distanceFlightTerrain = GeometryUtilities.distance3d(lasCoordinate, interpolatedFlightPoint, null);
            short norm = (short) floor(r.intensity * pow(distanceFlightTerrain, 2.0) / pStdRange + 0.5);
            r.intensity = norm;
            writer.addPoint(r);
            pm.worked(1);
        }
        pm.done();
    }
}
Also used : Envelope(org.locationtech.jts.geom.Envelope) DateTime(org.joda.time.DateTime) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) Entry(java.util.Map.Entry) ALasWriter(org.hortonmachine.gears.io.las.core.ALasWriter) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) STRtree(org.locationtech.jts.index.strtree.STRtree) List(java.util.List) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader) LineSegment(org.locationtech.jts.geom.LineSegment) TreeMap(java.util.TreeMap) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(org.locationtech.jts.geom.Geometry) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) File(java.io.File) Execute(oms3.annotations.Execute)

Example 3 with ILasHeader

use of org.hortonmachine.gears.io.las.core.ILasHeader in project hortonmachine by TheHortonMachine.

the class LasElevationHandler method process.

@Execute
public void process() throws Exception {
    checkNull(inFile, inDtm);
    GridCoverage2D dtm = getRaster(inDtm);
    File inLas = new File(inFile);
    try (ALasReader reader = ALasReader.getReader(inLas, null)) {
        reader.open();
        ILasHeader header = reader.getHeader();
        long recordsNum = header.getRecordsCount();
        ReferencedEnvelope3D env = header.getDataEnvelope();
        File outLas = new File(outFile);
        try (ALasWriter writer = ALasWriter.getWriter(outLas, env.getCoordinateReferenceSystem())) {
            writer.setBounds(header);
            writer.open();
            pm.beginTask("Normalizing las...", (int) recordsNum);
            while (reader.hasNextPoint()) {
                LasRecord dot = reader.getNextPoint();
                double dtmValue = CoverageUtilities.getValue(dtm, dot.x, dot.y);
                if (HMConstants.isNovalue(dtmValue)) {
                    dtmValue = 0;
                }
                if (doAdd) {
                    dot.z += dtmValue;
                } else {
                    dot.z -= dtmValue;
                }
                writer.addPoint(dot);
                pm.worked(1);
            }
            pm.done();
        }
    }
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) ALasWriter(org.hortonmachine.gears.io.las.core.ALasWriter) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) File(java.io.File) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader) Execute(oms3.annotations.Execute)

Example 4 with ILasHeader

use of org.hortonmachine.gears.io.las.core.ILasHeader in project hortonmachine by TheHortonMachine.

the class LasShapeVectorizer method process.

@Execute
public void process() throws Exception {
    checkNull(inLas);
    CoordinateReferenceSystem crs = null;
    double west = Double.POSITIVE_INFINITY;
    double south = Double.POSITIVE_INFINITY;
    double east = Double.NEGATIVE_INFINITY;
    double north = Double.NEGATIVE_INFINITY;
    // check the real minimum bounds
    pm.beginTask("Reading real bounds...", IHMProgressMonitor.UNKNOWN);
    long recordsCount = 0;
    try (ALasReader reader = ALasReader.getReader(new File(inLas), null)) {
        reader.open();
        ILasHeader header = reader.getHeader();
        crs = header.getCrs();
        recordsCount = header.getRecordsCount();
        while (reader.hasNextPoint()) {
            LasRecord dot = reader.getNextPoint();
            west = Math.min(west, dot.x);
            south = Math.min(south, dot.y);
            east = Math.max(east, dot.x);
            north = Math.max(north, dot.y);
        }
    }
    pm.done();
    // buffer by one resolution
    north = north + pYres;
    south = south - pYres;
    west = west - pXres;
    east = east + pXres;
    int rows = (int) round((north - south) / pYres);
    int cols = (int) round((east - west) / pXres);
    // bounds snapped on grid
    east = west + cols * pXres;
    north = south + rows * pYres;
    final GridGeometry2D gridGeometry2D = CoverageUtilities.gridGeometryFromRegionValues(north, south, east, west, cols, rows, crs);
    RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(gridGeometry2D);
    final WritableRaster wr = CoverageUtilities.createWritableRaster(cols, rows, null, null, HMConstants.doubleNovalue);
    // now map the points on the raster
    pm.beginTask("Mapping points on raster...", (int) recordsCount);
    try (ALasReader reader = ALasReader.getReader(new File(inLas), null)) {
        reader.open();
        final Point gridPoint = new Point();
        while (reader.hasNextPoint()) {
            LasRecord dot = reader.getNextPoint();
            double dotZ = dot.z;
            Coordinate coordinate = new Coordinate(dot.x, dot.y, dotZ);
            CoverageUtilities.colRowFromCoordinate(coordinate, gridGeometry2D, gridPoint);
            wr.setSample(gridPoint.x, gridPoint.y, 0, 1);
            pm.worked(1);
        }
    }
    pm.done();
    GridCoverage2D gridCoverage2D = CoverageUtilities.buildCoverage("mapped", wr, regionMap, crs);
    OmsVectorizer vectorizer = new OmsVectorizer();
    vectorizer.inRaster = gridCoverage2D;
    vectorizer.pm = pm;
    vectorizer.process();
    SimpleFeatureCollection outVector = vectorizer.outVector;
    dumpVector(outVector, outShp);
}
Also used : GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) RegionMap(org.hortonmachine.gears.utils.RegionMap) Point(java.awt.Point) Point(java.awt.Point) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) Coordinate(org.locationtech.jts.geom.Coordinate) OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) WritableRaster(java.awt.image.WritableRaster) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) File(java.io.File) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader) Execute(oms3.annotations.Execute)

Example 5 with ILasHeader

use of org.hortonmachine.gears.io.las.core.ILasHeader in project hortonmachine by TheHortonMachine.

the class LasMerger method process.

@Execute
public void process() throws Exception {
    checkNull(inFolder, outLas);
    CoordinateReferenceSystem crs = null;
    File inFolderFile = new File(inFolder);
    File[] lasList = inFolderFile.listFiles(new FilenameFilter() {

        public boolean accept(File arg0, String arg1) {
            return arg1.toLowerCase().endsWith(".las");
        }
    });
    StringBuilder sb = new StringBuilder("Merging files:");
    for (File file : lasList) {
        sb.append("\n").append(file.getAbsolutePath());
    }
    pm.message(sb.toString());
    // create readers and calculate bounds
    List<ALasReader> readers = new ArrayList<ALasReader>();
    double xMin = Double.POSITIVE_INFINITY;
    double yMin = Double.POSITIVE_INFINITY;
    double zMin = Double.POSITIVE_INFINITY;
    double xMax = Double.NEGATIVE_INFINITY;
    double yMax = Double.NEGATIVE_INFINITY;
    double zMax = Double.NEGATIVE_INFINITY;
    int count = 0;
    for (File lasFile : lasList) {
        ALasReader reader = ALasReader.getReader(lasFile, crs);
        reader.open();
        ILasHeader header = reader.getHeader();
        long recordsNum = header.getRecordsCount();
        count = (int) (count + recordsNum);
        ReferencedEnvelope3D envelope = header.getDataEnvelope();
        xMin = min(xMin, envelope.getMinX());
        yMin = min(yMin, envelope.getMinY());
        zMin = min(zMin, envelope.getMinZ());
        xMax = max(xMax, envelope.getMaxX());
        yMax = max(yMax, envelope.getMaxY());
        zMax = max(zMax, envelope.getMaxZ());
        readers.add(reader);
    }
    File outFile = new File(outLas);
    ALasWriter writer = ALasWriter.getWriter(outFile, crs);
    writer.setBounds(xMin, xMax, yMin, yMax, zMin, zMax);
    writer.open();
    pm.beginTask("Merging...", count);
    for (ALasReader reader : readers) {
        while (reader.hasNextPoint()) {
            LasRecord readNextLasDot = reader.getNextPoint();
            writer.addPoint(readNextLasDot);
            pm.worked(1);
        }
        reader.close();
    }
    writer.close();
    pm.done();
}
Also used : ArrayList(java.util.ArrayList) FilenameFilter(java.io.FilenameFilter) ALasWriter(org.hortonmachine.gears.io.las.core.ALasWriter) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) File(java.io.File) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader) Execute(oms3.annotations.Execute)

Aggregations

ILasHeader (org.hortonmachine.gears.io.las.core.ILasHeader)30 File (java.io.File)25 ALasReader (org.hortonmachine.gears.io.las.core.ALasReader)21 LasRecord (org.hortonmachine.gears.io.las.core.LasRecord)21 Execute (oms3.annotations.Execute)17 ReferencedEnvelope3D (org.geotools.geometry.jts.ReferencedEnvelope3D)14 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)14 ALasWriter (org.hortonmachine.gears.io.las.core.ALasWriter)13 Envelope (org.locationtech.jts.geom.Envelope)10 ArrayList (java.util.ArrayList)9 Coordinate (org.locationtech.jts.geom.Coordinate)9 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)8 IOException (java.io.IOException)7 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)7 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)7 Geometry (org.locationtech.jts.geom.Geometry)6 Point (org.locationtech.jts.geom.Point)6 Polygon (org.locationtech.jts.geom.Polygon)6 List (java.util.List)5 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)5