use of org.geotools.styling.PointSymbolizer in project polymap4-core by Polymap4.
the class DefaultStyles method createPointStyle.
/**
* Create a Style to draw point features as circles with blue outlines
* and cyan fill
*/
public static Style createPointStyle(Style style) {
Graphic gr = sf.createDefaultGraphic();
Mark mark = sf.getCircleMark();
mark.setStroke(sf.createStroke(ff.literal(Color.RED), ff.literal(1.5)));
mark.setFill(sf.createFill(ff.literal(Color.YELLOW)));
gr.graphicalSymbols().clear();
gr.graphicalSymbols().add(mark);
gr.setSize(ff.literal(8));
/*
* Setting the geometryPropertyName arg to null signals that we want to draw
* the default geometry of features
*/
PointSymbolizer sym = sf.createPointSymbolizer(gr, null);
Rule rule = sf.createRule();
rule.symbolizers().add(sym);
rule.setName("Rule for PointSymbolizer");
style.featureTypeStyles().get(0).rules().add(rule);
return style;
}
use of org.geotools.styling.PointSymbolizer in project polymap4-core by Polymap4.
the class FilterTest method visiblePoint.
@Test
public void visiblePoint() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
// point
PointStyle point = fs.members().createElement(PointStyle.defaults);
assertTrue(point.visibleIf.get() instanceof ConstantFilter);
point.visibleIf.createValue(initializeFilter(ff.equals(ff.property("prop"), ff.literal("literal"))));
point.diameter.createValue(ConstantNumber.defaults(23.0));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
org.geotools.styling.Style style = repo.serializedFeatureStyle(fs.id(), org.geotools.styling.Style.class).get();
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
assertTrue(rule.getFilter() instanceof PropertyIsEqualTo);
PropertyIsEqualTo filter = (PropertyIsEqualTo) rule.getFilter();
assertTrue(filter.getExpression1() instanceof PropertyName);
assertEquals("prop", ((PropertyName) filter.getExpression1()).getPropertyName());
assertTrue(filter.getExpression2() instanceof Literal);
assertEquals("literal", ((Literal) filter.getExpression2()).getValue());
PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
use of org.geotools.styling.PointSymbolizer in project polymap4-core by Polymap4.
the class StyleModelTest method testScaleMappedNumbers.
@Test
public void testScaleMappedNumbers() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
PointStyle point = fs.members().createElement(PointStyle.defaults);
point.diameter.createValue(ScaleMappedPrimitives.defaults()).add(0, 1, new Double(1)).add(1, 2, new Double(2)).add(2, Double.POSITIVE_INFINITY, new Double(3));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
assertEquals(1, result.featureTypeStyles().size());
FeatureTypeStyle fts = result.featureTypeStyles().get(0);
assertEquals(3, fts.rules().size());
assertEqualsLiteral(1.0, ((PointSymbolizer) fts.rules().get(0).symbolizers().get(0)).getGraphic().getSize());
assertEqualsLiteral(2.0, ((PointSymbolizer) fts.rules().get(1).symbolizers().get(0)).getGraphic().getSize());
assertEqualsLiteral(3.0, ((PointSymbolizer) fts.rules().get(2).symbolizers().get(0)).getGraphic().getSize());
}
use of org.geotools.styling.PointSymbolizer 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;
}
use of org.geotools.styling.PointSymbolizer in project hale by halestudio.
the class StyleServiceImpl method getSelectionSymbolizers.
/**
* Get the symbolizers representing the given symbolizer for a selection
*
* @param symbolizer the symbolizer
*
* @return the selection symbolizers
*/
private List<Symbolizer> getSelectionSymbolizers(Symbolizer symbolizer) {
List<Symbolizer> result = new ArrayList<Symbolizer>();
Color color = StylePreferences.getSelectionColor();
int width = StylePreferences.getSelectionWidth();
if (symbolizer instanceof PolygonSymbolizer) {
result.add(StyleHelper.createPolygonSymbolizer(color, width));
} else if (symbolizer instanceof LineSymbolizer) {
result.add(StyleHelper.createLineSymbolizer(color, width));
} else if (symbolizer instanceof PointSymbolizer) {
result.add(StyleHelper.mutatePointSymbolizer((PointSymbolizer) symbolizer, color, width));
// result.add(createPointSymbolizer(color, width));
} else {
// do not fall-back to original symbolizer cause we are painting
// over it
// result.add(symbolizer);
}
return result;
}
Aggregations