Search in sources :

Example 31 with NamedLayer

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

the class ExtractAttributesTest method getRuleList.

/**
 * Gets the rule list.
 *
 * @param sld the sld
 * @return the rule list
 */
protected List<Rule> getRuleList(StyledLayerDescriptor sld) {
    NamedLayer namedLayer = (NamedLayer) sld.layers().get(0);
    List<Rule> ruleList = namedLayer.styles().get(0).featureTypeStyles().get(0).rules();
    return ruleList;
}
Also used : Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 32 with NamedLayer

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

the class SLDUtilsTest method testCreateSLDFromStringGeoServer.

@Test
public void testCreateSLDFromStringGeoServer() {
    SLDData sldData = new SLDData(null, expectedSld);
    String geoserverUrl = "http://localhost:8080/geoserver";
    GeoServerConnection connectionData = new GeoServerConnection();
    try {
        connectionData.setUrl(new URL(geoserverUrl));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    sldData.setConnectionData(connectionData);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(null);
    assertNull(sld);
    sld = SLDUtils.createSLDFromString(sldData);
    StyledLayer[] styledLayers = sld.getStyledLayers();
    NamedLayer namedLayer = (NamedLayer) styledLayers[0];
    Style[] actualStyles = namedLayer.getStyles();
    PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
    assertEquals("circle", mark.getWellKnownName().toString());
    // Check resource locator
    geoserverUrl = geoserverUrl + "/styles/";
    assertTrue(geoserverUrl.compareTo(sldData.getResourceLocator().toExternalForm()) == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) MalformedURLException(java.net.MalformedURLException) StyledLayer(org.geotools.styling.StyledLayer) MarkImpl(org.geotools.styling.MarkImpl) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 33 with NamedLayer

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

the class SLDUtilsTest method testFindRule.

@Test
public void testFindRule() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);
    assertNotNull(actualRule);
    assertEquals(rule.getName(), actualRule.getName());
    actualRule = SLDUtils.findRule(sld, null, sldCopy);
    assertNull(actualRule);
    actualRule = SLDUtils.findRule(sld, rule, null);
    assertNull(actualRule);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) 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) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 34 with NamedLayer

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

the class SLDUtilsTest method testFindSymbolizer.

@Test
public void testFindSymbolizer() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);
    assertNotNull(actualSymbolizer);
    assertEquals(symbolizer.getLabel().toString(), ((TextSymbolizer) actualSymbolizer).getLabel().toString());
    actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
    assertNull(actualSymbolizer);
    actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
    assertNull(actualSymbolizer);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) 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) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Test(org.junit.Test)

Example 35 with NamedLayer

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

the class SLDUtilsTest method testReadSLDFile.

@Test
public void testReadSLDFile() {
    try {
        File tmpFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        FileWriter fileWriter = new FileWriter(tmpFile);
        fileWriter.write(expectedSld);
        fileWriter.flush();
        fileWriter.close();
        StyledLayerDescriptor sld = SLDUtils.readSLDFile(null);
        assertNull(sld);
        sld = SLDUtils.readSLDFile(tmpFile);
        StyledLayer[] styledLayers = sld.getStyledLayers();
        NamedLayer namedLayer = (NamedLayer) styledLayers[0];
        Style[] actualStyles = namedLayer.getStyles();
        PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
        MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
        assertEquals("circle", mark.getWellKnownName().toString());
        tmpFile.delete();
    } catch (IOException e) {
        e.printStackTrace();
        fail("Failed to create test file");
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) FileWriter(java.io.FileWriter) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) MarkImpl(org.geotools.styling.MarkImpl) IOException(java.io.IOException) File(java.io.File) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Aggregations

NamedLayer (org.geotools.styling.NamedLayer)51 Style (org.geotools.styling.Style)44 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)44 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)42 Rule (org.geotools.styling.Rule)38 Test (org.junit.Test)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)13 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 LineSymbolizer (org.geotools.styling.LineSymbolizer)11 StyledLayer (org.geotools.styling.StyledLayer)10 Symbolizer (org.geotools.styling.Symbolizer)8 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)7 SLDData (com.sldeditor.common.data.SLDData)6 TextSymbolizer (org.geotools.styling.TextSymbolizer)6 FilterFactory (org.opengis.filter.FilterFactory)6 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)5 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)5