String layername = conf.getLayername();
if (layername==null) throw new ActionException(this, "the layer name cannot be empty");
if (rasterpixelheight==0.0d || rasterpixelwidth==0.0d) throw new ActionException(this, "the raster pixel size is wrong");
FileSystemEvent fileEvent=(FileSystemEvent)ev;
File file = fileEvent.getSource();
FileDataStore store = null;
// this action can be used also getting a simpleFeatureCollection from another resource than a file
// in this case the features field is not null but it is filled externally
if (features==null) {
store = FileDataStoreFinder.getDataStore(file);
if (store==null) throw new ActionException(this, "the layer "+file.getCanonicalPath()+" cannot be found. Skip execution.");
FeatureSource featureSource = store.getFeatureSource();
SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
Query query = new Query( schema.getTypeName(), Filter.INCLUDE );
query.setCoordinateSystem(CRS.decode("EPSG:4326", true));
features = (SimpleFeatureCollection) featureSource.getFeatures( query );
// features = (SimpleFeatureCollection) featureSource.getFeatures();
}
//CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
CoordinateReferenceSystem crs = features.getSchema().getCoordinateReferenceSystem();
ReferencedEnvelope bounds = new ReferencedEnvelope(rasterx0, rasterx1, rastery0, rastery1,crs);
Dimension gridDim = new Dimension(rasterpixelwidth, rasterpixelheight);
String covName = layername;
ProgressListener monitor = null;
GridCoverage2D cov = VectorToRasterProcess.process(features, rasterAttribName, gridDim, bounds, covName, monitor);
LOGGER.debug("CRS :"+cov.getCoordinateReferenceSystem().toWKT());
// System.out.println(cov.toString());
// Map<String, Object> attribute = new HashMap<String, Object>();
// attribute.put("rasterAttribName", rasterAttribName);
// if (rasterCqlFilter!=null) attribute.put("rasterCqlFilter", rasterCqlFilter);
File tmpTiff = null;
if (conf.getFilename()!=null)
tmpTiff = new File(conf.getWorkingDirectory(),conf.getFilename());
else
tmpTiff = new File(conf.getWorkingDirectory(),"testcov.tif");
GeoTiffWriter writer = null;
try {
writer = new GeoTiffWriter(tmpTiff);
if (height>0 && width>0) {
GeoTiffWriteParams params = new GeoTiffWriteParams();
params.setTilingMode(TIFFImageWriteParam.MODE_EXPLICIT);
params.setTiling(conf.getRetileH(), conf.getRetileW());
ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue();
value.setValue(params);
writer.write(cov, new GeneralParameterValue[]{value});
}
else
writer.write(cov, null );
} catch (IOException e) {
// TODO Auto-generated catch block
LOGGER.error("An exception was raised executing the RasterizeAction",e);
throw new ActionException(this,"An exception was raised executing the RasterizeAction");
}
finally {
// if (writer!=null) writer.dispose();
FileSystemEvent fileSystemInsertEvent = new FileSystemEvent(tmpTiff, FileSystemEventType.FILE_ADDED);
ret.add(fileSystemInsertEvent);
if (store!=null) store.dispose();
}
// add the event to the return