use of org.geotools.coverage.grid.io.AbstractGridFormat in project sldeditor by robward-scisys.
the class DetermineRasterFormat method choose.
/**
* 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 (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();
}
use of org.geotools.coverage.grid.io.AbstractGridFormat in project sldeditor by robward-scisys.
the class RasterReader method createRasterSLDData.
/**
* Creates the raster sld.
*
* @param rasterFile the raster file
* @return the styled layer descriptor
*/
@Override
public SLDDataInterface createRasterSLDData(File rasterFile) {
if (rasterFile == null) {
return null;
}
StyledLayerDescriptor sld = null;
AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
AbstractGridCoverage2DReader reader = null;
try {
reader = format.getReader(rasterFile);
} catch (UnsupportedOperationException e) {
ConsoleManager.getInstance().error(this, Localisation.getField(RasterTool.class, "RasterReader.unknownFormat") + rasterFile.getAbsolutePath());
return null;
}
BufferedImage img = null;
try {
img = ImageIO.read(rasterFile);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
}
WritableRaster raster = img.getRaster();
Style style = createRGBStyle(reader, raster);
sld = sf.createStyledLayerDescriptor();
NamedLayer namedLayer = sf.createNamedLayer();
namedLayer.addStyle(style);
sld.addStyledLayer(namedLayer);
File sldFilename = ExternalFilenames.createSLDFilename(rasterFile);
StyleWrapper styleWrapper = new StyleWrapper(sldFilename.getName());
String sldContents = sldWriter.encodeSLD(null, sld);
SLDData sldData = new SLDData(styleWrapper, sldContents);
sldData.setSLDFile(sldFilename);
sldData.setReadOnly(false);
return sldData;
}
use of org.geotools.coverage.grid.io.AbstractGridFormat in project OpenTripPlanner by opentripplanner.
the class RasterPopulation method createIndividuals.
@Override
public void createIndividuals() {
LOG.info("Loading population from raster file {}", sourceFilename);
try {
File rasterFile = new File(sourceFilename);
// determine file format and CRS, then load raster
AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
GridCoverage2D coverage = reader.read(null);
this.coverageCRS = coverage.getCoordinateReferenceSystem();
GridGeometry2D gridGeometry = coverage.getGridGeometry();
GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D();
gridGeometry.getGridToCRS();
// because we may want to produce an empty raster rather than loading one, alongside the coverage we
// store the row/col dimensions and the referenced envelope in the original coordinate reference system.
this.cols = gridEnvelope.width;
this.rows = gridEnvelope.height;
this.createIndividuals0();
} catch (Exception ex) {
throw new IllegalStateException("Error loading population from raster file: ", ex);
}
LOG.info("Done loading raster from file.");
}
Aggregations