Search in sources :

Example 81 with StyledLayerDescriptor

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

the class MapBoxTool 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(MapBoxTool.class, "MapBoxTool.destinationAlreadyExists") + " " + sldFilename);
            } else {
                ConsoleManager.getInstance().information(this, Localisation.getField(MapBoxTool.class, "MapBoxTool.exportToSLDMsg") + " " + sldFilename);
                try (BufferedWriter out = new BufferedWriter(new FileWriter(fileToSave))) {
                    out.write(sldString);
                } 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)

Example 82 with StyledLayerDescriptor

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

the class CreateInlineDataSource method connect.

/**
 * Creates the data source.
 *
 * @param typeName the type name
 * @param geometryFieldName the geometry field name
 * @param editorFile the editor file
 * @return the list of data stores
 */
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
    for (DataSourceInfo dsInfo : dataSourceInfoList) {
        dsInfo.reset();
    }
    dataSourceInfoList.clear();
    if (editorFile != null) {
        StyledLayerDescriptor sld = editorFile.getSLD();
        List<UserLayer> userLayerList = InlineFeatureUtils.extractUserLayers(sld);
        for (UserLayer userLayer : userLayerList) {
            DataSourceInfo dsInfo = new DataSourceInfo();
            dsInfo.setUserLayer(userLayer);
            dataSourceInfoList.add(dsInfo);
            DataStore dataStore = userLayer.getInlineFeatureDatastore();
            if (dataStore == null) {
                continue;
            }
            try {
                List<Name> nameList = dataStore.getNames();
                if (!nameList.isEmpty()) {
                    typeName = nameList.get(0).getLocalPart();
                }
                // Set the type name
                dsInfo.setTypeName(typeName);
                SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
                SimpleFeatureType schema = source.getSchema();
                dsInfo.setSchema(schema);
                dsInfo.setDataStore(dataStore);
                GeometryTypeEnum geometryType = InlineFeatureUtils.determineGeometryType(schema.getGeometryDescriptor(), source.getFeatures());
                dsInfo.setGeometryType(geometryType);
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
                dsInfo.reset();
            }
        }
    }
    return dataSourceInfoList;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) UserLayer(org.geotools.styling.UserLayer) Name(org.opengis.feature.type.Name)

Example 83 with StyledLayerDescriptor

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

the class SymbolizerDetailsPanel method getMinimumVersion.

/**
 * Gets the minimum version vendor option present in the SLD.
 *
 * @param parentObj the parent obj
 * @param sldObj the sld obj
 * @param vendorOptionsPresentList the vendor options present list
 */
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
    Class<?> parentClass = null;
    Class<?> classSelected = sldObj.getClass();
    if (sldObj instanceof StyledLayerDescriptor) {
    // No parent
    } else if (sldObj instanceof StyledLayer) {
        parentClass = StyledLayerDescriptor.class;
    } else if (sldObj instanceof Style) {
        parentClass = StyledLayer.class;
    } else if (sldObj instanceof FeatureTypeStyle) {
        parentClass = Style.class;
    } else if (sldObj instanceof Rule) {
        parentClass = FeatureTypeStyle.class;
    } else if (sldObj instanceof Symbolizer) {
        parentClass = Rule.class;
    }
    internalGetMinimumVersion(parentObj, sldObj, vendorOptionsPresentList, parentClass, classSelected);
    if (sldObj instanceof PointSymbolizerImpl) {
        PointSymbolizerImpl pointSymbolizer = (PointSymbolizerImpl) sldObj;
        parentClass = PointSymbolizerImpl.class;
        classSelected = FillImpl.class;
        internalGetMinimumVersion(pointSymbolizer, pointSymbolizer.getGraphic(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof LineSymbolizerImpl) {
        LineSymbolizerImpl lineSymbolizer = (LineSymbolizerImpl) sldObj;
        parentClass = LineSymbolizerImpl.class;
        classSelected = StrokeImpl.class;
        internalGetMinimumVersion(lineSymbolizer, lineSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof PolygonSymbolizerImpl) {
        PolygonSymbolizerImpl polygonSymbolizer = (PolygonSymbolizerImpl) sldObj;
        parentClass = PolygonSymbolizerImpl.class;
        classSelected = FillImpl.class;
        internalGetMinimumVersion(polygonSymbolizer, polygonSymbolizer.getFill(), vendorOptionsPresentList, parentClass, classSelected);
        classSelected = StrokeImpl.class;
        internalGetMinimumVersion(polygonSymbolizer, polygonSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof TextSymbolizerImpl) {
        TextSymbolizerImpl textSymbolizer = (TextSymbolizerImpl) sldObj;
        parentClass = Rule.class;
        classSelected = TextSymbolizerImpl.class;
        internalGetMinimumVersion(parentObj, textSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof RasterSymbolizerImpl) {
        RasterSymbolizerImpl rasterSymbolizer = (RasterSymbolizerImpl) sldObj;
        parentClass = Rule.class;
        classSelected = RasterSymbolizerImpl.class;
        internalGetMinimumVersion(parentObj, rasterSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
    }
}
Also used : TextSymbolizerImpl(org.geotools.styling.TextSymbolizerImpl) StyledLayer(org.geotools.styling.StyledLayer) LineSymbolizerImpl(org.geotools.styling.LineSymbolizerImpl) StrokeImpl(org.geotools.styling.StrokeImpl) Symbolizer(org.geotools.styling.Symbolizer) RasterSymbolizerImpl(org.geotools.styling.RasterSymbolizerImpl) PolygonSymbolizerImpl(org.geotools.styling.PolygonSymbolizerImpl) 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) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl)

Example 84 with StyledLayerDescriptor

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

the class ScalePanelUtils method containsScales.

/**
 * Extracts all the rule scales.
 *
 * @param sldData the sld data
 * @return the scale sld data
 */
public static List<ScaleSLDData> containsScales(SLDDataInterface sldData) {
    List<ScaleSLDData> dataList = null;
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        for (StyledLayer styledLayer : styledLayerList) {
            if (styledLayer instanceof NamedLayerImpl) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                for (Style style : namedLayerImpl.styles()) {
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        for (Rule rule : fts.rules()) {
                            double minScale = rule.getMinScaleDenominator();
                            double maxScale = rule.getMaxScaleDenominator();
                            if (isMinScaleSet(minScale) || isMaxScaleSet(maxScale)) {
                                if (dataList == null) {
                                    dataList = new ArrayList<>();
                                }
                                ScaleSLDData scaleSLDData = new ScaleSLDData(sld, sldData);
                                scaleSLDData.setNamedLayer(namedLayerImpl.getName());
                                scaleSLDData.setFeatureTypeStyle(fts.getName());
                                scaleSLDData.setStyle(style.getName());
                                scaleSLDData.setRule(rule);
                                if (isMinScaleSet(minScale)) {
                                    scaleSLDData.setMinScale(minScale);
                                }
                                if (isMaxScaleSet(maxScale)) {
                                    scaleSLDData.setMaxScale(maxScale);
                                }
                                dataList.add(scaleSLDData);
                            }
                        }
                    }
                }
            }
        }
    }
    return dataList;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 85 with StyledLayerDescriptor

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

the class VectorReader method createSLDData.

/**
 * Creates the SLD data.
 *
 * @param map the map
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createSLDData(Map<String, Object> map, String featureClass) {
    StyledLayerDescriptor sld = null;
    DataStore dataStore = null;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
        return null;
    }
    if (dataStore != null) {
        // Try connecting to a vector data source
        String typeName;
        GeometryTypeEnum geometryTypeEnum = GeometryTypeEnum.UNKNOWN;
        try {
            if (featureClass == null) {
                typeName = dataStore.getTypeNames()[0];
            } else {
                typeName = featureClass;
            }
            SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
            SimpleFeatureType schema = source.getSchema();
            GeometryType geometryType = schema.getGeometryDescriptor().getType();
            Class<?> bindingType = geometryType.getBinding();
            geometryTypeEnum = GeometryTypeMapping.getGeometryType(bindingType);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
            return null;
        } finally {
            dataStore.dispose();
        }
        switch(geometryTypeEnum) {
            case POINT:
                sld = DefaultSymbols.createNewPoint();
                break;
            case LINE:
                sld = DefaultSymbols.createNewLine();
                break;
            case POLYGON:
                sld = DefaultSymbols.createNewPolygon();
                break;
            default:
                break;
        }
    }
    return sld;
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) GeometryTypeEnum(com.sldeditor.datasource.impl.GeometryTypeEnum)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)134 Test (org.junit.jupiter.api.Test)80 Rule (org.geotools.styling.Rule)54 Style (org.geotools.styling.Style)52 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)50 NamedLayer (org.geotools.styling.NamedLayer)48 SLDData (com.sldeditor.common.data.SLDData)25 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)24 File (java.io.File)22 StyledLayer (org.geotools.styling.StyledLayer)21 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 SLDDataInterface (com.sldeditor.common.SLDDataInterface)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)17 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 StyleWrapper (com.sldeditor.common.data.StyleWrapper)16 IOException (java.io.IOException)16 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)15 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)12