org.geotools.coverage.grid.io.AbstractGridFormat Java Examples

The following examples show how to use org.geotools.coverage.grid.io.AbstractGridFormat. 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: DetermineRasterFormat.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get user to choose raster format.
 *
 * @param rasterFile the raster file
 * @param selectionPanel the selection panel
 * @return the abstract grid format
 */
public static AbstractGridFormat choose(
        File rasterFile, ChooseRasterFormatInterface selectionPanel) {
    if (rasterFile != null) {
        final Set<AbstractGridFormat> formats =
                GridFormatFinder.findFormats(rasterFile, GeoTools.getDefaultHints());

        if (!classUndertest && (formats.size() > 1)) {
            if (selectionPanel != null) {
                AbstractGridFormat selectedFormat = selectionPanel.showPanel(formats);
                if (selectedFormat != null) {
                    return selectedFormat;
                }
            }
        }

        // otherwise just pick the first
        final Iterator<AbstractGridFormat> it = formats.iterator();
        if (it.hasNext()) {
            return it.next();
        }
    }
    return new UnknownFormat();
}
 
Example #2
Source File: CreateExternalDataSource.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Connect to raster data source.
 *
 * @param map the map
 */
private void connectToRasterDataSource(Map<String, Object> map) {
    Object rasterFilename = map.get(DataSourceConstants.FILE_MAP_KEY);
    if (rasterFilename != null) {
        File rasterFile = new File(ExternalFilenames.convertURLToFile((String) rasterFilename));

        ChooseRasterFormatInterface panel =
                new ChooseRasterFormatPanel(Controller.getInstance().getFrame());

        AbstractGridFormat format = DetermineRasterFormat.choose(rasterFile, panel);
        AbstractGridCoverage2DReader reader = format.getReader(rasterFile);

        dsInfo.setGridCoverageReader(reader);
    } else {
        logger.error("No matching datastore");
    }
}
 
Example #3
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static RegionMap generalParameterValues2RegionParamsMap( GeneralParameterValue[] params ) {
    GridGeometry2D gg = null;
    if (params != null) {
        for( int i = 0; i < params.length; i++ ) {
            final ParameterValue< ? > param = (ParameterValue< ? >) params[i];
            final String name = param.getDescriptor().getName().getCode();
            if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString())) {
                gg = (GridGeometry2D) param.getValue();
                break;
            }
        }
    }
    if (gg == null) {
        throw new IllegalArgumentException("No gridgeometry present"); //$NON-NLS-1$
    }
    RegionMap regionParams = gridGeometry2RegionParamsMap(gg);
    return regionParams;
}
 
Example #4
Source File: GridCoverageNwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private static GTRenderer getRenderer( File rasterFile ) {

        AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
        AbstractGridCoverage2DReader coverageReader = format.getReader(rasterFile);

        MapContent mapContent = new MapContent();
        try {

            Style rasterStyle = SldUtilities.getStyleFromFile(rasterFile);
            if (rasterStyle == null) {
                RasterSymbolizer sym = SldUtilities.sf.getDefaultRasterSymbolizer();
                rasterStyle = SLD.wrapSymbolizers(sym);
            }

            GridReaderLayer layer = new GridReaderLayer(coverageReader, rasterStyle);
            mapContent.addLayer(layer);
            mapContent.getViewport().setCoordinateReferenceSystem(CrsUtilities.WGS84);
        } catch (Exception e) {
            e.printStackTrace();
        }
        GTRenderer renderer = new StreamingRenderer();
        renderer.setMapContent(mapContent);
        return renderer;
    }
 
Example #5
Source File: OmsRasterWriter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private void writeArcGrid( File mapFile ) throws Exception {
    final ArcGridFormat format = new ArcGridFormat();
    final ArcGridWriteParams wp = new ArcGridWriteParams();
    final ParameterValueGroup paramWrite = format.getWriteParameters();
    paramWrite.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
    ArcGridWriter gtw = (ArcGridWriter) format.getWriter(new File(file));
    gtw.write(inRaster, (GeneralParameterValue[]) paramWrite.values().toArray(new GeneralParameterValue[1]));
    gtw.dispose();
}
 
Example #6
Source File: OmsRasterWriter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private void writeGeotiff( File mapFile ) throws Exception {
    final GeoTiffFormat format = new GeoTiffFormat();
    final GeoTiffWriteParams wp = new GeoTiffWriteParams();
    wp.setCompressionMode(GeoTiffWriteParams.MODE_DEFAULT);
    wp.setTilingMode(GeoToolsWriteParams.MODE_DEFAULT);
    final ParameterValueGroup paramWrite = format.getWriteParameters();
    paramWrite.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
    GeoTiffWriter gtw = (GeoTiffWriter) format.getWriter(mapFile);
    gtw.write(inRaster, (GeneralParameterValue[]) paramWrite.values().toArray(new GeneralParameterValue[1]));
}
 
Example #7
Source File: GeoToolsRasterDataStoreIngestPlugin.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsFile(final URL file) {
  AbstractGridFormat format = null;
  try {
    format = GridFormatFinder.findFormat(file);
  } catch (final Exception e) {
    LOGGER.info("Unable to support as raster file", e);
  }
  // the null check is enough and we don't need to check the format
  // accepts this file because the finder should have previously validated
  // this, also don't allwo ingest from geowave raster format because its URL validation is way
  // too lenient (ie. the URL is probably not supported)
  return (format != null && !(format instanceof GeoWaveGTRasterFormat));
}
 
Example #8
Source File: GeoWaveRasterReader.java    From geowave with Apache License 2.0 5 votes vote down vote up
public GridCoverage2D renderGridCoverage(
    final String coverageName,
    final Rectangle dim,
    final GeneralEnvelope generalEnvelope,
    Color backgroundColor,
    Color outputTransparentColor,
    final Interpolation interpolation) throws IOException {
  if (backgroundColor == null) {
    backgroundColor = AbstractGridFormat.BACKGROUND_COLOR.getDefaultValue();
  }
  if (outputTransparentColor == null) {
    outputTransparentColor = GeoWaveGTRasterFormat.OUTPUT_TRANSPARENT_COLOR.getDefaultValue();
  }

  final GeoWaveRasterReaderState state = new GeoWaveRasterReaderState(coverageName);
  state.setRequestedEnvelope(generalEnvelope);
  // /////////////////////////////////////////////////////////////////////
  //
  // Loading tiles trying to optimize as much as possible
  //
  // /////////////////////////////////////////////////////////////////////
  final GridCoverage2D coverage =
      loadTiles(
          coverageName,
          backgroundColor,
          outputTransparentColor,
          interpolation,
          dim,
          state,
          getCoordinateReferenceSystem(coverageName),
          getOriginalEnvelope(coverageName));

  return coverage;
}
 
Example #9
Source File: DetermineRasterFormatTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.datasource.chooseraster.DetermineRasterFormat#choose(java.io.File,
 * com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)}.
 */
@Test
public void testChoose() {
    AbstractGridFormat gridFormat = DetermineRasterFormat.choose(null, null);
    assertTrue(UnknownFormat.class == gridFormat.getClass());

    String testRasterFile = "/raster/sld/sld_cookbook_raster.tif";
    InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testRasterFile);
    File f = null;

    if (inputStream == null) {
        assertNotNull(inputStream, "Failed to find raster test file : " + testRasterFile);
    } else {
        try {
            f = SLDTestRunner.stream2file(inputStream, ".tif");

            gridFormat = DetermineRasterFormat.choose(f, null);

            assertTrue(gridFormat != null);

            // Force to WorldImageFormat
            gridFormat =
                    DetermineRasterFormat.choose(
                            f,
                            new ChooseRasterFormatInterface() {

                                @Override
                                public AbstractGridFormat showPanel(
                                        Set<AbstractGridFormat> formatList) {
                                    WorldImageFormat wif = new WorldImageFormat();

                                    return wif;
                                }
                            });

            assertTrue(WorldImageFormat.class == gridFormat.getClass());
        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            f.delete();
        }
    }
}
 
Example #10
Source File: HMModelIM.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
protected void addSource( File imageMosaicSource ) throws Exception {

        URL imageMosaicUrl = imageMosaicSource.toURI().toURL();
        final AbstractGridFormat imageMosaicFormat = (AbstractGridFormat) GridFormatFinder.findFormat(imageMosaicUrl);
        final ImageMosaicReader imReader = (ImageMosaicReader) imageMosaicFormat.getReader(imageMosaicUrl);
        // ImageMosaicReader imReader = new ImageMosaicReader(imageMosaicSource);

        if (readers.size() == 0) {
            File propertiesFile = FileUtilities.substituteExtention(imageMosaicSource, "properties");
            HashMap<String, String> propertiesMap = FileUtilities.readFileToHashMap(propertiesFile.getAbsolutePath(), null,
                    false);

            String xyREs = propertiesMap.get("Levels");
            String[] split = xyREs.split(",");
            xRes = Double.parseDouble(split[0]);
            yRes = Double.parseDouble(split[1]);

            locationField = propertiesMap.get("LocationAttribute");
            crs = imReader.getCoordinateReferenceSystem();

            GeneralEnvelope originalEnvelope = imReader.getOriginalEnvelope();
            llCorner = originalEnvelope.getLowerCorner().getCoordinate();
            urCorner = originalEnvelope.getUpperCorner().getCoordinate();

            SimpleFeatureCollection vectorBounds = OmsVectorReader.readVector(imageMosaicSource.getAbsolutePath());
            boundsGeometries = FeatureUtilities.featureCollectionToGeometriesList(vectorBounds, true, locationField);

            Envelope singleTileEnv = boundsGeometries.get(0).getEnvelopeInternal();
            Envelope allTilesEnv = new Envelope();
            for( Geometry boundsGeometry : boundsGeometries ) {
                allTilesEnv.expandToInclude(boundsGeometry.getEnvelopeInternal());
            }
            if (allTilesEnv.getWidth() > singleTileEnv.getWidth()) {
                isSingleInX = false;
            }
            if (allTilesEnv.getHeight() > singleTileEnv.getHeight()) {
                isSingleInY = false;
            }

        }
        readers.add(imReader);
    }
 
Example #11
Source File: OmsMapsViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void addImageMosaic( MapContent map ) throws Exception {
    if (inImageMosaics != null) {
        RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
        Style style = SLD.wrapSymbolizers(sym);

        final ParameterValue<Color> inTransp = AbstractGridFormat.INPUT_TRANSPARENT_COLOR.createValue();
        inTransp.setValue(Color.white);

        final ParameterValue<Color> outTransp = ImageMosaicFormat.OUTPUT_TRANSPARENT_COLOR.createValue();
        outTransp.setValue(Color.white);
        final ParameterValue<Color> backColor = ImageMosaicFormat.BACKGROUND_COLOR.createValue();
        backColor.setValue(Color.RED);
        final ParameterValue<Boolean> fading = ImageMosaicFormat.FADING.createValue();
        fading.setValue(true);

        final ParameterValue<Interpolation> interpol = ImageMosaicFormat.INTERPOLATION.createValue();
        interpol.setValue(new javax.media.jai.InterpolationBilinear());

        final ParameterValue<Boolean> resol = ImageMosaicFormat.ACCURATE_RESOLUTION.createValue();
        resol.setValue(true);

        
        final ParameterValue<Boolean> multiThread= ImageMosaicFormat.ALLOW_MULTITHREADING.createValue();
        multiThread.setValue(true);

        final ParameterValue<Boolean> usejai = ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue();
        usejai.setValue(false);

        final ParameterValue<double[]> bkg = ImageMosaicFormat.BACKGROUND_VALUES.createValue();
        bkg.setValue(new double[]{0});

        GeneralParameterValue[] gp = new GeneralParameterValue[]{inTransp, multiThread};

        for( String imageMosaicPath : inImageMosaics ) {
            ImageMosaicReader imr = new ImageMosaicReader(new File(imageMosaicPath));
            GridReaderLayer layer = new GridReaderLayer(imr, style, gp);
            map.addLayer(layer);
        }
    }

}
 
Example #12
Source File: OmsRasterReader.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    if (!concatOr(outRaster == null, doReset)) {
        return;
    }

    if (fileNovalue != null) {
        internalFileNovalue = fileNovalue;
    }
    if (geodataNovalue != null) {
        internalGeodataNovalue = geodataNovalue;
    }

    if (hasBoundsRequest() && (!hasResolutionRequest() && !hasRowColsRequest())) {
        throw new RuntimeException("If bounds are requested, also a resolution or number of rows/cols has to be supplied.");
    }
    if (hasBoundsRequest()) {
        pBounds = new double[]{pNorth, pSouth, pWest, pEast};
    }
    if (hasResolutionRequest()) {
        pRes = new double[]{pXres, pYres};
    }
    if (hasRowColsRequest()) {
        pRowcol = new int[]{pRows, pCols};
    }
    File mapFile = new File(file);
    AbstractGridFormat format = GridFormatFinder.findFormat(mapFile);
    if (format != null && !(format instanceof GrassCoverageFormat)) {
        if (format instanceof UnknownFormat) {
            throw new ModelsIllegalargumentException("Unupported format for: " + mapFile, this.getClass().getSimpleName(),
                    pm);
        } else {
            try {
                pm.beginTask("Reading coverage: " + mapFile.getName(), IHMProgressMonitor.UNKNOWN);
                AbstractGridCoverage2DReader rasterReader = format.getReader(mapFile);
                originalEnvelope = rasterReader.getOriginalEnvelope();
                if (!doEnvelope) {
                    outRaster = rasterReader.read(generalParameter);

                    Double noValueObj = CoverageUtilities.getNovalue(outRaster);
                    if (noValueObj != null) {
                        fileNovalue = noValueObj;
                    }

                    resample();
                    checkNovalues();
                }

                boolean crsValid = CrsUtilities.isCrsValid(outRaster.getCoordinateReferenceSystem());
                if (!crsValid) {
                    pm.errorMessage(
                            "The read CRS doesn't seem to be valid. This could lead to unexpected results. Consider adding a .prj file with the proper CRS definition if none is present.");
                }
            } finally {
                pm.done();
            }
        }
    } else if (CoverageUtilities.isGrass(file)) {
        try {
            pm.beginTask("Reading coverage: " + mapFile.getName(), IHMProgressMonitor.UNKNOWN);
            readGrass(mapFile);
        } finally {
            pm.done();
        }
    } else {
        throw new ModelsIllegalargumentException("Can't recognize the data format for: " + mapFile,
                this.getClass().getSimpleName(), pm);
    }

}
 
Example #13
Source File: GDALGeoTiffFormatFactory.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public AbstractGridFormat createFormat() {
  return new GDALGeoTiffFormat();
}
 
Example #14
Source File: GeoWaveGTRasterFormatFactory.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public AbstractGridFormat createFormat() {
  return new GeoWaveGTRasterFormat();
}
 
Example #15
Source File: ChooseRasterFormatInterface.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Show panel.
 *
 * @param formatList the format list
 * @return the abstract grid format
 */
AbstractGridFormat showPanel(Set<AbstractGridFormat> formatList);