use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class NewRasterSLD method create.
/**
* Creates the symbol.
*
* @return the styled layer descriptor
*/
/* (non-Javadoc)
* @see com.sldeditor.create.NewSLDInterface#create()
*/
@Override
public StyledLayerDescriptor create() {
StyledLayerDescriptor sld = getStyleFactory().createStyledLayerDescriptor();
NamedLayer namedLayer = getStyleFactory().createNamedLayer();
sld.addStyledLayer(namedLayer);
Style style = getStyleFactory().createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
FeatureTypeStyle fts = getStyleFactory().createFeatureTypeStyle();
ftsList.add(fts);
Rule rule = getStyleFactory().createRule();
fts.rules().add(rule);
RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
rule.symbolizers().add(raster);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class YSLDFileHandler method internalOpenFile.
/**
* Internal open file.
*
* @param f the file
* @param list the list
*/
private void internalOpenFile(File f, List<SLDDataInterface> list) {
if (f.isFile() && FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
try {
String contents = readFile(f, Charset.defaultCharset());
StyledLayerDescriptor sld = Ysld.parse(contents);
// Convert YSLD to SLD string
if (sldWriter == null) {
sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
}
String sldContents = sldWriter.encodeSLD(null, sld);
SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
sldData.setSLDFile(f);
sldData.setReadOnly(false);
sldData.setOriginalFormat(SLDOutputFormatEnum.YSLD);
list.add(sldData);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class ExtractValidFieldTypes method fieldTypesUpdated.
/**
* Evaluate fields types.
*
* @return true, field types updated
*/
public static boolean fieldTypesUpdated() {
boolean fieldsUpdated = false;
SLDStyleFactory styleFactory = new SLDStyleFactory();
StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
for (StyledLayer styledLayer : styledLayerList) {
List<org.geotools.styling.Style> styleList = null;
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
styleList = namedLayerImpl.styles();
} else if (styledLayer instanceof UserLayerImpl) {
UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
styleList = userLayerImpl.userStyles();
}
if (styleList != null) {
for (Style style : styleList) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
for (Symbolizer symbolizer : rule.symbolizers()) {
FeatureSource<SimpleFeatureType, SimpleFeature> featureList = DataSourceFactory.getDataSource().getFeatureSource();
if (featureList != null) {
Object drawMe = null;
try {
drawMe = featureList.getFeatures().features().next();
} catch (NoSuchElementException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
styleFactory.createStyle(drawMe, symbolizer);
} catch (IllegalArgumentException e) {
String message = e.getMessage();
if (message.startsWith(UNABLE_TO_DECODE_PREFIX) && message.endsWith(UNABLE_TO_DECODE_SUFFIX)) {
String fieldName = message.substring(UNABLE_TO_DECODE_PREFIX.length(), message.length() - UNABLE_TO_DECODE_SUFFIX.length());
DataSourceFactory.getDataSource().updateFieldType(fieldName, Long.class);
fieldsUpdated = true;
} else {
ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e);
}
}
}
}
}
}
}
}
}
}
return fieldsUpdated;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class RenderPanelImpl method renderSymbol.
/**
* Render symbol.
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.marker.iface.RenderSymbolInterface#renderSymbol()
*/
@Override
public void renderSymbol() {
validSymbol = SelectedSymbol.getInstance().isValid();
if (validSymbol) {
StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
if (sld != null) {
for (SLDOutputInterface sldOutput : sldOutputList) {
sldOutput.updatedSLD(sldData, sld);
}
renderSymbol((Style) renderSymbol.getRenderStyle(SelectedSymbol.getInstance()));
} else {
renderSymbol(null);
}
} else {
repaint();
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class YSLDTool method exportToSLD.
/**
* Export to SLD.
*/
private void exportToSLD() {
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
for (SLDDataInterface sldData : sldDataList) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
String layerName = sldData.getLayerNameWithOutSuffix();
if (sld != null) {
String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
String destinationFolder = sldData.getSLDFile().getParent();
File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
String sldFilename = fileToSave.getName();
if (fileToSave.exists()) {
ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + sldFilename);
} else {
ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToSLDMsg") + " " + sldFilename);
BufferedWriter out;
try {
out = new BufferedWriter(new FileWriter(fileToSave));
out.write(sldString);
out.close();
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
}
}
Aggregations