Search in sources :

Example 21 with StyledLayer

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

the class RenderSymbolTest method testRenderSymbol.

/**
 * Test method for {@link com.sldeditor.render.RenderSymbol#RenderSymbol()}.
 */
@Test
public void testRenderSymbol() {
    RenderSymbol symbol = new RenderSymbol();
    StyledLayerDescriptor sld = createSLD();
    StyledLayer styledLayer = sld.layers().get(0);
    if (styledLayer instanceof NamedLayerImpl) {
        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
        Style expectedStyle = namedLayerImpl.styles().get(0);
        SelectedSymbol.getInstance().setSld(sld);
        Style actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
        assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
        assertEquals(expectedStyle.getName(), actualStyle.getName());
        Rule expectedRule = expectedStyle.featureTypeStyles().get(0).rules().get(1);
        SelectedSymbol.getInstance().setFeatureTypeStyle(expectedStyle.featureTypeStyles().get(0));
        SelectedSymbol.getInstance().setRule(expectedRule);
        actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
        assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
        assertEquals(expectedRule.getName(), actualStyle.featureTypeStyles().get(0).rules().get(0).getName());
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) RenderSymbol(com.sldeditor.render.RenderSymbol) Style(org.geotools.styling.Style) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 22 with StyledLayer

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

the class RuleRenderVisitorTest method testRuleRenderVisitor.

/**
 * Test rule render visitor.
 */
@Test
public void testRuleRenderVisitor() {
    StyledLayerDescriptor sld = createSLD();
    StyledLayer styledLayer = sld.layers().get(0);
    if (styledLayer instanceof NamedLayerImpl) {
        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
        Style style = namedLayerImpl.styles().get(0);
        FeatureTypeStyle ftsToRender = style.featureTypeStyles().get(0);
        // Just find matching feature type style
        int symbolIndex = 0;
        RuleRenderVisitor visitor = new RuleRenderVisitor(ftsToRender, null, symbolIndex, new RuleRenderOptions());
        style.accept(visitor);
        Style copy = (Style) visitor.getCopy();
        Rule ruleToRender = ftsToRender.rules().get(0);
        Rule actualRule = copy.featureTypeStyles().get(0).rules().get(0);
        // Filters should be null
        assertNull(actualRule.getFilter());
        assertEquals(ruleToRender.symbolizers(), actualRule.symbolizers());
        // Now try and find 2nd rule, 2nd symbolizer
        ruleToRender = ftsToRender.rules().get(1);
        symbolIndex = 1;
        visitor = new RuleRenderVisitor(ftsToRender, ruleToRender, symbolIndex, new RuleRenderOptions());
        style.accept(visitor);
        copy = (Style) visitor.getCopy();
        assertEquals(1, copy.featureTypeStyles().get(0).rules().size());
        actualRule = copy.featureTypeStyles().get(0).rules().get(0);
        assertNull(actualRule.getFilter());
        assertEquals(1, actualRule.symbolizers().size());
        assertEquals(ruleToRender.symbolizers().get(1), actualRule.symbolizers().get(0));
    }
}
Also used : RuleRenderOptions(com.sldeditor.ui.render.RuleRenderOptions) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) RuleRenderVisitor(com.sldeditor.render.RuleRenderVisitor) 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) Test(org.junit.Test)

Example 23 with StyledLayer

use of org.geotools.styling.StyledLayer 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 24 with StyledLayer

use of org.geotools.styling.StyledLayer 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)

Example 25 with StyledLayer

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

the class SelectedSymbolTest method testGetSLD.

@Test
public void testGetSLD() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    // CHECKSTYLE:OFF
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    // CHECKSTYLE:ON
    instance.createNewSLD(sld);
    instance.setSld(sld);
    System.out.println("Select named layer");
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertNull(instance.getRule());
    assertNull(instance.getStyle());
    assertNull(instance.getFeatureTypeStyle());
    assertNull(instance.getSymbolizer());
    System.out.println("Select style");
    instance.addNewStyle(style);
    instance.setStyle(style);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertNull(instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    assertNull(instance.getSymbolizer());
    System.out.println("Select feature type style");
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    assertNull(instance.getSymbolizer());
    System.out.println("Select rule");
    instance.addNewRule(rule);
    instance.setRule(rule);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertEquals(rule, instance.getRule());
    assertNull(instance.getSymbolizer());
    assertTrue(instance.hasOnlyOneRule());
    System.out.println("Select symbolizer");
    instance.addSymbolizerToRule(symbolizer);
    instance.addNewRule(DefaultSymbols.createNewRule());
    assertFalse(instance.hasOnlyOneRule());
    assertEquals(-1, instance.getSymbolIndex());
    instance.setSymbolizer(symbolizer);
    assertEquals(namedLayer, instance.getStyledLayer());
    assertEquals(style, instance.getStyle());
    assertEquals(fts, instance.getFeatureTypeStyle());
    assertEquals(rule, instance.getRule());
    assertEquals(symbolizer, instance.getSymbolizer());
    assertEquals(0, instance.getSymbolIndex());
    // Get SLD structure
    StyledLayerDescriptor actualSLD = instance.getSld();
    assertEquals(sld, actualSLD);
    StyledLayer[] actualStyledLayers = actualSLD.getStyledLayers();
    assertEquals(1, actualStyledLayers.length);
    NamedLayer actualNamedLayer = (NamedLayer) actualStyledLayers[0];
    assertEquals(namedLayer, actualNamedLayer);
    Style[] actualStyle = actualNamedLayer.getStyles();
    assertEquals(1, actualStyle.length);
    assertEquals(style, actualStyle[0]);
    assertEquals(1, style.featureTypeStyles().size());
    FeatureTypeStyle actualFeatureTypeStyle = style.featureTypeStyles().get(0);
    assertEquals(fts, actualFeatureTypeStyle);
    List<Rule> actualRules = actualFeatureTypeStyle.rules();
    assertEquals(2, actualRules.size());
    Rule actualRule = actualRules.get(0);
    assertEquals(rule, actualRule);
    assertEquals(1, actualRule.symbolizers().size());
    assertEquals(symbolizer, actualRule.symbolizers().get(0));
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) StyledLayer(org.geotools.styling.StyledLayer) 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) Test(org.junit.Test)

Aggregations

StyledLayer (org.geotools.styling.StyledLayer)43 Style (org.geotools.styling.Style)28 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)25 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)22 Rule (org.geotools.styling.Rule)19 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)19 UserLayerImpl (org.geotools.styling.UserLayerImpl)16 Symbolizer (org.geotools.styling.Symbolizer)12 NamedLayer (org.geotools.styling.NamedLayer)10 Test (org.junit.Test)10 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)7 LineSymbolizer (org.geotools.styling.LineSymbolizer)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)5 IOException (java.io.IOException)4 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)4 SLDData (com.sldeditor.common.data.SLDData)3 ArrayList (java.util.ArrayList)3 UserLayer (org.geotools.styling.UserLayer)3 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)2