use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SymbolizerDetailsPanel method getMinimumVersion.
/**
* Gets the minimum version vendor option present in the SLD.
*
* @param parentObj the parent obj
* @param sldObj the sld obj
* @param vendorOptionsPresentList the vendor options present list
*/
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
Class<?> parentClass = null;
Class<?> classSelected = sldObj.getClass();
if (sldObj instanceof StyledLayerDescriptor) {
// No parent
} else if (sldObj instanceof StyledLayer) {
parentClass = StyledLayerDescriptor.class;
} else if (sldObj instanceof Style) {
parentClass = StyledLayer.class;
} else if (sldObj instanceof FeatureTypeStyle) {
parentClass = Style.class;
} else if (sldObj instanceof Rule) {
parentClass = FeatureTypeStyle.class;
} else if (sldObj instanceof Symbolizer) {
parentClass = Rule.class;
}
internal_getMinimumVersion(parentObj, sldObj, vendorOptionsPresentList, parentClass, classSelected);
if (sldObj instanceof PointSymbolizerImpl) {
PointSymbolizerImpl pointSymbolizer = (PointSymbolizerImpl) sldObj;
parentClass = PointSymbolizerImpl.class;
classSelected = FillImpl.class;
internal_getMinimumVersion(pointSymbolizer, pointSymbolizer.getGraphic(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof LineSymbolizerImpl) {
LineSymbolizerImpl lineSymbolizer = (LineSymbolizerImpl) sldObj;
parentClass = LineSymbolizerImpl.class;
classSelected = StrokeImpl.class;
internal_getMinimumVersion(lineSymbolizer, lineSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof PolygonSymbolizerImpl) {
PolygonSymbolizerImpl polygonSymbolizer = (PolygonSymbolizerImpl) sldObj;
parentClass = PolygonSymbolizerImpl.class;
classSelected = FillImpl.class;
internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getFill(), vendorOptionsPresentList, parentClass, classSelected);
classSelected = StrokeImpl.class;
internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof TextSymbolizerImpl) {
TextSymbolizerImpl textSymbolizer = (TextSymbolizerImpl) sldObj;
parentClass = Rule.class;
classSelected = TextSymbolizerImpl.class;
internal_getMinimumVersion(parentObj, textSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof RasterSymbolizerImpl) {
RasterSymbolizerImpl rasterSymbolizer = (RasterSymbolizerImpl) sldObj;
parentClass = Rule.class;
classSelected = RasterSymbolizerImpl.class;
internal_getMinimumVersion(parentObj, rasterSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
}
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class PointSymbolizerDetails method populate.
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
*/
@Override
public void populate(SelectedSymbol selectedSymbol) {
if (selectedSymbol != null) {
Symbolizer symbolizer = selectedSymbol.getSymbolizer();
populateStandardData(symbolizer);
fieldConfigVisitor.populateField(FieldIdEnum.GEOMETRY, symbolizer.getGeometry());
}
updateSymbol();
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class RasterSymbolizerDetails method updateSymbol.
/**
* Update symbol.
*/
private void updateSymbol() {
// Contrast enhancement
Expression gammaValueExpression = fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_CONTRAST_GAMMAVALUE);
ContrastEnhancement contrastEnhancement = null;
GroupConfigInterface group = getGroup(GroupIdEnum.RASTER_CONTRAST);
if (group.isPanelEnabled()) {
String method = null;
group = getGroup(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD);
if (group != null) {
MultiOptionGroup contrastNormalizeMethodGroup = (MultiOptionGroup) group;
OptionGroup selectedOption = contrastNormalizeMethodGroup.getSelectedOptionGroup();
if (selectedOption != null) {
method = selectedOption.getLabel();
}
}
contrastEnhancement = (ContrastEnhancement) getStyleFactory().contrastEnhancement(gammaValueExpression, method);
}
// Colour map
ColorMap colorMap = fieldConfigVisitor.getColourMap(FieldIdEnum.RASTER_COLOURMAP);
ValueComboBoxData colourMapType = fieldConfigVisitor.getComboBox(FieldIdEnum.RASTER_COLOURMAP_TYPE);
colorMap.setType(Integer.valueOf(colourMapType.getKey()));
// Channel selection
ChannelSelection channelSelection = null;
group = getGroup(GroupIdEnum.RASTER_CHANNELSELECTION);
if (group != null) {
if (group.isPanelEnabled()) {
MultiOptionGroup contrastEnhancementGroup = (MultiOptionGroup) group;
OptionGroup selectedOption = contrastEnhancementGroup.getSelectedOptionGroup();
if (selectedOption.getId() == GroupIdEnum.RASTER_GREY_CHANNEL_OPTION) {
// Grey option group
SelectedChannelType greyChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_GREY_CHANNEL, FieldIdEnum.RASTER_RGB_GREY_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST_METHOD);
channelSelection = getStyleFactory().channelSelection(greyChannel);
} else {
SelectedChannelType redChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_RGB_CHANNEL_RED, FieldIdEnum.RASTER_RGB_RED_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST_METHOD);
SelectedChannelType greenChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_RGB_CHANNEL_GREEN, FieldIdEnum.RASTER_RGB_GREEN_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_GREEN_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_GREEN_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_GREEN_CONTRAST_METHOD);
SelectedChannelType blueChannel = extractContrastEnhancementGroup(GroupIdEnum.RASTER_RGB_CHANNEL_BLUE, FieldIdEnum.RASTER_RGB_BLUE_NAME, GroupIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST, FieldIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST_GAMMA, GroupIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST_METHOD);
SelectedChannelType[] channels = new SelectedChannelType[3];
channels[0] = redChannel;
channels[1] = greenChannel;
channels[2] = blueChannel;
channelSelection = getStyleFactory().createChannelSelection(channels);
}
}
}
//
// Overlap
//
OverlapBehavior overlapBehavior = null;
group = getGroup(GroupIdEnum.RASTER_OVERLAP);
if (group.isPanelEnabled()) {
ValueComboBoxData overlapBehaviorValue = fieldConfigVisitor.getComboBox(FieldIdEnum.RASTER_OVERLAP_BEHAVIOUR);
overlapBehavior = OverlapBehavior.valueOf(overlapBehaviorValue.getKey());
}
//
// Shaded relief
//
ShadedRelief shadedRelief = null;
group = getGroup(GroupIdEnum.RASTER_SHADEDRELIEF);
if (group.isPanelEnabled()) {
shadedRelief = new ShadedReliefImpl();
shadedRelief.setBrightnessOnly(fieldConfigVisitor.getBoolean(FieldIdEnum.RASTER_SHADEDRELIEF_BRIGHTNESS));
shadedRelief.setReliefFactor(fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_SHADEDRELIEF_FACTOR));
}
Symbolizer symbolizer = null;
StandardData standardData = getStandardData();
Expression opacityExpression = fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_OPACITY);
// Geometry field
Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);
RasterSymbolizer rasterSymbolizer = (RasterSymbolizer) getStyleFactory().rasterSymbolizer(standardData.name, geometryField, standardData.description, standardData.unit, opacityExpression, channelSelection, overlapBehavior, colorMap, contrastEnhancement, shadedRelief, symbolizer);
if (vendorOptionRasterFactory != null) {
vendorOptionRasterFactory.updateSymbol(rasterSymbolizer);
}
rasterSymbolizer.setOverlapBehavior(overlapBehavior);
SelectedSymbol.getInstance().replaceSymbolizer(rasterSymbolizer);
this.fireUpdateSymbol();
}
use of org.geotools.styling.Symbolizer in project polymap4-core by Polymap4.
the class StyleCompositeSerializer method defaultFeatureTypeStyle.
protected FeatureTypeStyle defaultFeatureTypeStyle(org.geotools.styling.Style result, Style style, Symbolizer... symbolizers) {
Rule rule = sf.createRule();
// handle visibleIf
FilterStyleProperty visibleIf = (FilterStyleProperty) style.visibleIf.get();
if (visibleIf instanceof ScaleRangeFilter) {
rule.setMinScaleDenominator(((ScaleRangeFilter) visibleIf).minScale.get());
rule.setMaxScaleDenominator(((ScaleRangeFilter) visibleIf).maxScale.get());
} else if (visibleIf instanceof ConstantFilter) {
Filter filter = ((ConstantFilter) visibleIf).filter();
if (!filter.equals(Filter.INCLUDE)) {
rule.setFilter(filter);
}
} else {
throw new RuntimeException("Unhandled Style.visibleIf type: " + visibleIf.getClass());
}
for (Symbolizer s : symbolizers) {
rule.symbolizers().add(s);
}
;
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(rule);
result.featureTypeStyles().add(fts);
return fts;
}
use of org.geotools.styling.Symbolizer in project hale by halestudio.
the class DefinitionImages method getLegendImage.
/**
* Get a legend image for a given type definition
*
* @param type the type definition
* @param dataSet the data set the type definition belongs to
* @param definedOnly if only for defined styles a image shall be created
* @return the legend image or <code>null</code>
*/
protected BufferedImage getLegendImage(TypeDefinition type, DataSet dataSet, boolean definedOnly) {
StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
Style style = (definedOnly) ? (ss.getDefinedStyle(type)) : (ss.getStyle(type, dataSet));
if (style == null) {
return null;
}
// create a dummy feature based on the style
Drawer d = Drawer.create();
SimpleFeature feature = null;
Symbolizer[] symbolizers = SLD.symbolizers(style);
if (symbolizers.length > 0) {
Symbolizer symbolizer = symbolizers[0];
if (symbolizer instanceof LineSymbolizer) {
feature = d.feature(d.line(LINE_POINTS));
} else if (symbolizer instanceof PointSymbolizer) {
feature = d.feature(d.point(WIDTH / 2, HEIGHT / 2));
}
if (symbolizer instanceof PolygonSymbolizer) {
feature = d.feature(d.polygon(POLY_POINTS));
}
}
if (feature != null) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
// GraphicsEnvironment.getLocalGraphicsEnvironment().
// getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(WIDTH, HEIGHT,
// Transparency.TRANSLUCENT);
// use white background to have a neutral color even if selected
Color bg = Color.WHITE;
Graphics2D g = image.createGraphics();
try {
g.setColor(bg);
g.fillRect(0, 0, WIDTH, HEIGHT);
} finally {
g.dispose();
}
d.drawDirect(image, feature, style);
return image;
}
return null;
}
Aggregations