use of org.geotools.styling.StyledLayerDescriptor 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.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class YSLDTool method exportToYSLD.
/**
* Export to YSLD.
*/
private void exportToYSLD() {
SLDWriterInterface ysldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.YSLD);
for (SLDDataInterface sldData : sldDataList) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
String layerName = sldData.getLayerNameWithOutSuffix();
if (sld != null) {
String sldString = ysldWriter.encodeSLD(sldData.getResourceLocator(), sld);
String destinationFolder = sldData.getSLDFile().getParent();
File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, YSLDTool.YSLD_FILE_EXTENSION);
String ysldFilename = fileToSave.getName();
if (fileToSave.exists()) {
ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + ysldFilename);
} else {
ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToYSLDMsg") + " " + ysldFilename);
try (BufferedWriter out = new BufferedWriter(new FileWriter(fileToSave))) {
out.write(sldString);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SLDEditorCommon method populate.
/**
* Populate.
*
* @param sldData the sld data
*/
public void populate(SLDDataInterface sldData) {
String layerName = sldData.getLayerName();
File sldEditorFile = sldData.getSldEditorFile();
if (sldEditorFile != null) {
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(SLDEditor.class, "SLDEditor.loadedSLDEditorFile"), sldEditorFile.getAbsolutePath()));
}
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(SLDEditor.class, "SLDEditor.loadedSLDFile"), layerName));
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
SelectedSymbol selectedSymbolInstance = SelectedSymbol.getInstance();
selectedSymbolInstance.setSld(sld);
selectedSymbolInstance.setFilename(layerName);
selectedSymbolInstance.setName(layerName);
SLDEditorFile.getInstance().setSLDData(sldData);
// Reload data source if sticky flag is set
boolean isDataSourceSticky = SLDEditorFile.getInstance().isStickyDataSource();
DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
DataSourcePropertiesInterface previousDataSource = dataSource.getDataConnectorProperties();
dataSource.reset();
if (isDataSourceSticky) {
SLDEditorFile.getInstance().setDataSource(previousDataSource);
}
dataSource.connect(ExternalFilenames.removeSuffix(layerName), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
VendorOptionManager.getInstance().loadSLDFile(SLDEditorUIPanels.getInstance(), sld, sldData);
LegendManager.getInstance().sldLoaded(sldData.getLegendOptions());
SLDEditorFile.getInstance().fileOpenedSaved();
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class VendorOptionUI method populate.
/**
* Populate.
*
* @param selectedSymbol the selected symbol
*/
public void populate(SelectedSymbol selectedSymbol) {
if (selectedSymbol != null) {
StyledLayerDescriptor sld = selectedSymbol.getSld();
updatePanel(sld);
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SLDWriterImpl method encodeSLD.
/**
* Encode sld to a string.
*
* @param resourceLocator the resource locator
* @param sld the sld
* @return the string
*/
@Override
public String encodeSLD(URL resourceLocator, StyledLayerDescriptor sld) {
String xml = "";
if (sld != null) {
InlineDatastoreVisitor duplicator = new InlineDatastoreVisitor();
sld.accept(duplicator);
StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicator.getCopy();
if (resourceLocator != null) {
SLDExternalImages.updateOnlineResources(resourceLocator, sldCopy);
}
SLDTransformer transformer = new SLDTransformer();
transformer.setIndentation(2);
try {
xml = transformer.transform(sldCopy);
} catch (TransformerException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
return xml;
}
Aggregations