Search in sources :

Example 16 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class PortrayalDemo method createContext.

private static MapLayers createContext() throws DataStoreException, URISyntaxException {
    // create a map context
    final MapLayers context = MapBuilder.createContext();
    // create a feature layer
    final FeatureSet features = openShapeFile();
    final MutableStyle featureStyle = SF.style(StyleConstants.DEFAULT_LINE_SYMBOLIZER);
    final MapLayer featureLayer = MapBuilder.createLayer(features);
    featureLayer.setStyle(featureStyle);
    // create a coverage layer
    // final GridCoverageResource reader = openWorldFile();
    // final MutableStyle coverageStyle = SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER);
    // final CoverageMapLayer coverageLayer = MapBuilder.createCoverageLayer(reader, 0, coverageStyle,"background");
    // add all layers in the context
    // context.layers().add(coverageLayer);
    context.getComponents().add(featureLayer);
    return context;
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) MapLayer(org.apache.sis.portrayal.MapLayer) FeatureSet(org.apache.sis.storage.FeatureSet) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 17 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class ReportDemo method main.

public static void main(String[] args) throws Exception {
    Demos.init();
    final InputStream template = ReportDemo.class.getResourceAsStream("/data/report/complexReport.jrxml");
    final Entry<JasperReport, FeatureType> entry = JasperReportService.prepareTemplate(template);
    final JasperReport report = entry.getKey();
    final FeatureType type = entry.getValue();
    System.out.println(type);
    // source to make an atlas ----------------------------------------------------
    final FeatureStore store = (FeatureStore) DataStores.open((Map) Collections.singletonMap("path", ReportDemo.class.getResource("/data/world/Countries.shp").toURI()));
    final GenericName name = store.getNames().iterator().next();
    final FeatureCollection countries = store.createSession(true).getFeatureCollection(new Query(name));
    // Iterator over all the countries --------------------------------------------
    final FeatureIterator ite = countries.iterator();
    // We map the feature type to the report type ---------------------------------
    final GenericMappingFeatureIterator mapped = new GenericMappingFeatureIterator(ite, new FeatureMapper() {

        @Override
        public FeatureType getSourceType() {
            return countries.getType();
        }

        @Override
        public FeatureType getTargetType() {
            return type;
        }

        @Override
        public Feature transform(Feature feature) {
            final Feature modified = type.newInstance();
            // create the main map with a single feature ------------------
            final FeatureCollection col = FeatureStoreUtilities.collection(feature);
            final MapLayers context = MapBuilder.createContext();
            final MutableStyle style = RandomStyleBuilder.createRandomVectorStyle(col.getType());
            final MapLayer layer = MapBuilder.createLayer(col);
            layer.setStyle(style);
            context.getComponents().add(layer);
            try {
                // add a custom decoration on our map.
                final GridTemplate gridTemplate = new DefaultGridTemplate(CommonCRS.WGS84.normalizedGeographic(), new BasicStroke(1.5f), new Color(120, 120, 120, 200), new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3, new float[] { 5, 5 }, 0), new Color(120, 120, 120, 60), new Font("serial", Font.BOLD, 12), Color.GRAY, 0, Color.WHITE, new Font("serial", Font.ITALIC, 10), Color.GRAY, 0, Color.WHITE);
                final PortrayalExtension ext = new PortrayalExtension() {

                    @Override
                    public void completeCanvas(J2DCanvas canvas) throws PortrayalException {
                        canvas.getContainer().getRoot().getChildren().add(new GraphicGridJ2D(canvas, gridTemplate));
                    }
                };
                final CanvasDef canvasDef = new CanvasDef(new Dimension(1, 1), null);
                canvasDef.setBackground(Color.WHITE);
                canvasDef.setStretchImage(false);
                canvasDef.setEnvelope(Envelopes.transform(context.getEnvelope().get(), CRS.forCode("EPSG:3395")));
                final SceneDef sceneDef = new SceneDef(context, null, ext);
                final MapDef mapdef = new MapDef(canvasDef, sceneDef, null);
                modified.setPropertyValue("map3", mapdef);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            // casual attributs -------------------
            modified.setPropertyValue("CNTRY_NAME", feature.getProperty("CNTRY_NAME").getValue());
            modified.setPropertyValue("POP_CNTRY", feature.getProperty("POP_CNTRY").getValue());
            // chart -------------------------
            final DefaultPieDataset pds = new DefaultPieDataset();
            pds.setValue((Comparable) feature.getProperty("SOVEREIGN").getValue(), Math.random());
            pds.setValue((Comparable) feature.getProperty("ISO_3DIGIT").getValue(), Math.random());
            final JFreeChart chart = ChartFactory.createPieChart("Info", pds, true, true, Locale.FRENCH);
            modified.setPropertyValue("chart4", new ChartDef(chart));
            // legend --------------------------
            modified.setPropertyValue("legend5", new LegendDef());
            // scale bar -------------------
            modified.setPropertyValue("scalebar6", new ScaleBarDef());
            // north arow -------------------
            modified.setPropertyValue("northarrow7", new NorthArrowDef());
            // subtable --------------
            final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
            ftb.setName("subdata");
            ftb.addAttribute(Integer.class).setName("men");
            ftb.addAttribute(Integer.class).setName("women");
            ftb.addAttribute(String.class).setName("desc");
            final FeatureType subType = ftb.build();
            final FeatureCollection subcol = FeatureStoreUtilities.collection("sub", subType);
            try {
                FeatureWriter fw = subcol.getSession().getFeatureStore().getFeatureWriter(Query.filtered(subType.getName().toString(), Filter.exclude()));
                for (int i = 0, n = new Random().nextInt(20); i < n; i++) {
                    Feature f = fw.next();
                    f.setPropertyValue("men", new Random().nextInt());
                    f.setPropertyValue("women", new Random().nextInt());
                    f.setPropertyValue("desc", "some text from attribut");
                    fw.write();
                }
                fw.close();
            } catch (DataStoreException ex) {
                ex.printStackTrace();
            }
            modified.setPropertyValue("table8", new CollectionDataSource(subcol));
            return modified;
        }
    });
    // Generate the report --------------------------------------------------------
    final OutputDef output = new OutputDef(JasperReportService.MIME_PDF, new File("atlas.pdf"));
    JasperReportService.generateReport(report, mapped, null, output);
}
Also used : BasicStroke(java.awt.BasicStroke) FeatureType(org.opengis.feature.FeatureType) FeatureWriter(org.geotoolkit.storage.feature.FeatureWriter) Query(org.geotoolkit.storage.feature.query.Query) ScaleBarDef(org.geotoolkit.report.graphic.scalebar.ScaleBarDef) MapLayer(org.apache.sis.portrayal.MapLayer) LegendDef(org.geotoolkit.report.graphic.legend.LegendDef) CollectionDataSource(org.geotoolkit.report.CollectionDataSource) JasperReport(net.sf.jasperreports.engine.JasperReport) DefaultGridTemplate(org.geotoolkit.display2d.ext.grid.DefaultGridTemplate) GridTemplate(org.geotoolkit.display2d.ext.grid.GridTemplate) Feature(org.opengis.feature.Feature) Font(java.awt.Font) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) GenericMappingFeatureIterator(org.geotoolkit.storage.memory.GenericMappingFeatureIterator) GenericName(org.opengis.util.GenericName) MutableStyle(org.geotoolkit.style.MutableStyle) Random(java.util.Random) SceneDef(org.geotoolkit.display2d.service.SceneDef) MapDef(org.geotoolkit.report.graphic.map.MapDef) PortrayalExtension(org.geotoolkit.display2d.service.PortrayalExtension) FeatureMapper(org.geotoolkit.storage.memory.mapping.FeatureMapper) J2DCanvas(org.geotoolkit.display2d.canvas.J2DCanvas) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) ChartDef(org.geotoolkit.report.graphic.chart.ChartDef) GraphicGridJ2D(org.geotoolkit.display2d.ext.grid.GraphicGridJ2D) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) DataStoreException(org.apache.sis.storage.DataStoreException) InputStream(java.io.InputStream) DefaultGridTemplate(org.geotoolkit.display2d.ext.grid.DefaultGridTemplate) Color(java.awt.Color) GenericMappingFeatureIterator(org.geotoolkit.storage.memory.GenericMappingFeatureIterator) Dimension(java.awt.Dimension) NorthArrowDef(org.geotoolkit.report.graphic.northarrow.NorthArrowDef) PortrayalException(org.geotoolkit.display.PortrayalException) DataStoreException(org.apache.sis.storage.DataStoreException) JFreeChart(org.jfree.chart.JFreeChart) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) OutputDef(org.geotoolkit.display2d.service.OutputDef) Map(java.util.Map) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) File(java.io.File) MapLayers(org.apache.sis.portrayal.MapLayers) PortrayalException(org.geotoolkit.display.PortrayalException)

Example 18 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class Styles method graphicFillLine.

public static MutableStyle graphicFillLine() throws URISyntaxException {
    // general informations
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    final Expression offset = LITERAL_ONE_FLOAT;
    // the stroke fill
    // a pattern that will be repeated like a mosaic
    final Expression size = FF.literal(12);
    final Expression opacity = LITERAL_ONE_FLOAT;
    final Expression rotation = LITERAL_ONE_FLOAT;
    final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
    final Displacement disp = DEFAULT_DISPLACEMENT;
    final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    final Stroke fillStroke = SF.stroke(Color.BLACK, 2);
    final Fill fill = SF.fill(Color.RED);
    final Mark mark = SF.mark(MARK_CIRCLE, fill, fillStroke);
    symbols.add(mark);
    final GraphicFill graphicfill = SF.graphicFill(symbols, opacity, size, rotation, anchor, disp);
    // the visual element
    final Expression color = SF.literal(Color.BLUE);
    final Expression width = FF.literal(4);
    final Expression linecap = STROKE_CAP_ROUND;
    final Expression linejoin = STROKE_JOIN_BEVEL;
    final float[] dashes = new float[] { 8, 4, 2, 2, 2, 2, 2, 4 };
    final Expression dashOffset = LITERAL_ZERO_FLOAT;
    final Stroke stroke = SF.stroke(graphicfill, color, opacity, width, linejoin, linecap, dashes, dashOffset);
    final LineSymbolizer symbolizer = SF.lineSymbolizer(name, geometry, desc, unit, stroke, offset);
    final MutableStyle style = SF.style(symbolizer);
    return style;
}
Also used : Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) Fill(org.opengis.style.Fill) GraphicFill(org.opengis.style.GraphicFill) Description(org.opengis.style.Description) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) ExternalMark(org.opengis.style.ExternalMark) Mark(org.opengis.style.Mark) Unit(javax.measure.Unit) Displacement(org.opengis.style.Displacement) AnchorPoint(org.opengis.style.AnchorPoint) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) GraphicFill(org.opengis.style.GraphicFill) LineSymbolizer(org.opengis.style.LineSymbolizer)

Example 19 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class Styles method defaultPolygon.

// ////////////////////////////////////////////////////////////////////
// POLYGON SYMBOLIZER ////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
public static MutableStyle defaultPolygon() {
    final PolygonSymbolizer symbol = DEFAULT_POLYGON_SYMBOLIZER;
    final MutableStyle style = SF.style(symbol);
    return style;
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer)

Example 20 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class Styles method centeredText.

public static MutableStyle centeredText() {
    // general informations
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    final Expression label = FF.property("CNTRY_NAME");
    final Font font = SF.font(FF.literal("Arial"), FONT_STYLE_ITALIC, FONT_WEIGHT_BOLD, FF.literal(14));
    final LabelPlacement placement = SF.pointPlacement();
    final Halo halo = SF.halo(Color.WHITE, 1);
    final Fill fill = SF.fill(Color.BLUE);
    final TextSymbolizer symbol = SF.textSymbolizer(name, geometry, desc, unit, label, font, placement, halo, fill);
    final MutableStyle style = SF.style(DEFAULT_POLYGON_SYMBOLIZER, symbol);
    return style;
}
Also used : Fill(org.opengis.style.Fill) GraphicFill(org.opengis.style.GraphicFill) Description(org.opengis.style.Description) LabelPlacement(org.opengis.style.LabelPlacement) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) TextSymbolizer(org.opengis.style.TextSymbolizer) Unit(javax.measure.Unit) Font(org.opengis.style.Font) Halo(org.opengis.style.Halo)

Aggregations

MutableStyle (org.geotoolkit.style.MutableStyle)55 Expression (org.opengis.filter.Expression)20 MapLayer (org.apache.sis.portrayal.MapLayer)19 Unit (javax.measure.Unit)16 MapLayers (org.apache.sis.portrayal.MapLayers)15 Description (org.opengis.style.Description)15 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 Feature (org.opengis.feature.Feature)11 FeatureType (org.opengis.feature.FeatureType)11 Fill (org.opengis.style.Fill)11 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Stroke (org.opengis.style.Stroke)11 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)10 FeatureSet (org.apache.sis.storage.FeatureSet)10 GraphicStroke (org.opengis.style.GraphicStroke)10 PointSymbolizer (org.opengis.style.PointSymbolizer)10 BufferedImage (java.awt.image.BufferedImage)9 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)9 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9