/** * walk through the latitude and find the edge of the scan * where the lat overlaps the previous lat. set _scanlineOffset */ private void calculateScanlineOffset() { // look at first pixel in each line int start = findStart(0); // if not found try end of line if(start == -1) { start = findStart(_latBand.getSceneRasterWidth() - 1); } if(start == -1) { // did not find an overlap _scanlineOffset = 0; } else { _scanlineOffset = start % _scanlineHeight; } }
/** * GuiTest_DialogAndModalDialog correct functionality for getBandOutputRasterWidth() */ public void testGetWidth() { assertEquals(50, _rsBandBlaByte5050.getSceneRasterWidth()); assertEquals(10, _rsBandBlubbUShort1010.getSceneRasterWidth()); assertEquals(20, _rsBandTestShort2020.getSceneRasterWidth()); assertEquals(15, _rsBandGnmpfInt1515.getSceneRasterWidth()); assertEquals(23, _rsBandBlimFloat2323.getSceneRasterWidth()); assertEquals(10, _rsBandZippFloat1005.getSceneRasterWidth()); assertEquals(100, _rsBandBlepDouble100100.getSceneRasterWidth()); }
private void copyBandRasterDataSubSampling(Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, int destWidth) { final int sourceMinY = sourceOffsetY; final int sourceMaxY = sourceOffsetY + sourceHeight - 1; int destPos = 0; for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) { // no subsampling in x-direction if (sourceStepX == 1) { copyData(sourceBand.getRasterData(), sourceY * sourceBand.getSceneRasterWidth() + sourceOffsetX, destBuffer, destPos, destWidth); } else { copyLine(sourceBand.getRasterData(), sourceY * sourceBand.getSceneRasterWidth() + sourceOffsetX, sourceWidth, sourceStepX, destBuffer, destPos); } destPos += destWidth; } }
@Override public Double getValueAt(int rowIndex, int columnIndex) { if (unableToFetchValues()) { return null; } final int centerOffset = MathUtils.floorInt(size / 2.0); int pixelX = centerPixelX - centerOffset + columnIndex; int pixelY = centerPixelY - centerOffset + rowIndex; if (band.isPixelValid(pixelX, pixelY)) { return ProductUtils.getGeophysicalSampleDouble(band, pixelX, pixelY, 0); } else { final Rectangle imageRectangle = new Rectangle(band.getSceneRasterWidth(), band.getSceneRasterHeight()); if (imageRectangle.contains(pixelX, pixelY)) { return Double.NaN; } return null; } }
private static void performBandTest(String filePath) throws IOException { Product product = ProductIO.readProduct(filePath); Band band0 = product.getBandAt(0); double[] times = computeStx(band0); System.out.println(product.getProductType()); System.out.println("band width : " + band0.getSceneRasterWidth()); System.out.println("band height: " + band0.getSceneRasterHeight()); System.out.println(); for (int i = 0; i < times.length; i++) { System.out.println("stx" + i + " : " + times[i]); } System.out.println(); }
/** * Adds the given band to this product. * * @param band the band to added, must not be <code>null</code> */ public void addBand(final Band band) { Guardian.assertNotNull("band", band); if (band.getSceneRasterWidth() != getSceneRasterWidth() || band.getSceneRasterHeight() != getSceneRasterHeight()) { throw new IllegalArgumentException("illegal raster dimensions"); } if (containsRasterDataNode(band.getName())) { throw new IllegalArgumentException("The Product '" + getName() + "' already contains " + "a band with the name '" + band.getName() + "'."); } bandGroup.add(band); }
private Rectangle findL3Rectangle(Rectangle l1Rectangle, Band srcBand) { PixelPos bottomLeft = new PixelPos(l1Rectangle.x, l1Rectangle.y); PixelPos l3PixelPos = l3GeoCoding.getPixelPos(l1GeoCoding.getGeoPos(bottomLeft, null), null); Rectangle l3Rectangle = new Rectangle(Math.round(l3PixelPos.x), Math.round(l3PixelPos.y), 1, 1); PixelPos bottomRight = new PixelPos(l1Rectangle.x + l1Rectangle.width, l1Rectangle.y); l3PixelPos = l3GeoCoding.getPixelPos(l1GeoCoding.getGeoPos(bottomRight, null), l3PixelPos); l3Rectangle.add(l3PixelPos.x, l3PixelPos.y); PixelPos topRight = new PixelPos(l1Rectangle.x + l1Rectangle.width, l1Rectangle.y + l1Rectangle.height); l3PixelPos = l3GeoCoding.getPixelPos(l1GeoCoding.getGeoPos(topRight, null), l3PixelPos); l3Rectangle.add(l3PixelPos.x, l3PixelPos.y); PixelPos topLeft = new PixelPos(l1Rectangle.x, l1Rectangle.y + l1Rectangle.height); l3PixelPos = l3GeoCoding.getPixelPos(l1GeoCoding.getGeoPos(topLeft, null), l3PixelPos); l3Rectangle.add(l3PixelPos.x, l3PixelPos.y); l3Rectangle.grow(2, 2); Rectangle sceneRectangle = new Rectangle(srcBand.getSceneRasterWidth(), srcBand.getSceneRasterHeight()); return l3Rectangle.intersection(sceneRectangle); }
private static ProductData createProductDataForBand(final Band band, final int start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemIntAt(i, start + i); } band.setData(data); return data; }
/** * {@inheritDoc} */ @Override public void readRasterDataFully(ProgressMonitor pm) throws IOException { final ProductData rasterData; if (hasRasterData()) { rasterData = getRasterData(); } else { rasterData = createCompatibleRasterData(getRasterWidth(), getRasterHeight()); } readRasterData(0, 0, getSceneRasterWidth(), getSceneRasterHeight(), rasterData, pm); setRasterData(rasterData); }
private static ProductData createProductDataForBand(final Band band, final float start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemFloatAt(i, start + i); } band.setData(data); return data; }
private static ProductData createProductDataForBand(final Band band, final double start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemDoubleAt(i, start + i); } band.setData(data); return data; }
private void fillBandWithData(final Band band, final int start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemIntAt(i, start + i); } band.setData(data); } }
private static ProductData createDataFor(Band dataBand) { final int width = dataBand.getSceneRasterWidth(); final int height = dataBand.getSceneRasterHeight(); final ProductData data = ProductData.createInstance(dataBand.getDataType(), width * height); for (int y = 0; y < height; y++) { final int line = y * width; for (int x = 0; x < width; x++) { data.setElemIntAt(line + x, x * y); } } return data; } }
private static ProductData createDataFor(Band dataBand) { final int width = dataBand.getSceneRasterWidth(); final int height = dataBand.getSceneRasterHeight(); final ProductData data = ProductData.createInstance(dataBand.getDataType(), width * height); for (int y = 0; y < height; y++) { final int line = y * width; for (int x = 0; x < width; x++) { data.setElemIntAt(line + x, x * y); } } return data; } }
private void setSourceImage(Band sourceBand) { final TiledImage sourceImage = new TiledImage(0, 0, sourceBand.getSceneRasterWidth(), sourceBand.getSceneRasterHeight(), 0, 0, new SingleBandedSampleModel(DataBuffer.TYPE_INT, sourceBand.getSceneRasterWidth(), sourceBand.getSceneRasterHeight()), null); sourceImage.setSample(0, 0, 0, 123); sourceImage.setSample(1, 1, 0, 234); sourceImage.setSample(2, 2, 0, 345); sourceImage.setSample(3, 3, 0, 456); sourceBand.setSourceImage(sourceImage); }
/** * Gets an estimated raw storage size in bytes of this product node. * * @param subsetDef if not <code>null</code> the subset may limit the size returned * @return the size in bytes. */ @Override public long getRawStorageSize(ProductSubsetDef subsetDef) { long size = 0L; if (isPartOfSubset(subsetDef)) { size += 256; // add estimated overhead of 256 bytes long numDataElems = getNumDataElems(); if (subsetDef != null) { long width = getSceneRasterWidth(); long height = getSceneRasterHeight(); Rectangle region = subsetDef.getRegion(); if (region != null) { width = region.width; height = region.height; } width /= 1 + subsetDef.getSubSamplingX(); height /= 1 + subsetDef.getSubSamplingY(); numDataElems = width * height; } size += ProductData.getElemSize(getDataType()) * numDataElems; } return size; }
private void addBandsToOutput(String description, boolean convertMerisName) { for (Band inBand : inputBandList) { String newBandName; String bandUnit; if (convertMerisName) { newBandName = convertMerisBandName(inBand.getName(), bandNameMapping); bandUnit = "dl"; } else { newBandName = inBand.getName(); bandUnit = inBand.getUnit(); } Band outBand = new Band(newBandName, inBand.getGeophysicalDataType(), inBand.getSceneRasterWidth(), inBand.getSceneRasterHeight()); outBand.setUnit(bandUnit); outBand.setDescription(description + inBand.getName()); ProductUtils.copySpectralBandProperties(inBand, outBand); targetProduct.addBand(outBand); } }
private Product writeReadProduct() throws IOException { final GeoTiffProductWriter writer = (GeoTiffProductWriter) new GeoTiffProductWriterPlugIn().createWriterInstance(); outProduct.setProductWriter(writer); writer.writeGeoTIFFProduct(new MemoryCacheImageOutputStream(outputStream), outProduct); final Band[] bands = outProduct.getBands(); for (Band band : bands) { if (writer.shouldWrite(band)) { band.readRasterDataFully(ProgressMonitor.NULL); writer.writeBandRasterData(band, 0, 0, band.getSceneRasterWidth(), band.getSceneRasterHeight(), band.getData(), ProgressMonitor.NULL); } } writer.flush(); ByteArraySeekableStream inputStream = new ByteArraySeekableStream(outputStream.toByteArray()); final Product product = reader.readGeoTIFFProduct(new MemoryCacheImageInputStream(inputStream), location); product.setProductReader(reader); return product; }
assertEquals(4, targetBand.getSceneRasterWidth()); assertEquals(4, targetBand.getSceneRasterHeight());
public void testWriteFlagCoding() throws Exception { Band flagBand = new Band("flag_band", ProductData.TYPE_UINT8, 10, 10); FlagCoding flagCoding = new FlagCoding("some_flags"); flagBand.setSampleCoding(flagCoding); flagCoding.setDescription("A Flag Coding"); for (int i = 0; i < 8; i++) { addFlag(flagCoding, i); } NetcdfFileWriteable writeable = NetcdfFileWriteable.createNew("not stored"); writeable.addDimension("y", flagBand.getSceneRasterHeight()); writeable.addDimension("x", flagBand.getSceneRasterWidth()); final DataType ncDataType = DataTypeUtils.getNetcdfDataType(flagBand.getDataType()); Variable variable = writeable.addVariable(flagBand.getName(), ncDataType, writeable.getRootGroup().getDimensions()); CfBandPart.writeCfBandAttributes(flagBand, new N3Variable(variable, writeable)); CfFlagCodingPart.writeFlagCoding(flagBand, new N3FileWriteable(writeable)); Variable someFlagsVariable = writeable.findVariable("flag_band"); assertNotNull(someFlagsVariable); Attribute flagMasksAttrib = someFlagsVariable.findAttribute("flag_masks"); assertNotNull(flagMasksAttrib); assertEquals(someFlagsVariable.getDataType(), flagMasksAttrib.getDataType()); assertEquals(8, flagMasksAttrib.getLength()); assertTrue(flagMasksAttrib.isUnsigned()); for (int i = 0; i < 8; i++) { assertEquals(1 << i, flagMasksAttrib.getValues().getInt(i)); } Attribute descriptionAttrib = someFlagsVariable.findAttribute("long_name"); assertNotNull(flagCoding.getDescription(), descriptionAttrib.getStringValue()); }