Search in sources :

Example 1 with ExternalGraphic

use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.

the class CharacterMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the marker graphic
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markerList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT);
    if (fontElement != null) {
        JsonObject fontObj = fontElement.getAsJsonObject();
        String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
        int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX);
        Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code));
        // Create colour
        Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR));
        Fill fill = styleFactory.createFill(colour);
        Stroke stroke = null;
        Mark mark = styleFactory.mark(wellKnownName, fill, stroke);
        ExternalGraphic[] externalGraphics = null;
        Mark[] marks = new Mark[1];
        marks[0] = mark;
        Symbol[] symbols = null;
        Expression opacity = null;
        Expression rotation = ff.literal(angle);
        Expression size = ff.literal(symbolSize);
        Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation);
        // Displacement (offsets)
        if ((xOffset > 0.0) && (yOffset > 0.0)) {
            Expression expressionX = ff.literal(xOffset);
            Expression expressionY = ff.literal(yOffset);
            Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY);
            graphic.setDisplacement(displacement);
        }
        markerList.add(graphic);
    }
    return markerList;
}
Also used : Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement)

Example 2 with ExternalGraphic

use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.

the class SimpleMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the graphic marker list
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE);
    double size = getDouble(obj, CommonSymbolKeys.SIZE);
    int style = getInt(obj, CommonSymbolKeys.STYLE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
    Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR));
    Expression wellKnownName = ff.literal(styleMap.get(style));
    Stroke stroke = null;
    if (outlineSize > 0.0) {
        stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize));
    }
    Fill fill = styleFactory.createFill(markerColour);
    Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle));
    Expression expressionOpacity = null;
    ExternalGraphic[] externalGraphics = null;
    Symbol[] symbols = null;
    Mark[] marks = new Mark[1];
    marks[0] = mark;
    Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle));
    // Set offset
    if ((xOffset > 0.0) && (yOffset > 0.0)) {
        Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
        graphic.setDisplacement(displacement);
    }
    markList.add(graphic);
    return markList;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression)

Example 3 with ExternalGraphic

use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.

the class UpdateGraphicalSymbol method processGraphicalSymbol.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.data.ProcessGraphicSymbolInterface#processGraphicalSymbol(java.net.URL, java.util.List, java.util.List)
     */
@Override
public void processGraphicalSymbol(URL resourceLocator, List<GraphicalSymbol> graphicalSymbolList, List<String> externalImageList) {
    for (GraphicalSymbol symbol : graphicalSymbolList) {
        if (symbol instanceof ExternalGraphic) {
            ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) symbol;
            OnLineResourceImpl onlineResource = (OnLineResourceImpl) externalGraphic.getOnlineResource();
            String currentValue = null;
            URL currentValueURL = null;
            try {
                currentValueURL = onlineResource.getLinkage().toURL();
                currentValue = currentValueURL.toExternalForm();
            } catch (MalformedURLException e) {
                ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
            }
            if ((resourceLocator == null) || RelativePath.hasHost(currentValueURL)) {
                // Just report back the external image
                URI uri = null;
                try {
                    uri = new URI(currentValue);
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            } else {
                try {
                    File file = new File(currentValueURL.getFile());
                    File folder = new File(resourceLocator.getFile());
                    currentValue = RelativePath.getRelativePath(file, folder);
                    // If the backslashes are not converted to forward slashes
                    // creating the URI does not work
                    currentValue = currentValue.replace('\\', '/');
                    OnLineResourceImpl updatedOnlineResource = new OnLineResourceImpl();
                    URI uri = new URI(currentValue);
                    updatedOnlineResource.setLinkage(uri);
                    externalGraphic.setOnlineResource(updatedOnlineResource);
                    externalGraphic.setURI(uri.toASCIIString());
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GraphicalSymbol(org.opengis.style.GraphicalSymbol) OnLineResourceImpl(org.geotools.metadata.iso.citation.OnLineResourceImpl) URISyntaxException(java.net.URISyntaxException) ExternalGraphic(org.geotools.styling.ExternalGraphic) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 4 with ExternalGraphic

use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.

the class ExternalGraphicDetails method getSymbol.

/**
 * Gets the symbol.
 *
 * @return the symbol
 */
public ExternalGraphic getSymbol() {
    ExternalGraphic extGraphic = null;
    if (externalURL != null) {
        String fileExtension = ExternalFilenames.getFileExtension(externalURL.toString());
        String imageFormat = ExternalFilenames.getImageFormat(fileExtension);
        String uri = "";
        try {
            uri = externalURL.toURI().toString();
        } catch (URISyntaxException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        extGraphic = getStyleFactory().createExternalGraphic(uri, imageFormat);
    }
    return extGraphic;
}
Also used : URISyntaxException(java.net.URISyntaxException) ExternalGraphic(org.geotools.styling.ExternalGraphic)

Example 5 with ExternalGraphic

use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.

the class FieldConfigFilename method getValue.

/**
 * Gets the value.
 *
 * @param fieldConfigManager the field config manager
 * @param symbolType the symbol type
 * @param fillEnabled the fill enabled
 * @param strokeEnabled the stroke enabled
 * @return the value
 */
@Override
public List<GraphicalSymbol> getValue(GraphicPanelFieldManager fieldConfigManager, Expression symbolType, boolean fillEnabled, boolean strokeEnabled) {
    List<GraphicalSymbol> symbols = null;
    if (externalGraphicPanel != null) {
        ExternalGraphic extGraphic = externalGraphicPanel.getSymbol();
        symbols = SelectedSymbol.getInstance().getSymbolList(extGraphic);
    }
    return symbols;
}
Also used : GraphicalSymbol(org.opengis.style.GraphicalSymbol) ExternalGraphic(org.geotools.styling.ExternalGraphic)

Aggregations

ExternalGraphic (org.geotools.styling.ExternalGraphic)9 Graphic (org.geotools.styling.Graphic)6 GraphicalSymbol (org.opengis.style.GraphicalSymbol)6 Displacement (org.geotools.styling.Displacement)4 Expression (org.opengis.filter.expression.Expression)4 JsonObject (com.google.gson.JsonObject)3 ArrayList (java.util.ArrayList)3 Fill (org.geotools.styling.Fill)3 Mark (org.geotools.styling.Mark)3 JsonElement (com.google.gson.JsonElement)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 AnchorPoint (org.geotools.styling.AnchorPoint)2 Stroke (org.geotools.styling.Stroke)2 Symbol (org.geotools.styling.Symbol)2 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1