Search in sources :

Example 56 with StyledLayerDescriptor

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

the class RuleRenderVisitorTest method createSLD.

/**
 * Creates the sld.
 *
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createSLD() {
    String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + "    xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + "    xmlns=\"http://www.opengis.net/sld\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\" " + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "  <NamedLayer>" + "    <Name>Attribute-based point</Name>" + "    <UserStyle>" + "      <Title>GeoServer SLD Cook Book: Attribute-based point</Title>" + "      <FeatureTypeStyle>" + "        <Rule>" + "          <Name>SmallPop</Name>" + "          <Title>1 to 50000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>50000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>MediumPop</Name>" + "          <Title>50000 to 500000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>500000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>circle</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#123456</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>LargePop</Name>" + "          <Title>500000 to 900000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>900000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "      </FeatureTypeStyle>" + "    </UserStyle>" + "  </NamedLayer>" + "</StyledLayerDescriptor>";
    SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
    sldData.setDataSourceProperties(DataSourceConnectorFactory.getNoDataSource());
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    return sld;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 57 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor 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.jupiter.api.Test)

Example 58 with StyledLayerDescriptor

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

the class ScaleToolPanelTest method testScaleToolPanelRevert.

/**
 * Test method for {@link
 * com.sldeditor.tool.scale.ScaleToolPanel#ScaleToolPanel(com.sldeditor.common.SLDEditorInterface)}.
 */
@Test
void testScaleToolPanelRevert() {
    TestSLDEditorInterface app = new TestSLDEditorInterface();
    TestScaleToolPanel testObj = new TestScaleToolPanel(app);
    DummyScaleSLDFile testData = new DummyScaleSLDFile();
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDEditorFile.getInstance().setSLDData(testData.getSLDData());
    sldDataList.add(testData.getSLDData());
    testObj.populate(sldDataList);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(testData.getSLDData());
    List<Rule> ruleList = null;
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        if (styledLayerList != null) {
            for (StyledLayer styledLayer : styledLayerList) {
                if (styledLayer instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                    for (Style style : namedLayerImpl.styles()) {
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            ruleList = fts.rules();
                        }
                    }
                }
            }
        }
    }
    assertNotNull(ruleList);
    double originalMaxScale = ruleList.get(1).getMaxScaleDenominator();
    double expectedMinScale = 100.0;
    testObj.setMinScale(0, expectedMinScale);
    double expectedMaxScale = 999.0;
    testObj.setMaxScale(1, expectedMaxScale);
    // Make no changes
    testObj.revertData();
    assertNull(testObj.getMinScale(0));
    String stringValue = (String) testObj.getMaxScale(1);
    double actualScale = ScaleUtil.extractValue((String) stringValue);
    assertTrue(Math.abs(actualScale - originalMaxScale) < 0.0001);
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) ArrayList(java.util.ArrayList) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) Test(org.junit.jupiter.api.Test)

Example 59 with StyledLayerDescriptor

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

the class ScaleToolPanelTest method testScaleToolPanel.

/**
 * Test method for {@link
 * com.sldeditor.tool.scale.ScaleToolPanel#ScaleToolPanel(com.sldeditor.common.SLDEditorInterface)}.
 */
@Test
void testScaleToolPanel() {
    TestSLDEditorInterface app = new TestSLDEditorInterface();
    TestScaleToolPanel testObj = new TestScaleToolPanel(app);
    DummyScaleSLDFile testData = new DummyScaleSLDFile();
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDEditorFile.getInstance().setSLDData(testData.getSLDData());
    sldDataList.add(testData.getSLDData());
    testObj.populate(sldDataList);
    double expectedMinScale = 100.0;
    testObj.setMinScale(0, expectedMinScale);
    double expectedMaxScale = 999.0;
    testObj.setMaxScale(1, expectedMaxScale);
    // Make no changes
    testObj.saveData();
    // Should be the same as before
    assertNotNull(app.savedSldData);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(app.savedSldData);
    List<Rule> ruleList = null;
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        if (styledLayerList != null) {
            for (StyledLayer styledLayer : styledLayerList) {
                if (styledLayer instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                    for (Style style : namedLayerImpl.styles()) {
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            ruleList = fts.rules();
                        }
                    }
                }
            }
        }
    }
    assertNotNull(ruleList);
    assertTrue(Math.abs(ruleList.get(0).getMinScaleDenominator() - expectedMinScale) < 0.0001);
    assertTrue(Math.abs(ruleList.get(1).getMaxScaleDenominator() - expectedMaxScale) < 0.0001);
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) ArrayList(java.util.ArrayList) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) Test(org.junit.jupiter.api.Test)

Example 60 with StyledLayerDescriptor

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

the class YSLDToolTest method getSLDDataFile.

/**
 * Gets the SLD/YSLD file.
 *
 * @param testfile the testfile
 * @return the SLD data file
 */
private static SLDData getSLDDataFile(String testfile) {
    SLDData sldData = null;
    InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile);
    if (inputStream == null) {
        assertNotNull(inputStream, "Failed to find test file : " + testfile);
    } else {
        File f = null;
        try {
            String fileExtension = ExternalFilenames.getFileExtension(testfile);
            f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension));
            String sldContents = readFile(f.getAbsolutePath());
            if (fileExtension.compareTo("ysld") == 0) {
                StyledLayerDescriptor sld = Ysld.parse(sldContents);
                // Convert YSLD to SLD string
                SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
                sldContents = sldWriter.encodeSLD(null, sld);
            }
            sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) InputStream(java.io.InputStream) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) File(java.io.File)

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