protected Product processProduct(Product existingProduct) throws IOException { initInput(); Document dom = readDom(); this.product = existingProduct == null ? DimapProductHelpers.createProduct(dom) : existingProduct; this.product.setProductReader(this); if (existingProduct == null) { readTiePointGrids(dom); } bindBandsToFiles(dom); if (existingProduct == null) { readVectorData(ImageManager.DEFAULT_IMAGE_CRS, true); // read GCPs and pins from DOM (old-style) DimapProductHelpers.addGcps(dom, this.product); DimapProductHelpers.addPins(dom, this.product); initGeoCodings(dom); readVectorData(ImageManager.getModelCrs(product.getGeoCoding()), false); DimapProductHelpers.addMaskUsages(dom, this.product); } this.product.setProductReader(this); this.product.setFileLocation(inputFile); this.product.setModified(false); return this.product; }
private void initGeoCodings(Document dom) { final GeoCoding[] geoCodings = DimapProductHelpers.createGeoCoding(dom, product); if (geoCodings != null) { if (geoCodings.length == 1) { product.setGeoCoding(geoCodings[0]); } else if (geoCodings.length == product.getNumBands()) { for (int i = 0; i < geoCodings.length; i++) { final Band band = product.getBandAt(i); if (product.getSceneRasterWidth() == band.getRasterWidth() && product.getSceneRasterHeight() == band.getRasterHeight()) { product.setGeoCoding(geoCodings[i]); } band.setGeoCoding(geoCodings[i]); } } } else { final Band lonBand = product.getBand("longitude"); final Band latBand = product.getBand("latitude"); if (latBand != null && lonBand != null) { final GeoCoding geoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, null, 6); product.setGeoCoding(geoCoding); } } }
private void readTiePointGrids(Document jDomDocument) throws IOException { final String[] tiePointGridNames = product.getTiePointGridNames(); for (String tiePointGridName : tiePointGridNames) { final TiePointGrid tiePointGrid = product.getTiePointGrid(tiePointGridName); String dataFile = DimapProductHelpers.getTiePointDataFile(jDomDocument, tiePointGrid.getName()); final int dataType = DimapProductHelpers.getTiePointDataType( jDomDocument.getRootElement(), tiePointGrid.getName()); dataFile = FileUtils.exchangeExtension(dataFile, DimapProductConstants.IMAGE_FILE_EXTENSION); FileImageInputStream inputStream = null; try { inputStream = new FileImageInputStream(new File(inputDir, dataFile)); final float[] data = ((float[]) tiePointGrid.getData().getElems()); inputStream.seek(0); if (dataType == ProductData.TYPE_FLOAT32) { inputStream.readFully(data, 0, data.length); } else { final double[] doubles = new double[data.length]; inputStream.readFully(doubles, 0, doubles.length); int i = 0; for (double d : doubles) { data[i++] = (float) d; } } inputStream.close(); inputStream = null; // See if we have a -180...+180 or a 0...360 degree discontinuity if (tiePointGrid.getDiscontinuity() != TiePointGrid.DISCONT_NONE) { tiePointGrid.setDiscontinuity(TiePointGrid.getDiscontinuity(data)); } } catch (Exception e) { throw new IOException( MessageFormat.format( "I/O error while reading tie-point grid ''{0}''.", tiePointGridName), e); } finally { if (inputStream != null) { inputStream.close(); } } } }
private void bindBandsToFiles(Document dom) { bandDataFiles = DimapProductHelpers.getBandDataFiles(dom, product, getInputDir()); final Band[] bands = product.getBands(); for (final Band band : bands) { if (band instanceof VirtualBand || band instanceof FilterBand) { continue; } final File dataFile = bandDataFiles.get(band); if (dataFile == null || !dataFile.canRead()) { SystemUtils.LOG.warning( "DimapProductReader: Unable to read file '" + dataFile + "' referenced by '" + band.getName() + "'."); SystemUtils.LOG.warning( "DimapProductReader: Removed band '" + band.getName() + "' from product '" + product.getFileLocation() + "'."); } } }