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; } }
public Band getBand(String bandname, String username) { Band retB = null; try { PreparedStatement stmt = conn.prepareStatement( "select b.id, b.costs_per_hour from bands b join musicians m on b.leader_id = m.id where b.name = ? and m.username = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setString(1, bandname); stmt.setString(2, username); ResultSet rs = stmt.executeQuery(); while (rs.next()) { retB = new Band(); retB.setId(rs.getInt(1)); retB.setName(bandname); retB.setCostsPerHour(rs.getInt(2)); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return retB; }
public void deleteMember(Band band, String username) { try { PreparedStatement stmt = conn.prepareStatement( "delete from available_times where band_id = ? and musician_id = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, band.getId()); stmt.setInt(2, this.getMusicianIdFromName(username)); stmt.executeUpdate(); stmt = conn.prepareStatement( "delete from bandmembers where band_id = ? and musician_id = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, band.getId()); stmt.setInt(2, this.getMusicianIdFromName(username)); stmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private static void writedescription(PrintWriter out, RasterDataNode rasterDataNode) { assert rasterDataNode != null; String description = rasterDataNode.getDescription(); String unit = rasterDataNode.getUnit(); if (unit == null || unit.trim().length() == 0) { unit = "1"; } if (rasterDataNode.isLog10Scaled()) { unit = "log(" + unit + ")"; } unit = " - Unit: " + unit; String wavelength = ""; // String bandwidth = ""; if (rasterDataNode instanceof Band) { Band band = (Band) rasterDataNode; if (band.getSpectralWavelength() != 0.0) { wavelength = " - Wavelength: " + band.getSpectralWavelength() + "nm"; // bandwidth = " - Bandwidth: " + band.getSpectralBandwidth() + "nm"; } } if (description == null || description.trim().length() == 0) { description = rasterDataNode.getProduct().getDescription(); } out.println( "description = {" + description + unit + wavelength // + bandwidth + "}"); }
/** * The template method which is called by the <code>readBandRasterDataSubSampling</code> method * after an optional spatial subset has been applied to the input parameters. * * <p> * * <p>The destination band, buffer and region parameters are exactly the ones passed to the * original <code>readBandRasterDataSubSampling</code> call. Since the <code>destOffsetX</code> * and <code>destOffsetY</code> parameters are already taken into acount in the <code> * sourceOffsetX</code> and <code>sourceOffsetY</code> parameters, an implementor of this method * is free to ignore them. * * @param sourceOffsetX the absolute X-offset in source raster co-ordinates * @param sourceOffsetY the absolute Y-offset in source raster co-ordinates * @param sourceWidth the width of region providing samples to be read given in source raster * co-ordinates * @param sourceHeight the height of region providing samples to be read given in source raster * co-ordinates * @param sourceStepX the sub-sampling in X direction within the region providing samples to be * read * @param sourceStepY the sub-sampling in Y direction within the region providing samples to be * read * @param destBand the destination band which identifies the data source from which to read the * sample values * @param destBuffer the destination buffer which receives the sample values to be read * @param destOffsetX the X-offset in the band's raster co-ordinates * @param destOffsetY the Y-offset in the band's raster co-ordinates * @param destWidth the width of region to be read given in the band's raster co-ordinates * @param destHeight the height of region to be read given in the band's raster co-ordinates * @throws IOException if an I/O error occurs * @see #getSubsetDef */ @Override protected void readBandRasterDataImpl( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { Band sourceBand = (Band) bandMap.get(destBand); // if the band already has an internal raster if (sourceBand.getRasterData() != null) { // if the destination region equals the entire raster if (sourceBand.getSceneRasterWidth() == destWidth && sourceBand.getSceneRasterHeight() == destHeight) { copyBandRasterDataFully(sourceBand, destBuffer, destWidth, destHeight); // else if the destination region is smaller than the entire raster } else { copyBandRasterDataSubSampling( sourceBand, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, sourceStepX, sourceStepY, destBuffer, destWidth); } } else { // if the desired destination region equals the source raster if (sourceWidth == destWidth && sourceHeight == destHeight) { readBandRasterDataRegion( sourceBand, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, destBuffer, pm); // else if the desired destination region is smaller than the source raster } else { readBandRasterDataSubSampling( sourceBand, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, sourceStepX, sourceStepY, destBuffer, destWidth, pm); } } }
/** * Writes the wavelength value to the out stream if the given rasterDataNode is an instance of * <code>BAND</code> * * @param out - the tream to write to * @param rasterDataNode the <code>RasterDataNode</code> */ private static void writeWavelength(PrintWriter out, RasterDataNode rasterDataNode) { if (rasterDataNode instanceof Band) { final Band band = (Band) rasterDataNode; final float spectralWavelength = band.getSpectralWavelength(); if (spectralWavelength != 0) { out.println("wavelength = {" + spectralWavelength + "}"); } } }
public synchronized void readBandData( Band destBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException, InvalidRangeException { if (mustFlipY) { sourceOffsetY = destBand.getSceneRasterHeight() - (sourceOffsetY + sourceHeight); } if (mustFlipX) { sourceOffsetX = destBand.getSceneRasterWidth() - (sourceOffsetX + sourceWidth); } sourceOffsetY += leadLineSkip; start[0] = sourceOffsetY; start[1] = sourceOffsetX; stride[0] = sourceStepY; stride[1] = sourceStepX; count[0] = sourceHeight; count[1] = sourceWidth; Object buffer = destBuffer.getElems(); Variable variable = variableMap.get(destBand); pm.beginTask("Reading band '" + variable.getShortName() + "'...", sourceHeight); try { Section section = new Section(start, count, stride); Array array; int[] newshape = {sourceHeight, sourceWidth}; array = variable.read(section); if (array.getRank() == 3) { array = array.reshapeNoCopy(newshape); } Object storage; if (mustFlipX && !mustFlipY) { storage = array.flip(1).copyTo1DJavaArray(); } else if (!mustFlipX && mustFlipY) { storage = array.flip(0).copyTo1DJavaArray(); } else if (mustFlipX && mustFlipY) { storage = array.flip(0).flip(1).copyTo1DJavaArray(); } else { storage = array.copyTo1DJavaArray(); } arraycopy(storage, 0, buffer, 0, destBuffer.getNumElems()); } finally { pm.done(); } }
private static void setFlagCoding(Band band, FlagCoding flagCoding) { if (flagCoding != null) { final String flagCodingName = flagCoding.getName(); final Product product = band.getProduct(); if (!product.getFlagCodingGroup().contains(flagCodingName)) { addFlagCoding(product, flagCoding); } band.setSampleCoding(product.getFlagCodingGroup().get(flagCodingName)); } }
static Band createSubset(Band sourceBand, Scene targetScene, ProductSubsetDef subsetDef) { final Band targetBand = new Band( sourceBand.getName(), sourceBand.getDataType(), targetScene.getRasterWidth(), targetScene.getRasterHeight()); ProductUtils.copyRasterDataNodeProperties(sourceBand, targetBand); targetBand.setSourceImage(getSourceImage(subsetDef, sourceBand)); return targetBand; }
public Group(SubDataset parent, String name, int headerHeight, int footerHeight) { this.parent = parent; this.name = name; if (parent instanceof Report) { groupFooter = new Band((Report) parent, name + "Footer", headerHeight); groupFooter.setGroup(this); groupFooter.setGroupFooter(true); groupHeader = new Band((Report) parent, name + "Header", footerHeight); groupHeader.setGroup(this); groupHeader.setGroupHeader(true); } }
public static void main(String[] args) { MongoClient mongo = new MongoClient("localhost"); Datastore datastore = new Morphia().createDatastore(mongo, "bandmanager"); Band band = new Band(); band.setName("Love Burger"); band.setGenre("Rock"); // datastore.save(band); Query query = datastore.createQuery(Band.class).field("name").contains("urger"); Band cons = (Band) query.asList().get(0); System.out.println(cons); }
public void setParameter(int type, int value) { mCurrentBand.mask = false; switch (type) { case PARAM_BRIGHTNESS: mCurrentBand.brightness = value; break; case PARAM_SATURATION: mCurrentBand.saturation = value; break; case PARAM_CONTRAST: mCurrentBand.contrast = value; break; default: throw new IllegalArgumentException("no such type " + type); } }
public void updateBand(Band band) { try { PreparedStatement stmt = conn.prepareStatement( "update bands set costs_per_hour = ? where id = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, band.getCostsPerHour()); stmt.setInt(2, band.getId()); stmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void readBandRasterDataSubSampling( Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, int destWidth, ProgressMonitor pm) throws IOException { final int sourceMinY = sourceOffsetY; final int sourceMaxY = sourceOffsetY + sourceHeight - 1; ProductData lineBuffer = ProductData.createInstance(destBuffer.getType(), sourceWidth); int destPos = 0; try { pm.beginTask("Reading sub sampled raster data...", 2 * (sourceMaxY - sourceMinY)); for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) { sourceBand.readRasterData( sourceOffsetX, sourceY, sourceWidth, 1, lineBuffer, SubProgressMonitor.create(pm, 1)); if (sourceStepX == 1) { copyData(lineBuffer, 0, destBuffer, destPos, destWidth); } else { copyLine(lineBuffer, 0, sourceWidth, sourceStepX, destBuffer, destPos); } pm.worked(1); destPos += destWidth; } } finally { pm.done(); } }
private static RenderedImage getSourceImage(ProductSubsetDef subsetDef, Band band) { RenderedImage sourceImage = band.getSourceImage(); if (subsetDef != null) { final Rectangle region = subsetDef.getRegion(); if (region != null) { float x = region.x; float y = region.y; float width = region.width; float height = region.height; sourceImage = CropDescriptor.create(sourceImage, x, y, width, height, null); } final int subSamplingX = subsetDef.getSubSamplingX(); final int subSamplingY = subsetDef.getSubSamplingY(); if (mustSubSample(subSamplingX, subSamplingY) || mustTranslate(region)) { float scaleX = 1.0f / subSamplingX; float scaleY = 1.0f / subSamplingY; float transX = region != null ? -region.x : 0; float transY = region != null ? -region.y : 0; Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); sourceImage = ScaleDescriptor.create( sourceImage, scaleX, scaleY, transX, transY, interpolation, null); } } return sourceImage; }
public int getIdFromRehearsalRequest(Band band, RehearsalRequest rehearsalRequest) { int id = -1; try { PreparedStatement stmt = conn.prepareStatement( "select id from rehearsal_requests where band_id = ? and start_time = ? and end_time = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, band.getId()); stmt.setTimestamp(2, new java.sql.Timestamp(rehearsalRequest.getStartTime().getTime())); stmt.setTimestamp(3, new java.sql.Timestamp(rehearsalRequest.getEndTime().getTime())); ResultSet rs = stmt.executeQuery(); while (rs.next()) { id = rs.getInt(1); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return id; }
protected void setSpectralBand(Product product) { int spectralBandIndex = 0; for (String name : product.getBandNames()) { Band band = product.getBandAt(product.getBandIndex(name)); if (name.matches("\\w+_\\d{3,}")) { String[] parts = name.split("_"); String wvlstr = parts[parts.length - 1].trim(); // Some bands have the wvl portion in the middle... if (!wvlstr.matches("^\\d{3,}")) { wvlstr = parts[parts.length - 2].trim(); } final float wavelength = Float.parseFloat(wvlstr); band.setSpectralWavelength(wavelength); band.setSpectralBandIndex(spectralBandIndex++); } } }
public void addBand(Band band, String username) { try { PreparedStatement stmt = conn.prepareStatement( "insert into bands values(0, ?, ?, ?)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setString(1, band.getName()); stmt.setInt(2, this.getMusicianIdFromName(username)); stmt.setInt(3, band.getCostsPerHour()); stmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void creatExample() { Band p = new Band(); p.mask = false; p.xPos1 = -1; p.yPos1 = 100; p.xPos2 = -1; p.yPos2 = 100; p.brightness = -50; p.contrast = 0; p.saturation = 0; mBands.add(0, p); mCurrentBand = p; trimVector(); }
public Band[] getBands() { ResultSet rs = this.getData("select id, name from bands"); Vector<Band> bands = new Vector<Band>(); try { while (rs.next()) { Band b = new Band(); b.setId(rs.getInt(1)); b.setName(rs.getString(2)); bands.add(b); } conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return bands.toArray(new Band[bands.size()]); }
private boolean checkFlagDatasetIncluded() { final String[] nodeNames = productSubsetDef.getNodeNames(); final List<String> flagDsNameList = new ArrayList<String>(10); boolean flagDsInSubset = false; for (int i = 0; i < product.getNumBands(); i++) { Band band = product.getBandAt(i); if (band.getFlagCoding() != null) { flagDsNameList.add(band.getName()); if (StringUtils.contains(nodeNames, band.getName())) { flagDsInSubset = true; } break; } } final int numFlagDs = flagDsNameList.size(); boolean ok = true; if (numFlagDs > 0 && !flagDsInSubset) { int status = JOptionPane.showConfirmDialog( getJDialog(), "No flag dataset selected.\n\n" + "If you do not include a flag dataset in the subset,\n" + "you will not be able to create bitmask overlays.\n\n" + "Do you wish to include the available flag dataset(s)\n" + "in the current subset?\n", "No Flag Dataset Selected", JOptionPane.YES_NO_CANCEL_OPTION); if (status == JOptionPane.YES_OPTION) { productSubsetDef.addNodeNames(flagDsNameList.toArray(new String[numFlagDs])); ok = true; } else if (status == JOptionPane.NO_OPTION) { /* OK, no flag datasets wanted */ ok = true; } else if (status == JOptionPane.CANCEL_OPTION) { ok = false; } } return ok; }
static void copyReferencedRasters( String validMaskExpression, Scene sourceScene, Scene targetScene, ProductSubsetDef subsetDef) throws ParseException { final Product targetProduct = targetScene.getProduct(); final RasterDataNode[] nodes = BandArithmetic.getRefRasters(validMaskExpression, sourceScene.getProduct()); for (RasterDataNode node : nodes) { if (!targetProduct.containsRasterDataNode(node.getName())) { if (node instanceof TiePointGrid) { TiePointGrid tpg = TiePointGrid.createSubset((TiePointGrid) node, subsetDef); targetProduct.addTiePointGrid(tpg); } if (node instanceof Band) { final Band sourceBand = (Band) node; final Band band = createSubset(sourceBand, targetScene, subsetDef); targetProduct.addBand(band); setFlagCoding(band, sourceBand.getFlagCoding()); } } } }
private void readBandRasterDataRegion( Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { sourceBand.readRasterData( sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, destBuffer, pm); }
public int addBand(Rect rect) { mBands.add(0, mCurrentBand = new Band(rect.centerX(), rect.centerY())); mCurrentBand.mask = false; int x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2; int y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2; double addDelta = ADD_MIN_DIST * Math.max(rect.width(), rect.height()); boolean moved = true; int count = 0; int toMove = mBands.indexOf(mCurrentBand); while (moved) { moved = false; count++; if (count > 14) { break; } for (Band point : mBands) { if (point.mask) { break; } } for (Band point : mBands) { if (point.mask) { break; } int index = mBands.indexOf(point); if (toMove != index) { double dist = Math.hypot(point.xPos1 - x, point.yPos1 - y); if (dist < addDelta) { moved = true; mCurrentBand.xPos1 += addDelta; mCurrentBand.yPos1 += addDelta; mCurrentBand.xPos2 += addDelta; mCurrentBand.yPos2 += addDelta; x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2; y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2; if (mCurrentBand.yPos1 > rect.bottom) { mCurrentBand.yPos1 = (int) (rect.top + addDelta); } if (mCurrentBand.xPos1 > rect.right) { mCurrentBand.xPos1 = (int) (rect.left + addDelta); } } } } } trimVector(); return 0; }
public void computeLatLonBandData( int height, int width, Band latBand, Band lonBand, final float[] latRawData, final float[] lonRawData, final int[] colPoints) { float[] latFloats = new float[height * width]; float[] lonFloats = new float[height * width]; final int rawWidth = colPoints.length; int colPointIdx = 0; int p1 = colPoints[colPointIdx] - 1; int p2 = colPoints[++colPointIdx] - 1; for (int x = 0; x < width; x++) { if (x == p2 && colPointIdx < rawWidth - 1) { p1 = p2; p2 = colPoints[++colPointIdx] - 1; } final int steps = p2 - p1; final double step = 1.0 / steps; final double weight = step * (x - p1); for (int y = 0; y < height; y++) { final int rawPos2 = y * rawWidth + colPointIdx; final int rawPos1 = rawPos2 - 1; final int pos = y * width + x; latFloats[pos] = computeGeoPixel(latRawData[rawPos1], latRawData[rawPos2], weight); lonFloats[pos] = computeGeoPixel(lonRawData[rawPos1], lonRawData[rawPos2], weight); } } latBand.setDataElems(latFloats); lonBand.setDataElems(lonFloats); }
public void addAppearance(Band band, Appointment appointment) { try { PreparedStatement stmt = conn.prepareStatement( "insert into appearances values (?, ?)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, appointment.getId()); stmt.setInt(2, band.getId()); stmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public void deSerializeRepresentation(JsonReader sreader) throws IOException { sreader.beginObject(); Vector<Band> points = new Vector<Band>(); while (sreader.hasNext()) { String name = sreader.nextName(); if (name.startsWith(LINE_NAME)) { int pointNo = Integer.parseInt(name.substring(LINE_NAME.length())); sreader.beginArray(); Band p = new Band(); p.mask = false; sreader.hasNext(); p.xPos1 = sreader.nextInt(); sreader.hasNext(); p.yPos1 = sreader.nextInt(); sreader.hasNext(); p.xPos2 = sreader.nextInt(); sreader.hasNext(); p.yPos2 = sreader.nextInt(); sreader.hasNext(); p.brightness = sreader.nextInt(); sreader.hasNext(); p.contrast = sreader.nextInt(); sreader.hasNext(); p.saturation = sreader.nextInt(); sreader.hasNext(); sreader.endArray(); points.add(p); } else { sreader.skipValue(); } } mBands = points; trimVector(); mCurrentBand = mBands.get(0); sreader.endObject(); }
protected Band addNewBand(Product product, Variable variable) { final int sceneRasterWidth = product.getSceneRasterWidth(); final int sceneRasterHeight = product.getSceneRasterHeight(); Band band = null; int variableRank = variable.getRank(); if (variableRank == 2) { final int[] dimensions = variable.getShape(); final int height = dimensions[0] - leadLineSkip - tailLineSkip; final int width = dimensions[1]; if (height == sceneRasterHeight && width == sceneRasterWidth) { final String name = variable.getShortName(); final int dataType = getProductDataType(variable); band = new Band(name, dataType, width, height); final String validExpression = bandInfoMap.get(name); if (validExpression != null && !validExpression.equals("")) { band.setValidPixelExpression(validExpression); } product.addBand(band); try { band.setNoDataValue( (double) variable.findAttribute("bad_value_scaled").getNumericValue().floatValue()); band.setNoDataValueUsed(true); } catch (Exception ignored) { } final List<Attribute> list = variable.getAttributes(); for (Attribute hdfAttribute : list) { final String attribName = hdfAttribute.getShortName(); if ("units".equals(attribName)) { band.setUnit(hdfAttribute.getStringValue()); } else if ("long_name".equals(attribName)) { band.setDescription(hdfAttribute.getStringValue()); } else if ("slope".equals(attribName)) { band.setScalingFactor(hdfAttribute.getNumericValue(0).doubleValue()); } else if ("intercept".equals(attribName)) { band.setScalingOffset(hdfAttribute.getNumericValue(0).doubleValue()); } } } } return band; }
public void addMember(Band band, String username) { try { PreparedStatement stmt = conn.prepareStatement( "insert into bandmembers values(?, ?, ?)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, band.getId()); stmt.setInt(2, this.getMusicianIdFromName(username)); stmt.setTimestamp(3, new java.sql.Timestamp(new Date().getTime())); stmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private Band addBand(Product product, String varName, int productType) { Band band = new Band( varName, productType, product.getSceneRasterWidth(), product.getSceneRasterHeight()); band.setScalingOffset(0.0); band.setScalingFactor(1.0); band.setLog10Scaled(false); if (productType == ProductData.TYPE_FLOAT32) { band.setNoDataValue(Double.NaN); } else { band.setNoDataValue(-999); } band.setNoDataValueUsed(true); product.addBand(band); return band; }