org.geotools.coverage.grid.GridCoverage2D Java Examples
The following examples show how to use
org.geotools.coverage.grid.GridCoverage2D.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRasterNormalizer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testCutout() throws Exception { OmsRasterNormalizer cutout = new OmsRasterNormalizer(); cutout.pm = pm; cutout.inRaster = inCoverage; cutout.doSetnovalues = true; cutout.pNValue = 1.0; cutout.process(); GridCoverage2D out = cutout.outRaster; double[][] expected = new double[][]{// /* */{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // {0.0, 0.0, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.0}, // {0.0, 0.7, 0.6, 0.6, 0.6, 0.6, 0.6, 0.7, 0.7, 0.0},// {0.0, 1.0, 0.5, 0.7, 0.6, 0.6, 0.6, 0.6, 0.5, 0.0}, // {0.0, 0.3, 0.4, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0}, // {0.0, 0.2, 0.3, 0.3, 0.4, 0.4, 0.4, 0.3, 0.3, 0.0}, // {0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.5, 0.4, 0.4, 0.0}, // {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}; checkMatrixEqual(out.getRenderedImage(), expected, DELTA); }
Example #2
Source File: TestRasterFormats.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testTiff() throws Exception { File file = getFile("formats/tiff/test.tif"); GridCoverage2D raster = OmsRasterReader.readRaster(file.getAbsolutePath()); RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(raster); Double novalue = CoverageUtilities.getNovalue(raster); assertNull(novalue); assertEquals(30, regionMap.getCols()); assertEquals(26, regionMap.getRows()); assertEquals(7874.0, regionMap.getXres()); assertEquals(8120.769230769229580, regionMap.getYres(), DELTA); assertEquals(688054.25, regionMap.getWest()); assertEquals(5472037.36448598, regionMap.getSouth(), DELTA); CoordinateReferenceSystem crs = raster.getCoordinateReferenceSystem(); String epsg = CrsUtilities.getCodeFromCrs(crs); assertEquals("EPSG:26921", epsg); }
Example #3
Source File: TestAspect.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testAspectRadiants() throws Exception { double[][] pitData = HMTestMaps.pitData; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D pitCoverage = CoverageUtilities.buildCoverage("pit", pitData, envelopeParams, crs, true); OmsAspect aspect = new OmsAspect(); aspect.inElev = pitCoverage; aspect.doRadiants = true; aspect.pm = pm; aspect.process(); GridCoverage2D aspectCoverage = aspect.outAspect; checkMatrixEqual(aspectCoverage.getRenderedImage(), HMTestMaps.aspectDataRadiants, 0.01); }
Example #4
Source File: TestDrainDir.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testDrain() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] pitfillerData = HMTestMaps.pitData; GridCoverage2D pitfillerCoverage = CoverageUtilities.buildCoverage("pitfiller", pitfillerData, envelopeParams, crs, true); double[][] flowData = HMTestMaps.flowData; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); OmsDrainDir drainDir = new OmsDrainDir(); // drainDir.doLad = false; drainDir.pLambda = 1; drainDir.inPit = pitfillerCoverage; drainDir.inFlow = flowCoverage; drainDir.pm = pm; drainDir.process(); GridCoverage2D draindirCoverage = drainDir.outFlow; GridCoverage2D tcaCoverage = drainDir.outTca; checkMatrixEqual(draindirCoverage.getRenderedImage(), HMTestMaps.drainData1); checkMatrixEqual(tcaCoverage.getRenderedImage(), HMTestMaps.mtcaData); }
Example #5
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Get the array of region parameters covered by the {@link GridCoverage2D coverage}. * * @param gridCoverage the coverage. * @return the array of region parameters as [n, s, w, e, xres, yres, cols, rows] */ public static double[] getRegionArrayFromGridCoverage( GridCoverage2D gridCoverage ) { Envelope envelope = gridCoverage.getEnvelope(); DirectPosition lowerCorner = envelope.getLowerCorner(); double[] westSouth = lowerCorner.getCoordinate(); DirectPosition upperCorner = envelope.getUpperCorner(); double[] eastNorth = upperCorner.getCoordinate(); GridGeometry2D gridGeometry = gridCoverage.getGridGeometry(); GridEnvelope2D gridRange = gridGeometry.getGridRange2D(); int height = gridRange.height; int width = gridRange.width; AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS(); double xRes = XAffineTransform.getScaleX0(gridToCRS); double yRes = XAffineTransform.getScaleY0(gridToCRS); double[] params = new double[]{eastNorth[1], westSouth[1], westSouth[0], eastNorth[0], xRes, yRes, width, height}; return params; }
Example #6
Source File: TestRasterHoleFiller.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testHoleFiller() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D inCoverage = CoverageUtilities.buildCoverage("data", data, envelopeParams, crs, true); OmsHoleFiller transformer = new OmsHoleFiller(); transformer.inRaster = inCoverage; transformer.pMode = Variables.IDW; transformer.pBuffer = 10000; transformer.process(); GridCoverage2D outCoverage = transformer.outRaster; double[][] expected = new double[][]{// /* */{5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0}, // {5.0, 5.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 5.0}, // {5.0, 7.0, 6.0, 6.0, 6.0, 6.0, 6.0, 7.0, 7.0, 5.0}, // {5.0, 5.0, 5.0, 7.0, 6.0, 6.0, 6.0, 6.0, 5.0, 5.0}, // {5.0, 4.6000000000000005, 4.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0}, // {5.0, 4.32, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 5.0}, // {5.0, 4.553333333333334, 4.0, 4.0, 4.0, 4.0, 5.0, 4.0, 4.0, 5.0}, // {5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0} // }; RenderedImage renderedImage = outCoverage.getRenderedImage(); checkMatrixEqual(renderedImage, expected); }
Example #7
Source File: TestRasterReprojector.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testRasterReprojector() throws Exception { double[][] inData = HMTestMaps.mapData; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D inCoverage = CoverageUtilities.buildCoverage("data", inData, envelopeParams, crs, true); OmsRasterReprojector reprojector = new OmsRasterReprojector(); reprojector.inRaster = inCoverage; reprojector.pCode = "EPSG:4326"; reprojector.process(); GridCoverage2D outGeodata = reprojector.outRaster; reprojector = new OmsRasterReprojector(); reprojector.inRaster = outGeodata; reprojector.pCode = "EPSG:32632"; reprojector.process(); outGeodata = reprojector.outRaster; checkMatrixEqual(outGeodata.getRenderedImage(), HMTestMaps.mapData); }
Example #8
Source File: TestFlowUtils.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
protected void setUp() throws Exception { double[][] mapData = HMTestMaps.mapData; double[][] flowData = HMTestMaps.flowData; CoordinateReferenceSystem crs = HMTestMaps.getCrs(); HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); GridCoverage2D inElev = CoverageUtilities.buildCoverage("elevation", mapData, envelopeParams, crs, true); GridCoverage2D inFlow = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev); nCols = regionMap.getCols(); nRows = regionMap.getRows(); xRes = regionMap.getXres(); yRes = regionMap.getYres(); elevationIter = CoverageUtilities.getRandomIterator(inElev); flowIter = CoverageUtilities.getRandomIterator(inFlow); }
Example #9
Source File: Mapcalc.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Execute public void process() throws Exception { OmsMapcalc mapcalc = new OmsMapcalc(); List<GridCoverage2D> coverages = new ArrayList<GridCoverage2D>(); addRaster(coverages, inRaster1); addRaster(coverages, inRaster2); addRaster(coverages, inRaster3); addRaster(coverages, inRaster4); addRaster(coverages, inRaster5); addRaster(coverages, inRaster6); addRaster(coverages, inRaster7); addRaster(coverages, inRaster8); addRaster(coverages, inRaster9); addRaster(coverages, inRaster10); addRaster(coverages, inRaster11); addRaster(coverages, inRaster12); addRaster(coverages, inRaster13); addRaster(coverages, inRaster14); mapcalc.inRasters = coverages; mapcalc.pFunction = pFunction; mapcalc.pm = pm; mapcalc.process(); dumpRaster(mapcalc.outRaster, outRaster); }
Example #10
Source File: LasFileDataManager.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Constructor. * * @param lasFile the las folder index file. * @param inDem a dem to normalize the elevation. If <code>null</code>, the original las elevation is used. * @param elevThreshold a threshold to use for the elevation normalization. * @param inCrs the data {@link org.opengis.referencing.crs.CoordinateReferenceSystem}. if null, the one of the dem is read, if available. */ LasFileDataManager( File lasFile, GridCoverage2D inDem, double elevThreshold, CoordinateReferenceSystem inCrs ) { this.lasFile = lasFile; this.inDem = inDem; this.elevThreshold = elevThreshold; fileNamesList.add(lasFile.getName()); try { // prj file rules if available inCrs = CrsUtilities.readProjectionFile(lasFile.getAbsolutePath(), "las"); } catch (Exception e) { // ignore and try to read } if (inCrs != null) { crs = inCrs; } else if (inDem != null) { crs = inDem.getCoordinateReferenceSystem(); } else { throw new IllegalArgumentException("The Crs can't be null."); } }
Example #11
Source File: TestCoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testLos() throws Exception { double[][] elevationData = HMTestMaps.mapData; RegionMap eP = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D elevationCoverage = CoverageUtilities.buildCoverage("elevation", elevationData, eP, crs, true); Coordinate c1 = new Coordinate(west + xres / 2.0, north - yres / 2.0); Coordinate c2 = new Coordinate(east - xres / 2.0, north - yres / 2.0); List<ProfilePoint> profile = CoverageUtilities.doProfile(elevationCoverage, c1, c2); double[] losData = ProfilePoint.getLastVisiblePointData(profile); double[] expected = {1200.0, 1640785.0, 5140005.0, 120.0, 16.69924423399362, 1000.0, 1640755.0, 5140005.0, 90.0, 24.22774531795417}; for( int i = 0; i < expected.length; i++ ) { assertEquals(expected[i], losData[i], DELTA); } }
Example #12
Source File: TestGradient.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testGradient() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] pitData = HMTestMaps.pitData; GridCoverage2D pitfillerCoverage = CoverageUtilities.buildCoverage("elevation", pitData, envelopeParams, crs, true); OmsGradient gradient = new OmsGradient(); gradient.inElev = pitfillerCoverage; gradient.pm = pm; gradient.process(); GridCoverage2D gradientCoverage = gradient.outSlope; checkMatrixEqual(gradientCoverage.getRenderedImage(), HMTestMaps.gradientData, 0.01); }
Example #13
Source File: RasterDataAdapter.java From geowave with Apache License 2.0 | 6 votes |
public RasterDataAdapter( final String coverageName, final Map<String, String> metadata, final GridCoverage2D originalGridCoverage, final int tileSize, final boolean buildPyramid, final boolean buildHistogram, final double[][] noDataValuesPerBand) { this( coverageName, metadata, originalGridCoverage, tileSize, buildPyramid, buildHistogram, noDataValuesPerBand, new NoDataMergeStrategy()); }
Example #14
Source File: TestRasterResolutionResampler.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testRasterResolutionResampler() throws Exception { double[][] flowData = HMTestMaps.flowData; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); OmsRasterResolutionResampler transformer = new OmsRasterResolutionResampler(); transformer.inGeodata = flowCoverage; transformer.pInterpolation = Variables.NEAREST_NEIGHTBOUR; transformer.pXres = 60.0; transformer.pYres = 60.0; transformer.process(); GridCoverage2D outCoverage = transformer.outGeodata; double value = CoverageUtilities.getValue(outCoverage, 1, 1); assertEquals(7.0, value, 0.000000001); }
Example #15
Source File: OmsCoverageLister.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Execute public void process() throws Exception { outGC = new ArrayList<GridCoverage2D>(); for( String file : inFiles ) { OmsRasterReader reader = new OmsRasterReader(); reader.file = file; reader.fileNovalue = fileNovalue; reader.geodataNovalue = geodataNovalue; reader.pNorth = pNorth; reader.pSouth = pSouth; reader.pWest = pWest; reader.pEast = pEast; reader.pXres = pXres; reader.pYres = pYres; reader.pRows = pRows; reader.pCols = pCols; reader.process(); outGC.add(reader.outRaster); } }
Example #16
Source File: TestRasterNull.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testRasterNull2() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D inCoverage = CoverageUtilities.buildCoverage("data", data, envelopeParams, crs, true); OmsRasterNull transformer = new OmsRasterNull(); transformer.inRaster = inCoverage; transformer.pValue = 4.0; transformer.pNull = 1.0; transformer.process(); GridCoverage2D outCoverage = transformer.outRaster; double[][] expected2 = new double[][]{// /* */{5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0}, // {5.0, 5.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 5.0}, // {5.0, 7.0, 6.0, 6.0, 6.0, 6.0, 6.0, 7.0, 7.0, 5.0}, // {5.0, 5.0, 5.0, 7.0, 6.0, 6.0, 6.0, 6.0, 5.0, 5.0}, // {5.0, 3.0, 1.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0}, // {5.0, 2.0, 3.0, 3.0, 1.0, 1.0, 1.0, 3.0, 3.0, 5.0}, // {5.0, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 1.0, 1.0, 5.0}, // {5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0} // }; checkMatrixEqual(outCoverage.getRenderedImage(), expected2); }
Example #17
Source File: TestNetDif.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testNetDif() { double[][] flowData = HMTestMaps.flowData; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); double[][] strahlerData = HMTestMaps.strahlerData; GridCoverage2D strahlerCoverage = CoverageUtilities.buildCoverage("net", strahlerData, envelopeParams, crs, true); double[][] pitfillerData = HMTestMaps.pitData; GridCoverage2D pitfillerCoverage = CoverageUtilities.buildCoverage("pit", pitfillerData, envelopeParams, crs, true); OmsNetDiff netDif = new OmsNetDiff(); netDif.inFlow = flowCoverage; netDif.inStream = strahlerCoverage; netDif.inRaster = pitfillerCoverage; netDif.process(); GridCoverage2D netDifCoverage = netDif.outDiff; checkMatrixEqual(netDifCoverage.getRenderedImage(), HMTestMaps.diff_forPit); }
Example #18
Source File: TestHillshade.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testHillshade() throws Exception { double[][] elevationData = HMTestMaps.mapData; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs3004(); GridCoverage2D elevationCoverage = CoverageUtilities.buildCoverage("elevation", elevationData, envelopeParams, crs, true); OmsHillshade hillshade = new OmsHillshade(); hillshade.inElev = elevationCoverage; hillshade.pElev = 45.0; hillshade.pAzimuth = 315; hillshade.pm = pm; hillshade.process(); GridCoverage2D hillshadeCoverage = hillshade.outHill; checkMatrixEqual(hillshadeCoverage.getRenderedImage(), HMTestMaps.outHillshade, 0.1); }
Example #19
Source File: TestMorpher.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testPrune() throws Exception { OmsMorpher morpher = new OmsMorpher(); morpher.inMap = skeleton; morpher.pMode = Variables.PRUNE; morpher.pIterations = 1; morpher.process(); GridCoverage2D morphed = morpher.outMap; double[][] pruned = new double[][]{// /* */{NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, 1.0, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, // {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN} // }; checkMatrixEqual(morphed.getRenderedImage(), pruned, DELTA); }
Example #20
Source File: RasterDataAdapter.java From geowave with Apache License 2.0 | 6 votes |
public RasterDataAdapter( final String coverageName, final Map<String, String> metadata, final GridCoverage2D originalGridCoverage, final int tileSize, final boolean buildPyramid) { this( coverageName, metadata, originalGridCoverage, tileSize, buildPyramid, DEFAULT_BUILD_HISTOGRAM, new double[originalGridCoverage.getNumSampleDimensions()][], new NoDataMergeStrategy()); }
Example #21
Source File: TestAb.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testAb() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] tcaData = HMTestMaps.tcaData; GridCoverage2D tcaCoverage = CoverageUtilities.buildCoverage("tca", tcaData, envelopeParams, crs, true); double[][] planData = HMTestMaps.planData; GridCoverage2D planCoverage = CoverageUtilities.buildCoverage("plan", planData, envelopeParams, crs, true); OmsAb ab = new OmsAb(); ab.inTca = tcaCoverage; ab.inPlan = planCoverage; ab.pm = pm; ab.process(); GridCoverage2D alungCoverage = ab.outAb; GridCoverage2D bCoverage = ab.outB; checkMatrixEqual(alungCoverage.getRenderedImage(), HMTestMaps.abData, 0.01); checkMatrixEqual(bCoverage.getRenderedImage(), HMTestMaps.bData, 0.01); }
Example #22
Source File: TestTca.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testNewTca() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] flowData = HMTestMaps.flowData; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); OmsTca tca = new OmsTca(); tca.inFlow = flowCoverage; tca.pm = pm; tca.process(); GridCoverage2D tcaCoverage = tca.outTca; // PrintUtilities.printCoverageData(tcaCoverage); checkMatrixEqual(tcaCoverage.getRenderedImage(), HMTestMaps.tcaData); }
Example #23
Source File: TestRescaledDistance.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void testRescaledDistance() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] flowData = HMTestMaps.flowData; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); double[][] netData = HMTestMaps.extractNet0Data; GridCoverage2D netCoverage = CoverageUtilities.buildCoverage("net", netData, envelopeParams, crs, true); OmsRescaledDistance rescaledDistance = new OmsRescaledDistance(); rescaledDistance.inFlow = flowCoverage; rescaledDistance.inNet = netCoverage; rescaledDistance.pRatio = 0.3f; rescaledDistance.pm = pm; rescaledDistance.process(); GridCoverage2D rescaledDistanceCoverage = rescaledDistance.outRescaled; checkMatrixEqual(rescaledDistanceCoverage.getRenderedImage(), HMTestMaps.rescaledDistanceData, 0.1); }
Example #24
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Get the novalue defined for the raster. * * @param raster * @return the novalue or null if none defined. */ public static Double getNovalue( GridCoverage2D raster ) { Map< ? , ? > properties = raster.getProperties(); if (properties != null) { Object object = properties.get(NoDataContainer.GC_NODATA); if (object instanceof NoDataContainer) { NoDataContainer nodataContainer = (NoDataContainer) object; double noValue = nodataContainer.getAsSingleValue(); return noValue; } } return null; }
Example #25
Source File: OmsRasterVectorIntersector.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Execute public void process() throws Exception { checkNull(inRaster, inVector); SimpleFeatureType schema = inVector.getSchema(); if (!EGeometryType.isPolygon(schema.getGeometryDescriptor())) { throw new ModelsRuntimeException("The module works only with polygon vectors.", this); } RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster); OmsScanLineRasterizer raster = new OmsScanLineRasterizer(); raster.inVector = inVector; raster.pCols = regionMap.getCols(); raster.pRows = regionMap.getRows(); raster.pNorth = regionMap.getNorth(); raster.pSouth = regionMap.getSouth(); raster.pEast = regionMap.getEast(); raster.pWest = regionMap.getWest(); raster.pValue = 1.0; raster.process(); GridCoverage2D rasterizedVector = raster.outRaster; OmsCutOut cutout = new OmsCutOut(); cutout.pm = pm; cutout.inRaster = inRaster; cutout.inMask = rasterizedVector; cutout.doInverse = doInverse; cutout.process(); outRaster = cutout.outRaster; }
Example #26
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Helper function to run the Vectorize operation with given parameters and * retrieve the vectors. * * @param src the source {@link GridCoverage2D}. * @param args a {@code Map} of parameter names and values or <code>null</code>. * * @return the generated vectors as JTS Polygons */ @SuppressWarnings("unchecked") public static Collection<Polygon> doVectorize( GridCoverage2D src, Map<String, Object> args ) { if (args == null) { args = new HashMap<String, Object>(); } ParameterBlockJAI pb = new ParameterBlockJAI("Vectorize"); pb.setSource("source0", src.getRenderedImage()); // Set any parameters that were passed in for( Entry<String, Object> e : args.entrySet() ) { pb.setParameter(e.getKey(), e.getValue()); } // Get the desintation image: this is the unmodified source image data // plus a property for the generated vectors RenderedOp dest = JAI.create("Vectorize", pb); // Get the vectors Collection<Polygon> polygons = (Collection<Polygon>) dest.getProperty(VectorizeDescriptor.VECTOR_PROPERTY_NAME); RegionMap regionParams = CoverageUtilities.getRegionParamsFromGridCoverage(src); double xRes = regionParams.getXres(); double yRes = regionParams.getYres(); final AffineTransform mt2D = (AffineTransform) src.getGridGeometry().getGridToCRS2D(PixelOrientation.CENTER); final AffineTransformation jtsTransformation = new AffineTransformation(mt2D.getScaleX(), mt2D.getShearX(), mt2D.getTranslateX() - xRes / 2.0, mt2D.getShearY(), mt2D.getScaleY(), mt2D.getTranslateY() + yRes / 2.0); for( Polygon polygon : polygons ) { polygon.apply(jtsTransformation); } return polygons; }
Example #27
Source File: TestSumDownStream.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testSumDownstream() throws Exception { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] flowData = HMTestMaps.netFlowData; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); //$NON-NLS-1$ double[][] toSumData = HMTestMaps.netOneData; GridCoverage2D toSumCoverage = CoverageUtilities.buildCoverage("tosum", toSumData, envelopeParams, crs, true); //$NON-NLS-1$ OmsSumDownStream sumDownstream = new OmsSumDownStream(); sumDownstream.pm = pm; sumDownstream.inFlow = flowCoverage; sumDownstream.inToSum = toSumCoverage; sumDownstream.process(); GridCoverage2D summedCoverage = sumDownstream.outSummed; checkMatrixEqual(summedCoverage.getRenderedImage(), HMTestMaps.sumDownstreamData, 0.01); // with threshold double[][] toSumThresData = HMTestMaps.netOneThresData; GridCoverage2D toSumThresCoverage = CoverageUtilities.buildCoverage( "tosumthres", toSumThresData, envelopeParams, crs, true); //$NON-NLS-1$ sumDownstream = new OmsSumDownStream(); sumDownstream.pm = pm; sumDownstream.inFlow = flowCoverage; sumDownstream.inToSum = toSumThresCoverage; sumDownstream.pUpperThres = 2.0; sumDownstream.pLowerThres = 0.0; sumDownstream.process(); summedCoverage = sumDownstream.outSummed; printImage(summedCoverage.getRenderedImage()); checkMatrixEqual(summedCoverage.getRenderedImage(), HMTestMaps.sumDownstreamThresData, 0.01); }
Example #28
Source File: OmsRasterSummary.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static double[] getMinMaxAvgSum( GridCoverage2D raster ) throws Exception { OmsRasterSummary summary = new OmsRasterSummary(); summary.inRaster = raster; summary.doHistogram = false; summary.stats = new String[]{Variables.MIN, Variables.MAX, Variables.AVG, Variables.SUM}; summary.process(); double min = summary.outMin; double max = summary.outMax; double avg = summary.outMean; double sum = summary.outSum; return new double[]{min, max, avg, sum}; }
Example #29
Source File: TestDistanceToOutlet.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * test {@link OmsDistanceToOutlet} in the simple mode. * */ public void testDistanceToOutletMetere() { HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); double[][] flowData = HMTestMaps.mflowDataBorder; GridCoverage2D flowCoverage = CoverageUtilities.buildCoverage("flow", flowData, envelopeParams, crs, true); OmsDistanceToOutlet distanceToOutlet = new OmsDistanceToOutlet(); distanceToOutlet.inFlow = flowCoverage; distanceToOutlet.pMode = 0; distanceToOutlet.process(); GridCoverage2D distanceCoverage = distanceToOutlet.outDistance; checkMatrixEqual(distanceCoverage.getRenderedImage(), HMTestMaps.d2oMeterData, 0.01); }
Example #30
Source File: TestCutOut.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testCutoutInverseWithThresholds() throws Exception { OmsCutOut cutout = new OmsCutOut(); cutout.pm = pm; cutout.inRaster = inCoverage; cutout.inMask = inMask; cutout.doInverse = true; cutout.pMax = 1400.0; cutout.pMin = 800.0; cutout.process(); GridCoverage2D out = cutout.outRaster; checkMatrixEqual(out.getRenderedImage(), HMTestMaps.cutoutDataMaxMinInverse800_1400, 0); }