Search in sources :

Example 1 with OmsVectorizer

use of org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer in project hortonmachine by TheHortonMachine.

the class LasInfoController method findCircles.

public static List<Geometry> findCircles(GridCoverage2D inRaster, int pixelsThreshold) throws Exception {
    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
    int nCols = regionMap.getCols();
    int nRows = regionMap.getRows();
    RandomIter rasterIter = CoverageUtilities.getRandomIterator(inRaster);
    WritableRaster[] holder = new WritableRaster[1];
    GridCoverage2D outGC = CoverageUtilities.createCoverageFromTemplate(inRaster, HMConstants.doubleNovalue, holder);
    WritableRandomIter outIter = RandomIterFactory.createWritable(holder[0], null);
    for (int r = 0; r < nRows; r++) {
        for (int c = 0; c < nCols; c++) {
            double value = rasterIter.getSampleDouble(c, r, 0);
            if (value != 255) {
                outIter.setSample(c, r, 0, 1);
            } else {
                outIter.setSample(c, r, 0, -9999.0);
            }
        }
    }
    OmsVectorizer v = new OmsVectorizer();
    v.inRaster = outGC;
    v.doRemoveHoles = false;
    v.pThres = pixelsThreshold;
    v.pValue = 1.0;
    v.process();
    SimpleFeatureCollection outVector = v.outVector;
    List<SimpleFeature> featuresList = FeatureUtilities.featureCollectionToList(outVector).stream().filter(f -> {
        Object attribute = f.getAttribute(v.fDefault);
        if (attribute instanceof Number) {
            double value = ((Number) attribute).doubleValue();
            if (value != -9999.0) {
                Geometry geom = (Geometry) f.getDefaultGeometry();
                // assume no centroid intersection
                Point centroid = geom.getCentroid();
                Envelope env = geom.getEnvelopeInternal();
                double buffer = env.getWidth() * 0.01;
                Geometry centroidB = centroid.buffer(buffer);
                if (geom.intersects(centroidB)) {
                    return false;
                }
                return true;
            }
        }
        return false;
    }).collect(Collectors.toList());
    // DefaultFeatureCollection fc = new DefaultFeatureCollection();
    // fc.addAll(featuresList);
    // HMMapframe mf = HMMapframe.openFrame(false);
    // mf.addLayer(fc);
    List<Geometry> geomsList = featuresList.stream().map(f -> {
        Geometry geom = (Geometry) f.getDefaultGeometry();
        Envelope env = geom.getEnvelopeInternal();
        Coordinate centre = env.centre();
        Point centerPoint = GeometryUtilities.gf().createPoint(centre);
        double width = env.getWidth();
        double height = env.getHeight();
        double radius = Math.max(width, height) / 2.0;
        Geometry finalBuffer = centerPoint.buffer(radius);
        return finalBuffer;
    }).collect(Collectors.toList());
    return geomsList;
}
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) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) RegionMap(org.hortonmachine.gears.utils.RegionMap) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) Point(org.locationtech.jts.geom.Point) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) Point(org.locationtech.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(org.locationtech.jts.geom.Geometry) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) Coordinate(org.locationtech.jts.geom.Coordinate) WritableRaster(java.awt.image.WritableRaster)

Example 2 with OmsVectorizer

use of org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer 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 3 with OmsVectorizer

use of org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer in project hortonmachine by TheHortonMachine.

the class Vectorizer method process.

@Execute
public void process() throws Exception {
    OmsVectorizer vectorizer = new OmsVectorizer();
    vectorizer.inRaster = getRaster(inRaster);
    vectorizer.pValue = pValue;
    vectorizer.fDefault = fDefault;
    vectorizer.pThres = pThres;
    vectorizer.doRegioncheck = doRegioncheck;
    vectorizer.pm = pm;
    vectorizer.doProcess = doProcess;
    vectorizer.doReset = doReset;
    vectorizer.process();
    dumpVector(vectorizer.outVector, outVector);
}
Also used : OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) Execute(oms3.annotations.Execute)

Example 4 with OmsVectorizer

use of org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer in project hortonmachine by TheHortonMachine.

the class OmsBasinShape method process.

@Execute
public void process() throws Exception {
    if (!concatOr(outBasins == null, doReset)) {
        return;
    }
    checkNull(inBasins);
    HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inBasins);
    nCols = regionMap.get(CoverageUtilities.COLS).intValue();
    nRows = regionMap.get(CoverageUtilities.ROWS).intValue();
    // double xRes = regionMap.get(CoverageUtilities.XRES);
    // double yRes = regionMap.get(CoverageUtilities.YRES);
    RenderedImage basinsRI = inBasins.getRenderedImage();
    RenderedImage pitRI = null;
    if (inElev != null)
        pitRI = inElev.getRenderedImage();
    int[] nstream = new int[1];
    // nstream[0] = 1508;
    WritableRaster basinsWR = CoverageUtilities.renderedImage2WritableRaster(basinsRI, true);
    RandomIter basinsRandomIter = RandomIterFactory.create(basinsWR, null);
    for (int j = 0; j < nRows; j++) {
        for (int i = 0; i < nCols; i++) {
            if (!isNovalue(basinsRandomIter.getSampleDouble(i, j, 0)) && basinsRandomIter.getSampleDouble(i, j, 0) > (double) nstream[0]) {
                nstream[0] = (int) basinsRandomIter.getSampleDouble(i, j, 0);
            }
        }
    }
    WritableRaster subbasinsWR = CoverageUtilities.createWritableRaster(basinsRI.getWidth(), basinsRI.getHeight(), null, basinsRI.getSampleModel(), doubleNovalue);
    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    // set the name
    // $NON-NLS-1$
    b.setName("basinshape");
    // add a geometry property
    // $NON-NLS-1$
    String defaultGeometryName = "the_geom";
    b.setCRS(inBasins.getCoordinateReferenceSystem());
    b.add(defaultGeometryName, MultiPolygon.class);
    // add some properties
    // $NON-NLS-1$
    b.add("area", Float.class);
    // $NON-NLS-1$
    b.add("perimeter", Float.class);
    // $NON-NLS-1$
    b.add(NetworkChannel.NETNUMNAME, Integer.class);
    // $NON-NLS-1$
    b.add("maxelev", Float.class);
    // $NON-NLS-1$
    b.add("minelev", Float.class);
    // $NON-NLS-1$
    b.add("avgelev", Float.class);
    // $NON-NLS-1$
    b.add(NetworkChannel.BARICENTERELEVNAME, Float.class);
    // build the type
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    outBasins = new DefaultFeatureCollection();
    // for each stream correct problems with basins and create geometries
    pm.beginTask("Extracting basins...", nstream[0]);
    for (int num = 1; num <= nstream[0]; num++) {
        Object[] values = new Object[8];
        int nordRow = -1;
        int southRow = 0;
        int eastCol = -1;
        int westCol = nCols;
        int numPixel = 0;
        double minZ = Double.MAX_VALUE;
        double maxZ = Double.MIN_VALUE;
        double averageZ = 0.0;
        if (pitRI != null)
            pitRandomIter = RandomIterFactory.create(pitRI, null);
        WritableRandomIter subbasinIter = RandomIterFactory.createWritable(subbasinsWR, null);
        for (int j = 0; j < nRows; j++) {
            for (int i = 0; i < nCols; i++) {
                double basinId = basinsRandomIter.getSampleDouble(i, j, 0);
                if (isNovalue(basinId)) {
                    continue;
                }
                int basinNum = (int) basinId;
                if (basinNum == num) {
                    if (nordRow == -1) {
                        nordRow = i;
                    }
                    if (i > nordRow) {
                        southRow = i;
                    }
                    if (westCol > j) {
                        westCol = j;
                    }
                    if (eastCol < j) {
                        eastCol = j;
                    }
                    subbasinIter.setSample(i, j, 0, basinNum);
                    if (pitRI != null) {
                        double elevation = pitRandomIter.getSampleDouble(i, j, 0);
                        if (!isNovalue(elevation)) {
                            minZ = elevation < minZ ? elevation : minZ;
                            maxZ = elevation > maxZ ? elevation : maxZ;
                            averageZ = averageZ + elevation;
                        } else {
                            minZ = -1;
                            maxZ = -1;
                            averageZ = 0;
                        }
                    }
                    numPixel++;
                }
            }
        }
        if (numPixel != 0) {
            // min, max and average
            values[3] = num;
            values[4] = maxZ;
            values[5] = minZ;
            values[6] = averageZ / numPixel;
            numPixel = 0;
            for (int i = nordRow; i < southRow + 1; i++) {
                for (int j = westCol; j < eastCol + 1; j++) {
                    if (isNovalue(subbasinIter.getSampleDouble(i, j, 0))) {
                        for (int k = 1; k <= 8; k++) {
                            // index.setFlow(k);
                            // index.getParameters()[
                            int indexI = i + ModelsSupporter.DIR[k][1];
                            // 0];
                            // index.getParameters()[
                            int indexJ = j + ModelsSupporter.DIR[k][0];
                            // 1];
                            if (!isNovalue(subbasinIter.getSampleDouble(indexI, indexJ, 0))) {
                                numPixel++;
                            }
                            k++;
                        }
                        if (numPixel == 4) {
                            subbasinIter.setSample(i, j, 0, num);
                        }
                    }
                    numPixel = 0;
                }
            }
            // extract the feature polygon of that basin number
            OmsVectorizer vectorizer = new OmsVectorizer();
            try {
                vectorizer.inRaster = inBasins;
                vectorizer.pm = pm;
                vectorizer.doReset = true;
                vectorizer.pValue = (double) num;
                vectorizer.process();
            } catch (Exception e) {
                pm.errorMessage(e.getLocalizedMessage());
                continue;
            }
            SimpleFeatureCollection outGeodata = vectorizer.outVector;
            FeatureIterator<SimpleFeature> outGeodataIterator = outGeodata.features();
            List<Polygon> polygons = new ArrayList<Polygon>();
            while (outGeodataIterator.hasNext()) {
                SimpleFeature feature = outGeodataIterator.next();
                polygons.add((Polygon) feature.getDefaultGeometry());
            }
            outGeodataIterator.close();
            MultiPolygon geometry = GeometryUtilities.gf().createMultiPolygon((Polygon[]) polygons.toArray(new Polygon[polygons.size()]));
            values[0] = geometry;
            values[1] = geometry.getArea();
            values[2] = geometry.getLength();
            Point centroid = geometry.getCentroid();
            if (centroid == null || centroid.isEmpty()) {
                pm.errorMessage("Unable to extract basin: " + num);
                continue;
            }
            Coordinate centroidCoords = centroid.getCoordinate();
            GridGeometry2D gridGeometry = inBasins.getGridGeometry();
            GridCoordinates2D worldToGrid = gridGeometry.worldToGrid(new DirectPosition2D(centroidCoords.x, centroidCoords.y));
            int[] rowColPoint = new int[] { worldToGrid.y, worldToGrid.x };
            double centroidElevation = -1;
            ;
            if (pitRI != null) {
                double elev = pitRandomIter.getSampleDouble(rowColPoint[1], rowColPoint[0], 0);
                if (!isNovalue(elev)) {
                    centroidElevation = elev;
                }
            }
            values[7] = centroidElevation;
            subbasinIter.done();
            subbasinsWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, doubleNovalue);
            // add the values
            builder.addAll(values);
            // build the feature with provided ID
            SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + num);
            ((DefaultFeatureCollection) outBasins).add(feature);
        }
        pm.worked(1);
    }
    pm.done();
    basinsRandomIter.done();
    basinsWR = null;
}
Also used : GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) ArrayList(java.util.ArrayList) DirectPosition2D(org.geotools.geometry.DirectPosition2D) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Coordinate(org.locationtech.jts.geom.Coordinate) GridCoordinates2D(org.geotools.coverage.grid.GridCoordinates2D) RenderedImage(java.awt.image.RenderedImage) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Execute(oms3.annotations.Execute)

Example 5 with OmsVectorizer

use of org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer in project hortonmachine by TheHortonMachine.

the class TestVectorizer method testVectorizer2.

public void testVectorizer2() throws Exception {
    double[][] inData = HMTestMaps.extractNet0Data;
    HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams();
    CoordinateReferenceSystem crs = HMTestMaps.getCrs();
    GridCoverage2D inCoverage = CoverageUtilities.buildCoverage("data", inData, envelopeParams, crs, true);
    OmsVectorizer vectorizer = new OmsVectorizer();
    vectorizer.pm = pm;
    vectorizer.inRaster = inCoverage;
    vectorizer.pValue = null;
    vectorizer.pThres = 1;
    vectorizer.fDefault = "rast";
    vectorizer.process();
    SimpleFeatureCollection outGeodata = vectorizer.outVector;
    assertEquals(2, outGeodata.size());
    List<SimpleFeature> features = FeatureUtilities.featureCollectionToList(outGeodata);
    SimpleFeature f1 = features.get(0);
    SimpleFeature f2 = features.get(1);
    Geometry g1 = (Geometry) f1.getDefaultGeometry();
    Geometry g2 = (Geometry) f2.getDefaultGeometry();
    // SimpleFeature nvFeature = f1;
    SimpleFeature valuesFeature = f2;
    if (g1.getArea() < g2.getArea()) {
        // nvFeature = f2;
        valuesFeature = f1;
    }
    double value = ((Number) valuesFeature.getAttribute("rast")).doubleValue();
    assertEquals(2.0, value, 0.0000001);
    Geometry geometry = (Geometry) valuesFeature.getDefaultGeometry();
    double area = geometry.getArea();
    assertEquals(6300.0, area, 0.0000001);
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(org.locationtech.jts.geom.Geometry) OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

OmsVectorizer (org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer)8 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)7 Execute (oms3.annotations.Execute)5 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 WritableRaster (java.awt.image.WritableRaster)4 RegionMap (org.hortonmachine.gears.utils.RegionMap)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 RandomIter (javax.media.jai.iterator.RandomIter)3 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)3 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)3 LasRecord (org.hortonmachine.gears.io.las.core.LasRecord)3 Geometry (org.locationtech.jts.geom.Geometry)3 Polygon (org.locationtech.jts.geom.Polygon)3 WritableRandomIter (javax.media.jai.iterator.WritableRandomIter)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)2