Search in sources :

Example 1 with ReferencedEnvelope3D

use of org.geotools.geometry.jts.ReferencedEnvelope3D in project hortonmachine by TheHortonMachine.

the class LasInfoController method getHeaderInfo.

private List<String[]> getHeaderInfo(ILasHeader header) {
    List<String[]> headerInfoList = new ArrayList<>();
    headerInfoList.add(new String[] { "File signature", new String(header.getFileSignature()) });
    headerInfoList.add(new String[] { "File source ID", "" + header.getFileSourceID() });
    headerInfoList.add(new String[] { "Project ID - data 1", "" + header.getProjectID_GUIDData1() });
    headerInfoList.add(new String[] { "Project ID - data 2", "" + header.getProjectID_GUIDData2() });
    headerInfoList.add(new String[] { "Project ID - data 3", "" + header.getProjectID_GUIDData3() });
    headerInfoList.add(new String[] { "Project ID - data 4", new String(header.getProjectID_GUIDData4()) });
    headerInfoList.add(new String[] { "Version", header.getVersion() });
    headerInfoList.add(new String[] { "System identifier", new String(header.getSystemIdentifier()) });
    headerInfoList.add(new String[] { "Generating software", header.getGeneratingSoftware() });
    try {
        short fileCreationYear = (short) header.getFileCreationYear();
        short fileCreationDayOfYear = (short) header.getFileCreationDayOfYear();
        String dtString = " - nv - ";
        if (fileCreationYear != 0 && fileCreationDayOfYear != 0) {
            DateTime dateTime = new DateTime();
            dateTime = dateTime.withYear(fileCreationYear).withDayOfYear(fileCreationDayOfYear);
            dtString = dateTime.toString(LasUtils.dateTimeFormatterYYYYMMDD);
        }
        headerInfoList.add(new String[] { "File creation date", dtString });
    } catch (Exception e) {
        e.printStackTrace();
    }
    // 
    headerInfoList.add(new String[] { "Header size", "" + header.getHeaderSize() });
    // 
    headerInfoList.add(new String[] { "Offset to data", "" + header.getOffset() });
    // 
    headerInfoList.add(new String[] { "Variable length records", "" + header.getNumberOfVariableLengthRecords() });
    // 
    headerInfoList.add(new String[] { "Point data format ID (0-99 for spec)", "" + header.getPointDataRecordFormat() });
    // 
    headerInfoList.add(new String[] { "Number of point records", "" + header.getRecordsCount() });
    // 
    headerInfoList.add(new String[] { "Record length", "" + header.getRecordLength() });
    double[] xyzScale = header.getXYZScale();
    headerInfoList.add(new String[] { "Scale", xyzScale[0] + ", " + xyzScale[1] + ", " + xyzScale[2] });
    double[] xyzOffset = header.getXYZOffset();
    headerInfoList.add(new String[] { "Offset", xyzOffset[0] + ", " + xyzOffset[1] + ", " + xyzOffset[2] });
    ReferencedEnvelope3D dataEnvelope3D = header.getDataEnvelope();
    headerInfoList.add(new String[] { "X Range", dataEnvelope3D.getMinX() + ", " + dataEnvelope3D.getMaxX() });
    headerInfoList.add(new String[] { "Y Range", dataEnvelope3D.getMinY() + ", " + dataEnvelope3D.getMaxY() });
    headerInfoList.add(new String[] { "Z Range", dataEnvelope3D.getMinZ() + ", " + dataEnvelope3D.getMaxZ() });
    return headerInfoList;
}
Also used : ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) IOException(java.io.IOException)

Example 2 with ReferencedEnvelope3D

use of org.geotools.geometry.jts.ReferencedEnvelope3D 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 3 with ReferencedEnvelope3D

use of org.geotools.geometry.jts.ReferencedEnvelope3D in project hortonmachine by TheHortonMachine.

the class OmsPointCloudMaximaFinderStream method main.

public static void main(String[] args) throws Exception {
    String lasPath = "/media/hydrologis/LESTOPLUS/test_lidar_spatialite/las_aurina/uni_bz_44.las";
    String outPath = "/home/hydrologis/TMP/tops_2m.asc";
    OmsPointCloudMaximaFinderStream s = new OmsPointCloudMaximaFinderStream();
    List<LasRecord> dotList = new ArrayList<>();
    try (ALasReader reader = ALasReader.getReader(new File(lasPath), null)) {
        reader.open();
        while (reader.hasNextPoint()) {
            LasRecord dot = (LasRecord) reader.getNextPoint();
            dotList.add(dot);
        }
        s.inLas = dotList;
        ReferencedEnvelope3D dataEnvelope = reader.getHeader().getDataEnvelope();
        s.aoi = new ReferencedEnvelope(dataEnvelope);
        s.pBaseGridResolution = 0.5;
        s.pMaxRadius = 2;
        s.process();
        OmsRasterWriter.writeRaster(outPath, s.outCoverage);
    }
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) ArrayList(java.util.ArrayList) File(java.io.File) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader)

Example 4 with ReferencedEnvelope3D

use of org.geotools.geometry.jts.ReferencedEnvelope3D 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)

Example 5 with ReferencedEnvelope3D

use of org.geotools.geometry.jts.ReferencedEnvelope3D in project hortonmachine by TheHortonMachine.

the class LasSplitter method process.

@SuppressWarnings("unchecked")
@Execute
public void process() throws Exception {
    checkNull(inFile);
    File inLas = new File(inFile);
    String lasName = FileUtilities.getNameWithoutExtention(inLas);
    try (ALasReader reader = ALasReader.getReader(inLas, null)) {
        reader.open();
        ILasHeader header = reader.getHeader();
        long recordsNum = header.getRecordsCount();
        double[] xyzScale = header.getXYZScale();
        double[] xyzOffset = header.getXYZOffset();
        ReferencedEnvelope3D env = header.getDataEnvelope();
        double[] xRange = NumericsUtilities.range2Bins(env.getMinX(), env.getMaxX(), pCols);
        double[] yRange = NumericsUtilities.range2Bins(env.getMinY(), env.getMaxY(), pRows);
        STRtree envelopeTree = new STRtree();
        HashMap<Envelope, ALasWriter> env2LaswriterMap = new HashMap<>();
        int fileCount = 1;
        for (int x = 0; x < xRange.length - 1; x++) {
            double minX = xRange[x];
            double maxX = xRange[x + 1];
            for (int y = 0; y < yRange.length - 1; y++) {
                double minY = yRange[y];
                double maxY = yRange[y + 1];
                Envelope envelope = new Envelope(new Coordinate(minX, minY), new Coordinate(maxX, maxY));
                File outLasPiece = new File(inLas.getParentFile(), lasName + "_" + fileCount + ".las");
                ALasWriter writer = ALasWriter.getWriter(outLasPiece, env.getCoordinateReferenceSystem());
                writer.setOffset(xyzOffset[0], xyzOffset[1], xyzOffset[2]);
                writer.setScales(xyzScale[0], xyzScale[1], xyzScale[2]);
                writer.setBounds(minX, maxX, minY, maxY, env.getMinZ(), env.getMaxZ());
                writer.open();
                envelopeTree.insert(envelope, writer);
                env2LaswriterMap.put(envelope, writer);
                fileCount++;
            }
        }
        pm.beginTask("Split file...", (int) recordsNum);
        while (reader.hasNextPoint()) {
            LasRecord dot = reader.getNextPoint();
            Coordinate coord = new Coordinate(dot.x, dot.y);
            List<ALasWriter> result = envelopeTree.query(new Envelope(coord));
            int size = result.size();
            if (size == 0) {
                continue;
            }
            ALasWriter aLasWriter = result.get(0);
            aLasWriter.addPoint(dot);
            pm.worked(1);
        }
        pm.done();
        for (ALasWriter writer : env2LaswriterMap.values()) {
            writer.close();
        }
    }
}
Also used : HashMap(java.util.HashMap) Envelope(org.locationtech.jts.geom.Envelope) ALasWriter(org.hortonmachine.gears.io.las.core.ALasWriter) Coordinate(org.locationtech.jts.geom.Coordinate) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) ILasHeader(org.hortonmachine.gears.io.las.core.ILasHeader) STRtree(org.locationtech.jts.index.strtree.STRtree) File(java.io.File) ALasReader(org.hortonmachine.gears.io.las.core.ALasReader) Execute(oms3.annotations.Execute)

Aggregations

ReferencedEnvelope3D (org.geotools.geometry.jts.ReferencedEnvelope3D)26 File (java.io.File)15 ALasReader (org.hortonmachine.gears.io.las.core.ALasReader)14 ILasHeader (org.hortonmachine.gears.io.las.core.ILasHeader)13 LasRecord (org.hortonmachine.gears.io.las.core.LasRecord)12 ArrayList (java.util.ArrayList)11 Execute (oms3.annotations.Execute)11 Polygon (org.locationtech.jts.geom.Polygon)11 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)7 Envelope (org.locationtech.jts.geom.Envelope)7 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)6 ALasWriter (org.hortonmachine.gears.io.las.core.ALasWriter)6 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)5 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)4 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)4 Envelope2D (org.geotools.geometry.Envelope2D)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4