/** TODO summary sentence for apply ... */ public void apply() { RasterSymbolizer symbolizer = (RasterSymbolizer) getContent(); StyleBuilder styleBuilder = getStyleBuilder(); double opacity = ((double) opacityScale.getSelection()) / 100; symbolizer.setOpacity(styleBuilder.literalExpression(opacity)); }
/* * https://osgeo-org.atlassian.net/browse/GEOT-5287 */ @Test public void testEmptyGeometryRendering() throws Exception { MapContent mc = new MapContent(); /* * We simulate reading empty geometries with this properties and mocking the capability to * filter, so that no filter layer is installed over our data and the empty geometry reaches * rendering code. These geometries are in EPSG:32717 because the 0,0 coordinate is in the * pole. */ File dir = new File(TestData.getResource(this, "empty-geom-rendering.properties").toURI()); PropertyDataStore dataStore = new PropertyDataStore(dir.getParentFile()) { @Override protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException { return new PropertyFeatureSource(entry, Query.ALL) { @Override protected boolean canFilter() { return true; } }; } }; /* * Set up the rendering of previous empty geometry */ StyleBuilder sb = new StyleBuilder(); Style style = sb.createStyle(sb.createPolygonSymbolizer()); Layer layer = new FeatureLayer(dataStore.getFeatureSource("empty-geom-rendering"), style); mc.addLayer(layer); StreamingRenderer sr = new StreamingRenderer(); sr.setMapContent(mc); BufferedImage img = new BufferedImage(40, 40, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = img.createGraphics(); Rectangle paintArea = new Rectangle(40, 40); // An EPSG:8357 extent on the EPSG:32717 area of application. double minx = -8929252.1; double maxx = -8708634.6; double miny = -491855.7; double maxy = -271204.3; ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope( new Rectangle2D.Double(minx, miny, maxx - minx, maxy - miny), CRS.decode("EPSG:3857")); sr.addRenderListener( new RenderListener() { public void featureRenderer(SimpleFeature feature) {} public void errorOccurred(Exception e) { errors++; } }); errors = 0; sr.paint(graphics, paintArea, referencedEnvelope); assertTrue(errors == 0); }
private static Symbolizer crossSymbolizer( final String name, final StyleBuilder builder, final int crossSize, final Color pointColor) { Mark cross = builder.createMark(name, pointColor, pointColor, 1); Graphic graphic = builder.createGraphic(null, cross, null); graphic.setSize(builder.literalExpression(crossSize)); return builder.createPointSymbolizer(graphic); }
private void quickPolygonSymbolizer() { // quickPolygonSymbolizer start StyleBuilder styleBuilder = new StyleBuilder(); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); PolygonSymbolizer polygonSymbolizer = styleBuilder.createPolygonSymbolizer(Color.BLUE); polygonSymbolizer.getFill().setOpacity(ff.literal(0.5)); // 50% blue polygonSymbolizer.setStroke(styleBuilder.createStroke(Color.BLACK, 2.0)); // will create a default feature type style and rule etc... Style style = styleBuilder.createStyle(polygonSymbolizer); // quickPolygonSymbolizer end }
/** Create the Grid Point style. */ static Style get(final GridParam params) { StyleBuilder builder = new StyleBuilder(); Symbolizer pointSymbolizer = crossSymbolizer("shape://plus", builder, CROSS_SIZE, ColorParser.toColor(params.gridColor)); Symbolizer halo = crossSymbolizer( "cross", builder, CROSS_SIZE + params.haloRadius, ColorParser.toColor(params.haloColor)); final Style style = builder.createStyle(pointSymbolizer); final List<Symbolizer> symbolizers = style.featureTypeStyles().get(0).rules().get(0).symbolizers(); symbolizers.add(0, halo); return style; }
@Test public void testRepeatedEnvelopeExpansion() throws Exception { final List<Filter> filters = new ArrayList<Filter>(); SimpleFeatureSource testSource = new CollectionFeatureSource(createLineCollection()) { @Override public SimpleFeatureCollection getFeatures(Query query) { filters.add(query.getFilter()); return super.getFeatures(query); } }; StyleBuilder sb = new StyleBuilder(); Style style20 = sb.createStyle(sb.createLineSymbolizer(20)); Style style10 = sb.createStyle(sb.createLineSymbolizer(10)); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(testSource, style20)); mc.addLayer(new FeatureLayer(testSource, style10)); StreamingRenderer sr = new StreamingRenderer(); sr.setMapContent(mc); BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = bi.createGraphics(); sr.paint( graphics, new Rectangle(0, 0, 100, 100), new ReferencedEnvelope(0, 100, 0, 100, DefaultGeographicCRS.WGS84)); graphics.dispose(); System.out.println(filters); assertEquals(2, filters.size()); Filter f1 = filters.get(0); assertTrue(f1 instanceof BBOX); BoundingBox bbox1 = ((BBOX) f1).getBounds(); ReferencedEnvelope expected = new ReferencedEnvelope(-11, 111, -11, 111, DefaultGeographicCRS.WGS84); assertEquals(expected, bbox1); Filter f2 = filters.get(1); assertTrue(f2 instanceof BBOX); BoundingBox bbox2 = ((BBOX) f2).getBounds(); assertEquals(new ReferencedEnvelope(-6, 106, -6, 106, DefaultGeographicCRS.WGS84), bbox2); }
private void splatExample() { // splatExample start StyleBuilder builder = new StyleBuilder(); FilterFactory2 ff = builder.getFilterFactory(); Graphic splat = builder.createGraphic(null, builder.createMark("splat"), null); PointSymbolizer symbolizer = builder.createPointSymbolizer(splat); // builder will fill in all the other classes with defaults Style style = builder.createStyle(symbolizer); // splatExample end }
public static Symbolizer[] getSymbolizers( Class<? extends Geometry> type, Color baseColor, boolean useTransparency) { StyleBuilder builder = new StyleBuilder(); Symbolizer[] syms = new Symbolizer[1]; if (LineString.class.isAssignableFrom(type) || MultiLineString.class.isAssignableFrom(type)) syms[0] = builder.createLineSymbolizer(baseColor, 2); if (Point.class.isAssignableFrom(type) || MultiPoint.class.isAssignableFrom(type)) { PointSymbolizer point = builder.createPointSymbolizer(builder.createGraphic()); FilterFactory ff = builder.getFilterFactory(); // point.getGraphic().getMarks()[0].setSize((Expression) ff.literal(10)); point.getGraphic().setSize(ff.literal(10)); Mark mark = (Mark) point.getGraphic().graphicalSymbols().get(0); mark.setFill(builder.createFill(baseColor)); syms[0] = point; } if (Polygon.class.isAssignableFrom(type) || MultiPolygon.class.isAssignableFrom(type)) { syms[0] = builder.createPolygonSymbolizer( builder.createStroke(baseColor, 2), builder.createFill(baseColor, useTransparency ? .6 : 1.0)); } return syms; }
private void featureTypeStyleExample() { // featureTypeStyleExample start StyleBuilder styleBuilder = new StyleBuilder(); Style style = styleBuilder.createStyle(); PointSymbolizer pointSymbolizer = styleBuilder.createPointSymbolizer(); Graphic graphic = styleBuilder.createGraphic(); ExternalGraphic external = styleBuilder.createExternalGraphic("file:///C:/images/house.gif", "image/gif"); graphic.graphicalSymbols().add(external); graphic.graphicalSymbols().add(styleBuilder.createMark("circle")); pointSymbolizer.setGraphic(graphic); Rule rule = styleBuilder.createRule(pointSymbolizer); FeatureTypeStyle featureTypeStyle = styleBuilder.createFeatureTypeStyle("Feature", rule); style.featureTypeStyles().add(featureTypeStyle); // featureTypeStyleExample end }
private void quickPointSymbolizer() { // quickPointSymbolizer start // "testPoint" feature type style StyleBuilder sb = new StyleBuilder(); FilterFactory2 ff = sb.getFilterFactory(); Mark testMark = sb.createMark(sb.attributeExpression("name"), sb.createFill(Color.RED, 0.5), null); Graphic graph = sb.createGraphic( null, // An external graphics if needed new Mark[] {testMark}, // a Mark if not an external graphics null, // aSymbol ff.literal(1), // opacity ff.property("size"), // read from feature "size" attribute ff.property("rotation")); // rotation, here read into the feature PointSymbolizer aPointSymbolizer = sb.createPointSymbolizer(graph); // creation of the style Style style = sb.createStyle(aPointSymbolizer); // quickPointSymbolizer end }
private void styleBuilderExample() throws Exception { // styleBuilderExample start // // We are using the GeoTools StyleBuilder that is helpful for quickly making things StyleBuilder builder = new StyleBuilder(); FilterFactory2 ff = builder.getFilterFactory(); // RULE 1 // first rule to draw cities // define a point symbolizer representing a city Graphic city = builder.createGraphic(); city.setSize(ff.literal(10)); city.graphicalSymbols().add(builder.createExternalGraphic("file:city.svg", "svg")); // svg // preferred city.graphicalSymbols().add(builder.createExternalGraphic("file:city.png", "png")); // png next city.graphicalSymbols() .add(builder.createMark(StyleBuilder.MARK_CIRCLE, Color.BLUE, Color.BLACK, 1)); PointSymbolizer pointSymbolizer = builder.createPointSymbolizer(city, "the_geom"); Rule rule1 = builder.createRule(pointSymbolizer); rule1.setName("rule1"); rule1.getDescription().setTitle("City"); rule1.getDescription().setAbstract("Rule for drawing cities"); rule1.setFilter(ff.less(ff.property("POPULATION"), ff.literal(50000))); // // RULE 2 Default Graphic dotGraphic = builder.createGraphic(null, builder.createMark(StyleBuilder.MARK_CIRCLE), null); PointSymbolizer dotSymbolize = builder.createPointSymbolizer(dotGraphic); Rule rule2 = builder.createRule(dotSymbolize); rule2.setIsElseFilter(true); // // define feature type styles used to actually define how features are rendered Rule rules[] = new Rule[] {rule1, rule2}; FeatureTypeStyle featureTypeStyle = builder.createFeatureTypeStyle("Feature", rules); // // create a "user defined" style Style style = builder.createStyle(); style.setName("style"); style.getDescription().setTitle("User Style"); style.getDescription().setAbstract("Definition of Style"); style.featureTypeStyles().add(featureTypeStyle); // styleBuilderExample end }
public static Style createRasterStyle() { StyleBuilder sb = new StyleBuilder(); RasterSymbolizer rs = sb.createRasterSymbolizer(); Style style = sb.createStyle(rs); return style; }
private void markTestSLD() { // markTestSLD start StyleBuilder sb = new StyleBuilder(); FilterFactory ff = sb.getFilterFactory(); Style style = sb.createStyle(); style.setName("MyStyle"); // "testPoint" feature type style Mark testMark = sb.createMark(sb.attributeExpression("name"), sb.createFill(Color.RED, 0.5), null); Graphic graph = sb.createGraphic( null, new Mark[] {testMark}, null, sb.literalExpression(1), sb.attributeExpression("size"), sb.attributeExpression("rotation")); style .featureTypeStyles() .add(sb.createFeatureTypeStyle("testPoint", sb.createPointSymbolizer(graph))); // "labelPoint" feature type style AnchorPoint anchorPoint = sb.createAnchorPoint(sb.attributeExpression("X"), sb.attributeExpression("Y")); PointPlacement pointPlacement = sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0)); TextSymbolizer textSymbolizer = sb.createTextSymbolizer( sb.createFill(Color.BLACK), new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)}, sb.createHalo(), sb.attributeExpression("name"), pointPlacement, null); Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED); Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0); PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2); style .featureTypeStyles() .add( sb.createFeatureTypeStyle( "labelPoint", new Symbolizer[] {textSymbolizer, pointSymbolizer})); // markTestSLD end }
private void quickTextSymbolizer() { // quickTextSymbolizer start // "labelPoint" feature type style StyleBuilder sb = new StyleBuilder(); FilterFactory2 ff = sb.getFilterFactory(); // creation of the TextSymbolizer AnchorPoint anchorPoint = sb.createAnchorPoint(sb.attributeExpression("X"), sb.attributeExpression("Y")); PointPlacement pointPlacement = sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0)); TextSymbolizer textSymbolizer = sb.createTextSymbolizer( sb.createFill(Color.BLACK), new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)}, sb.createHalo(), sb.attributeExpression("name"), pointPlacement, null); // creation of the Point symbolizer Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED); Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0); PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2); // creation of the style Style style = sb.createStyle(); FeatureTypeStyle featureTypeStyle = sb.createFeatureTypeStyle("labelPoint", new Symbolizer[] {textSymbolizer, pointSymbolizer}); style.featureTypeStyles().add(featureTypeStyle); // creation of the style // quickTextSymbolizer end }
public void render(Graphics2D destination, Envelope bounds, IProgressMonitor monitor) throws RenderException { WMTPlugin.trace("[BasicWMTRender.render] is called"); // $NON-NLS-1$ if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.beginTask("Render WMT", 100); // $NON-NLS-1$ setState(STARTING); ILayer layer = null; try { layer = getContext().getLayer(); // assume everything will work fine layer.setStatus(ILayer.DONE); layer.setStatusMessage(""); // $NON-NLS-1$ WMTSource wmtSource = getWmtSourceFromLayer(layer); if (wmtSource == null) throw new UnsupportedOperationException(Messages.Render_Error_NoSource); // Layer properties WMTLayerProperties layerProperties = new WMTLayerProperties((StyleBlackboard) layer.getStyleBlackboard()); // Get map extent, which should be drawn ReferencedEnvelope mapExtent = getRenderBounds(); if (mapExtent == null) { mapExtent = context.getViewportModel().getBounds(); } // Scale double scale = getContext().getViewportModel().getScaleDenominator(); WMTPlugin.trace("[BasicWMTRender.render] Scale: " + scale); // $NON-NLS-1$ WMTRenderJob renderJob = null; try { renderJob = WMTRenderJob.createRenderJob(mapExtent, scale, wmtSource); } catch (Exception exc) { throw new UnsupportedOperationException(Messages.Render_Error_Projection); } // Find tiles Map<String, Tile> tileList = wmtSource.cutExtentIntoTiles( renderJob, WMTRenderJob.getScaleFactor(), false, layerProperties); // if we have nothing to display, return if (tileList.isEmpty()) { throw new UnsupportedOperationException(Messages.Render_Error_NoData); } // check if this are too many tiles if ((tileList = checkTooManyTiles(layer, wmtSource, layerProperties, renderJob, tileList)) .isEmpty()) { throw new UnsupportedOperationException(Messages.Render_Error_TooManyTiles); } // Download and display tiles // look up the preference for caching tiles on-disk or in // memory and use the proper tilerange for that. TileRange range = createTileRange(wmtSource, renderJob, tileList); // create an empty raster symbolizer for rendering RasterSymbolizer style = styleBuilder.createRasterSymbolizer(); // setup how much each tile is worth for the monitor work % int tileCount = range.getTileCount(); int tileWorth = (tileCount / 100) * tileCount; int thisid = 0; if (testing) { staticid++; thisid = staticid; } // first render any tiles that are ready and render non-ready tiles with blank images Map<String, Tile> tiles = range.getTiles(); Set<String> notRenderedTiles = new HashSet<String>(); Set<String> renderedTiles = new HashSet<String>(); renderReadyTiles( destination, monitor, renderJob, style, tileWorth, thisid, tiles, notRenderedTiles, renderedTiles); setState(RENDERING); // if the tilerange is not already completed, then load // the missing tiles if (!notRenderedTiles.isEmpty()) { renderNotRenderedTiles( destination, monitor, renderJob, range, style, tileWorth, thisid, notRenderedTiles, renderedTiles); } if (testing) { System.out.println("DONE!!!: " + thisid); // $NON-NLS-1$ } } catch (UnsupportedOperationException doneExc) { setDone(monitor); layer.setStatus(ILayer.ERROR); layer.setStatusMessage(doneExc.getMessage()); WMTPlugin.log("[BasicWMTRenderer.render] Error: ", doneExc); // $NON-NLS-1$ return; } catch (CancellationException cancelExc) { return; } catch (Exception ex) { WMTPlugin.log("[BasicWMTRenderer.render] Unexpected Error: ", ex); // $NON-NLS-1$ } setDone(monitor); }
@Test public void testScreenMapMemory() { // build a feature source with two zig-zag line occupying the same position LiteCoordinateSequence cs = new LiteCoordinateSequence(new double[] {0, 0, 1, 1, 2, 0, 3, 1, 4, 0}); SimpleFeature zigzag1 = SimpleFeatureBuilder.build( testLineFeatureType, new Object[] {gf.createLineString(cs)}, "zz1"); SimpleFeature zigzag2 = SimpleFeatureBuilder.build( testLineFeatureType, new Object[] {gf.createLineString(cs)}, "zz2"); DefaultFeatureCollection fc = new DefaultFeatureCollection(); fc.add(zigzag1); fc.add(zigzag2); SimpleFeatureSource zzSource = new CollectionFeatureSource(fc); // prepare the map MapContent mc = new MapContent(); StyleBuilder sb = new StyleBuilder(); mc.addLayer(new FeatureLayer(zzSource, sb.createStyle(sb.createLineSymbolizer()))); StreamingRenderer sr = new StreamingRenderer(); sr.setMapContent(mc); // collect rendered features final List<SimpleFeature> features = new ArrayList<SimpleFeature>(); RenderListener renderedFeaturesCollector = new RenderListener() { @Override public void featureRenderer(SimpleFeature feature) { features.add(feature); } @Override public void errorOccurred(Exception e) { // nothing to do } }; sr.addRenderListener(renderedFeaturesCollector); BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = bi.createGraphics(); // have the lines be smaller than a 1/3 of a pixel sr.paint( graphics, new Rectangle(0, 0, 1, 1), new ReferencedEnvelope(0, 8, 0, 8, DefaultGeographicCRS.WGS84)); // check we only rendered one feature assertEquals(1, features.size()); assertEquals("zz1", features.get(0).getID()); // now have the lines be big enough to be painted instead features.clear(); sr.paint( graphics, new Rectangle(0, 0, 1, 1), new ReferencedEnvelope(0, 1, 0, 1, DefaultGeographicCRS.WGS84)); assertEquals(2, features.size()); assertEquals("zz1", features.get(0).getID()); assertEquals("zz2", features.get(1).getID()); graphics.dispose(); }
private Style createPointStyle() { StyleBuilder sb = new StyleBuilder(); return sb.createStyle(sb.createPointSymbolizer()); }
private Style createRasterStyle() { StyleBuilder sb = new StyleBuilder(); return sb.createStyle(sb.createRasterSymbolizer()); }
/** * Constructs a TextSymbolizer from the inputs * * @param build * @return TextSymbolizer defined by this model */ public TextSymbolizer get(StyleBuilder build) { if (!this.enabled) { return null; } if (this.font == null || this.font.length == 0) { return null; } if (this.labelType == null || "".equals(this.labelType)) { // $NON-NLS-1$ return null; } String fontName = this.font[0].getName(); boolean fontBold = (this.font[0].getStyle() == SWT.BOLD); boolean fontItalic = (this.font[0].getStyle() == SWT.ITALIC); double fontSize = this.font[0].getHeight(); Font gtFont = build.createFont(fontName, fontItalic, fontBold, fontSize); Fill fill = build.createFill(this.colour); LabelPlacement placement; if (pointPlacement) { // PointPlacement double horiz; if (this.place.getSelectionIndex() < 3) { switch (this.place.getSelectionIndex()) { case 0: horiz = SLDs.ALIGN_LEFT; break; case 1: horiz = SLDs.ALIGN_CENTER; break; case 2: horiz = SLDs.ALIGN_RIGHT; break; default: horiz = SLDs.ALIGN_CENTER; break; } } else { // custom value horiz = Double.parseDouble(this.place.getText()); } double vert; if (this.place2.getSelectionIndex() < 3) { switch (this.place2.getSelectionIndex()) { case 0: vert = SLDs.ALIGN_BOTTOM; break; case 1: vert = SLDs.ALIGN_MIDDLE; break; case 2: vert = SLDs.ALIGN_TOP; break; default: vert = SLDs.ALIGN_MIDDLE; break; } } else { // custom value vert = Double.parseDouble(this.place2.getText()); } double rotation = Double.parseDouble(this.place3.getText()); placement = build.createPointPlacement(vert, horiz, rotation); } else { // LinePlacement double offset = Double.parseDouble(this.place.getText()); placement = build.createLinePlacement(offset); } this.labelPlacement = placement; Expression exp = (Expression) CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()) .property(this.labelType); TextSymbolizer text = build.createTextSymbolizer(fill, new Font[] {gtFont}, null, exp, placement, null); if (SLD.isLine(this.schema)) { text.addToOptions("group", "yes"); // $NON-NLS-1$ //$NON-NLS-2$ } text.addToOptions("spaceAround", "2"); // $NON-NLS-1$ //$NON-NLS-2$ return text; }