Search in sources :

Example 31 with StyledLayerDescriptor

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

the class SLDUtils method readSLDFile.

/**
 * Creates a StyledLayerDescriptor object containing a SLD by reading the contents of a file.
 *
 * @param file the file
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor readSLDFile(File file) {
    StyledLayerDescriptor sld = null;
    if (file != null) {
        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
        try {
            // By using URL here allows external graphics to loaded properly
            URL url = file.toURI().toURL();
            SLDParser styleReader = new SLDParser(styleFactory, url);
            setResourcelocator(styleReader, file.toURI().toURL());
            sld = styleReader.parseSLD();
        } catch (MalformedURLException e) {
            ConsoleManager.getInstance().exception(SLDUtils.class, e);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(SLDUtils.class, e);
        }
    }
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) MalformedURLException(java.net.MalformedURLException) SLDParser(org.geotools.styling.SLDParser) IOException(java.io.IOException) URL(java.net.URL)

Example 32 with StyledLayerDescriptor

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

the class DefaultSymbols method createNewLine.

/**
 * Creates a new line symbol.
 *
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor createNewLine() {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    LineSymbolizer line = createDefaultLineSymbolizer();
    rule.symbolizers().add(line);
    return sld;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) LineSymbolizer(org.geotools.styling.LineSymbolizer) 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 33 with StyledLayerDescriptor

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

the class DefaultSymbols method createNewPoint.

/**
 * Creates a new point symbol.
 *
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor createNewPoint() {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    PointSymbolizer point = createDefaultPointSymbolizer();
    rule.symbolizers().add(point);
    return sld;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) 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 34 with StyledLayerDescriptor

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

the class DefaultSymbols method createNewRaster.

/**
 * Creates the new raster symbol.
 *
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor createNewRaster() {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    RasterSymbolizer raster = 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 35 with StyledLayerDescriptor

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

the class CreateInternalDataSource method connect.

/**
 * Creates the.
 *
 * @param typeName the type name
 * @param geometryFieldName the geometry field name
 * @param editorFile the editor file
 * @return the list of datastores
 */
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
    List<DataSourceInfo> dataSourceInfoList = new ArrayList<DataSourceInfo>();
    dataSourceInfoList.add(dsInfo);
    dsInfo.reset();
    if (editorFile != null) {
        StyledLayerDescriptor sld = editorFile.getSLD();
        determineGeometryType(sld);
        ExtendedSimpleFeatureTypeBuilder b = new ExtendedSimpleFeatureTypeBuilder();
        // set the name
        typeName = INTERNAL_SCHEMA_NAME;
        dsInfo.setTypeName(typeName);
        b.setName(typeName);
        String namespace = null;
        b.setNamespaceURI(namespace);
        // add a geometry property
        // set crs first
        b.setCRS(DefaultGeographicCRS.WGS84);
        SLDDataInterface sldData = editorFile.getSLDData();
        List<DataSourceAttributeData> fieldList = sldData.getFieldList();
        // Set the geometry field by default
        geometryField.reset();
        if (geometryFieldName != null) {
            geometryField.setGeometryFieldName(geometryFieldName);
        }
        List<AttributeDescriptor> attrDescList = new ArrayList<AttributeDescriptor>();
        if ((fieldList == null) || fieldList.isEmpty()) {
            // Read the fields from the SLD
            ExtractAttributes extract = new ExtractAttributes();
            extract.extractDefaultFields(sld);
            fieldList = extract.getFields();
            // Add non-geometry fields to the feature type builder
            for (DataSourceAttributeData dsAttribute : fieldList) {
                if (dsAttribute.getName() != null) {
                    b.add(dsAttribute.getName(), dsAttribute.getType());
                }
            }
            List<String> geometryFields = extract.getGeometryFields();
            for (String localGeometryFieldName : geometryFields) {
                geometryField.setGeometryFieldName(localGeometryFieldName);
            }
        } else {
            addFields(attrDescList, b, fieldList);
        }
        attrDescList.add(addGeometryField(b, geometryField.getGeometryFieldName()));
        b.addAll(attrDescList);
        // Store the fields
        sldData.setFieldList(fieldList);
        // Build the feature type
        SimpleFeatureType schema = b.buildFeatureType();
        dsInfo.setSchema(schema);
        CreateSampleData sampleData = new CreateSampleData();
        sampleData.create(schema, fieldList);
        MemoryDataStore dataStore = sampleData.getDataStore();
        dsInfo.setDataStore(dataStore);
        dsInfo.populateFieldMap();
    }
    return dataSourceInfoList;
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ArrayList(java.util.ArrayList) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) LineString(com.vividsolutions.jts.geom.LineString) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SLDDataInterface(com.sldeditor.common.SLDDataInterface)

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