Java Code Examples for org.geotools.styling.Graphic#setSize()

The following examples show how to use org.geotools.styling.Graphic#setSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a default point style.
 *
 * @return the created style.
 */
public static Style createPointStyle() {
	final Graphic gr = styleFactory.createDefaultGraphic();
	final Mark mark = styleFactory.getCircleMark();
	mark.setStroke(styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1)));
	mark.setFill(styleFactory.createFill(filterFactory.literal(Color.CYAN)));
	gr.graphicalSymbols().clear();
	gr.graphicalSymbols().add(mark);
	gr.setSize(filterFactory.literal(5));
	/*
	 * Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
	 */
	final PointSymbolizer sym = styleFactory.createPointSymbolizer(gr, null);

	final Rule rule = styleFactory.createRule();
	rule.symbolizers().add(sym);
	final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
	final Style style = styleFactory.createStyle();
	style.featureTypeStyles().add(fts);

	return style;
}
 
Example 2
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a default {@link Rule} for a point.
 * 
 * @return the default rule.
 */
public static Rule createDefaultPointRule() {
    Graphic graphic = sf.createDefaultGraphic();
    Mark circleMark = sf.getCircleMark();
    circleMark.setFill(sf.createFill(ff.literal("#" + Integer.toHexString(Color.RED.getRGB() & 0xffffff))));
    circleMark.setStroke(sf.createStroke(ff.literal("#" + Integer.toHexString(Color.BLACK.getRGB() & 0xffffff)),
            ff.literal(DEFAULT_WIDTH)));
    graphic.graphicalSymbols().clear();
    graphic.graphicalSymbols().add(circleMark);
    graphic.setSize(ff.literal(DEFAULT_SIZE));

    PointSymbolizer pointSymbolizer = sf.createPointSymbolizer();
    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(pointSymbolizer);

    pointSymbolizer.setGraphic(graphic);
    return rule;
}
 
Example 3
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPointStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    org.opengis.filter.FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

    final Mark mark = styleFactory.getCircleMark();
    mark.setStroke(styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1)));
    mark.setFill(styleFactory.createFill(filterFactory.literal(Color.CYAN)));

    final Graphic gr = styleFactory.getDefaultGraphic();
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(mark);
    gr.setSize(filterFactory.literal(5));

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PointSymbolizer sym = styleFactory.createPointSymbolizer(gr, null);

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Point Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example 4
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Changes the size of a mark inside a rule.
 * 
 * @param rule the {@link Rule}.
 * @param newSize the new size.
 */
public static void changeMarkSize( Rule rule, int newSize ) {
    PointSymbolizer pointSymbolizer = StyleUtilities.pointSymbolizerFromRule(rule);
    Graphic graphic = SLD.graphic(pointSymbolizer);
    graphic.setSize(ff.literal(newSize));
    // Mark oldMark = SLDs.mark(pointSymbolizer);
    // oldMark.setSize(ff.literal(newSize));
    // Graphic graphic = SLDs.graphic(pointSymbolizer);
}
 
Example 5
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a style based on a graphic.
 * 
 * @param graphicsPath the graphic.
 * @return the generated style.
 * @throws IOException
 */
public static StyleWrapper createStyleFromGraphic( File graphicsPath ) throws IOException {
    String name = graphicsPath.getName();
    ExternalGraphic exGraphic = null;
    if (name.toLowerCase().endsWith(".png")) {
        exGraphic = sf.createExternalGraphic(graphicsPath.toURI().toURL(), "image/png");
    } else if (name.toLowerCase().endsWith(".svg")) {
        exGraphic = sf.createExternalGraphic(graphicsPath.toURI().toURL(), "image/svg+xml");
    } else if (name.toLowerCase().endsWith(".sld")) {
        StyledLayerDescriptor sld = readStyle(graphicsPath);
        Style style = SldUtilities.getDefaultStyle(sld);
        return new StyleWrapper(style);
    }

    if (exGraphic == null) {
        throw new IOException("Style could not be created!");
    }

    Graphic gr = sf.createDefaultGraphic();
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(exGraphic);
    Expression size = ff.literal(20);
    gr.setSize(size);

    Rule rule = sf.createRule();
    PointSymbolizer pointSymbolizer = sf.createPointSymbolizer(gr, null);
    rule.symbolizers().add(pointSymbolizer);

    FeatureTypeStyle featureTypeStyle = sf.createFeatureTypeStyle();
    featureTypeStyle.rules().add(rule);

    Style namedStyle = sf.createStyle();
    namedStyle.featureTypeStyles().add(featureTypeStyle);
    namedStyle.setName(FilenameUtils.removeExtension(name));

    return new StyleWrapper(namedStyle);
}
 
Example 6
Source File: SymbolizerWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the fill's {@link ExternalGraphic} path.
 * 
 * <p>Currently one {@link ExternalGraphic} per {@link Symbolizer} is supported.
 * 
 * <p>This is used for polygons.
 * 
 * @param externalGraphicPath the path to set.
 * @throws MalformedURLException
 */
public void setFillExternalGraphicFillPath( String externalGraphicPath, double size ) throws MalformedURLException {
    Graphic graphic = null;
    PolygonSymbolizerWrapper polygonSymbolizerWrapper = adapt(PolygonSymbolizerWrapper.class);
    if (polygonSymbolizerWrapper != null) {
        graphic = polygonSymbolizerWrapper.getFillGraphicFill();
        if (graphic == null) {
            graphic = sf.createDefaultGraphic();
        }
        polygonSymbolizerWrapper.setFillGraphicFill(graphic);
    } else {
        return;
    }
    graphic.graphicalSymbols().clear();
    String urlStr = externalGraphicPath;
    if (!externalGraphicPath.startsWith("http:") && !externalGraphicPath.startsWith("file:")) { //$NON-NLS-1$ //$NON-NLS-2$
        urlStr = "file:" + externalGraphicPath; //$NON-NLS-1$
    }
    if (fillExternalGraphicFill == null) {
        fillExternalGraphicFill = sb.createExternalGraphic(new URL(urlStr), getFormat(externalGraphicPath));
    } else {
        setExternalGraphicPath(externalGraphicPath, fillExternalGraphicFill);
    }
    graphic.graphicalSymbols().add(fillExternalGraphicFill);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    graphic.setSize(ff.literal(size));
}
 
Example 7
Source File: DefaultSymbols.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the arrow.
 *
 * @param angleFunction the angle function
 * @param locationFunction the location function
 * @param markerSymbol the marker symbol
 * @param isSourceArrow the is source arrow
 * @return the point symbolizer
 */
private static PointSymbolizer createArrow(
        FunctionName angleFunction,
        FunctionName locationFunction,
        String markerSymbol,
        boolean isSourceArrow) {
    String name =
            isSourceArrow
                    ? Localisation.getString(SLDTreeTools.class, "TreeItem.sourceArrow")
                    : Localisation.getString(SLDTreeTools.class, "TreeItem.destArrow");

    PointSymbolizer pointSymbolizer = createDefaultPointSymbolizer();

    pointSymbolizer.setName(name);
    Graphic graphic = pointSymbolizer.getGraphic();
    graphic.setSize(ff.literal(DEFAULT_ARROW_SIZE));
    List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
    MarkImpl mark = (MarkImpl) graphicalSymbolList.get(0);

    Expression wellKnownName = ff.literal(markerSymbol);
    mark.setWellKnownName(wellKnownName);

    mark.getFill().setColor(ff.literal(DEFAULT_COLOUR));

    // Arrow rotation
    List<Expression> rotationArgumentList = new ArrayList<>();

    String geometryFieldName = "geom";
    DataSourceInterface dsInfo = DataSourceFactory.getDataSource();
    if (dsInfo != null) {
        geometryFieldName = dsInfo.getGeometryFieldName();
    }
    rotationArgumentList.add(ff.property(geometryFieldName));

    Expression rotation =
            FunctionManager.getInstance().createExpression(angleFunction, rotationArgumentList);
    if (isSourceArrow) {
        graphic.setRotation(ff.add(ff.literal(DEGREES_180), rotation));
    } else {
        graphic.setRotation(rotation);
    }

    AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0.5), ff.literal(0.5));
    graphic.setAnchorPoint(anchorPoint);

    // Set location of the arrow head
    List<Expression> endPointArgumentList = new ArrayList<>();
    endPointArgumentList.add(ff.property(geometryFieldName));

    Expression geometry =
            FunctionManager.getInstance()
                    .createExpression(locationFunction, endPointArgumentList);
    pointSymbolizer.setGeometry(geometry);

    return pointSymbolizer;
}
 
Example 8
Source File: OmsMapsViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void addFeatureCollections( MapContent map ) throws Exception {
    if (inVectors == null) {
        return;
    }
    for( String path : inVectors ) {
        SimpleFeatureCollection fc = OmsVectorReader.readVector(path);
        GeometryDescriptor geometryDescriptor = fc.getSchema().getGeometryDescriptor();
        EGeometryType type = EGeometryType.forGeometryDescriptor(geometryDescriptor);

        File file = new File(path);
        Style style = SldUtilities.getStyleFromFile(file);

        switch( type ) {
        case MULTIPOLYGON:
        case POLYGON:
            if (style == null) {
                Stroke polygonStroke = sf.createStroke(ff.literal(Color.BLUE), ff.literal(2));
                Fill polygonFill = sf.createFill(ff.literal(Color.BLUE), ff.literal(0.0));

                Rule polygonRule = sf.createRule();
                PolygonSymbolizer polygonSymbolizer = sf.createPolygonSymbolizer(polygonStroke, polygonFill, null);
                polygonRule.symbolizers().add(polygonSymbolizer);

                FeatureTypeStyle polygonFeatureTypeStyle = sf.createFeatureTypeStyle();
                polygonFeatureTypeStyle.rules().add(polygonRule);

                style = sf.createStyle();
                style.featureTypeStyles().add(polygonFeatureTypeStyle);
                style.setName("polygons");
            }
            break;
        case MULTIPOINT:
        case POINT:
            if (style == null) {
                Mark circleMark = sf.getCircleMark();
                Fill fill = sf.createFill(ff.literal(Color.RED));
                circleMark.setFill(fill);
                // circleMark.setStroke(null);

                Graphic gr = sf.createDefaultGraphic();
                gr.graphicalSymbols().clear();
                gr.graphicalSymbols().add(circleMark);
                Expression size = ff.literal(6);
                gr.setSize(size);

                Rule pointRule = sf.createRule();
                PointSymbolizer pointSymbolizer = sf.createPointSymbolizer(gr, null);
                pointRule.symbolizers().add(pointSymbolizer);

                FeatureTypeStyle pointsFeatureTypeStyle = sf.createFeatureTypeStyle();
                pointsFeatureTypeStyle.rules().add(pointRule);

                style = sf.createStyle();
                style.featureTypeStyles().add(pointsFeatureTypeStyle);
                style.setName("points");
            }
            break;
        case MULTILINESTRING:
        case LINESTRING:
            if (style == null) {
                Stroke lineStroke = sf.createStroke(ff.literal(Color.RED), ff.literal(2));

                Rule lineRule = sf.createRule();
                LineSymbolizer lineSymbolizer = sf.createLineSymbolizer(lineStroke, null);
                lineRule.symbolizers().add(lineSymbolizer);

                FeatureTypeStyle lineFeatureTypeStyle = sf.createFeatureTypeStyle();
                lineFeatureTypeStyle.rules().add(lineRule);

                style = sf.createStyle();
                style.featureTypeStyles().add(lineFeatureTypeStyle);
                style.setName("lines");
            }
            break;

        default:
            break;
        }

        FeatureLayer layer = new FeatureLayer(fc, style);
        map.addLayer(layer);

    }

}