Search in sources :

Example 36 with StyledLayerDescriptor

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

the class NewRasterSLD method create.

/**
 * Creates the symbol.
 *
 * @return the styled layer descriptor
 */
/* (non-Javadoc)
     * @see com.sldeditor.create.NewSLDInterface#create()
     */
@Override
public StyledLayerDescriptor create() {
    StyledLayerDescriptor sld = getStyleFactory().createStyledLayerDescriptor();
    NamedLayer namedLayer = getStyleFactory().createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = getStyleFactory().createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = getStyleFactory().createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = getStyleFactory().createRule();
    fts.rules().add(rule);
    RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
    rule.symbolizers().add(raster);
    return sld;
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 37 with StyledLayerDescriptor

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

the class YSLDFileHandler method internalOpenFile.

/**
 * Internal open file.
 *
 * @param f the file
 * @param list the list
 */
private void internalOpenFile(File f, List<SLDDataInterface> list) {
    if (f.isFile() && FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
        try {
            String contents = readFile(f, Charset.defaultCharset());
            StyledLayerDescriptor sld = Ysld.parse(contents);
            // Convert YSLD to SLD string
            if (sldWriter == null) {
                sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
            }
            String sldContents = sldWriter.encodeSLD(null, sld);
            SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            sldData.setReadOnly(false);
            sldData.setOriginalFormat(SLDOutputFormatEnum.YSLD);
            list.add(sldData);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) IOException(java.io.IOException)

Example 38 with StyledLayerDescriptor

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

the class ExtractValidFieldTypes method fieldTypesUpdated.

/**
 * Evaluate fields types.
 *
 * @return true, field types updated
 */
public static boolean fieldTypesUpdated() {
    boolean fieldsUpdated = false;
    SLDStyleFactory styleFactory = new SLDStyleFactory();
    StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        for (StyledLayer styledLayer : styledLayerList) {
            List<org.geotools.styling.Style> styleList = null;
            if (styledLayer instanceof NamedLayerImpl) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                styleList = namedLayerImpl.styles();
            } else if (styledLayer instanceof UserLayerImpl) {
                UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                styleList = userLayerImpl.userStyles();
            }
            if (styleList != null) {
                for (Style style : styleList) {
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        for (Rule rule : fts.rules()) {
                            for (Symbolizer symbolizer : rule.symbolizers()) {
                                FeatureSource<SimpleFeatureType, SimpleFeature> featureList = DataSourceFactory.getDataSource().getFeatureSource();
                                if (featureList != null) {
                                    Object drawMe = null;
                                    try {
                                        drawMe = featureList.getFeatures().features().next();
                                    } catch (NoSuchElementException e) {
                                        e.printStackTrace();
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                    try {
                                        styleFactory.createStyle(drawMe, symbolizer);
                                    } catch (IllegalArgumentException e) {
                                        String message = e.getMessage();
                                        if (message.startsWith(UNABLE_TO_DECODE_PREFIX) && message.endsWith(UNABLE_TO_DECODE_SUFFIX)) {
                                            String fieldName = message.substring(UNABLE_TO_DECODE_PREFIX.length(), message.length() - UNABLE_TO_DECODE_SUFFIX.length());
                                            DataSourceFactory.getDataSource().updateFieldType(fieldName, Long.class);
                                            fieldsUpdated = true;
                                        } else {
                                            ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return fieldsUpdated;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) IOException(java.io.IOException) Symbolizer(org.geotools.styling.Symbolizer) SimpleFeature(org.opengis.feature.simple.SimpleFeature) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayerImpl(org.geotools.styling.UserLayerImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SLDStyleFactory(org.geotools.renderer.style.SLDStyleFactory) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NoSuchElementException(java.util.NoSuchElementException)

Example 39 with StyledLayerDescriptor

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

the class RenderPanelImpl method renderSymbol.

/**
 * Render symbol.
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.marker.iface.RenderSymbolInterface#renderSymbol()
     */
@Override
public void renderSymbol() {
    validSymbol = SelectedSymbol.getInstance().isValid();
    if (validSymbol) {
        StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
        SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
        if (sld != null) {
            for (SLDOutputInterface sldOutput : sldOutputList) {
                sldOutput.updatedSLD(sldData, sld);
            }
            renderSymbol((Style) renderSymbol.getRenderStyle(SelectedSymbol.getInstance()));
        } else {
            renderSymbol(null);
        }
    } else {
        repaint();
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SLDOutputInterface(com.sldeditor.common.output.SLDOutputInterface)

Example 40 with StyledLayerDescriptor

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

the class YSLDTool method exportToSLD.

/**
 * Export to SLD.
 */
private void exportToSLD() {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerNameWithOutSuffix();
        if (sld != null) {
            String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String destinationFolder = sldData.getSLDFile().getParent();
            File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
            String sldFilename = fileToSave.getName();
            if (fileToSave.exists()) {
                ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + sldFilename);
            } else {
                ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToSLDMsg") + " " + sldFilename);
                BufferedWriter out;
                try {
                    out = new BufferedWriter(new FileWriter(fileToSave));
                    out.write(sldString);
                    out.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                }
            }
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileWriter(java.io.FileWriter) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)123 Test (org.junit.Test)73 Rule (org.geotools.styling.Rule)51 Style (org.geotools.styling.Style)49 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)47 NamedLayer (org.geotools.styling.NamedLayer)44 SLDData (com.sldeditor.common.data.SLDData)24 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)23 File (java.io.File)19 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 StyledLayer (org.geotools.styling.StyledLayer)19 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)16 StyleWrapper (com.sldeditor.common.data.StyleWrapper)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)14 IOException (java.io.IOException)14 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 LineSymbolizer (org.geotools.styling.LineSymbolizer)12