Search in sources :

Example 56 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class LegendManagerTest method testSLD2.

/**
 * Create test SLD
 *
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor testSLD2() {
    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:sld=\"http://www.opengis.net/sld\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\" " + "    xmlns:gml=\"http://www.opengis.net/gml\" " + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<NamedLayer>" + "    <Name>Attribute-based polygon</Name>" + "    <UserStyle>" + "      <Title>SLD Cook Book: Attribute-based polygon</Title>" + "      <FeatureTypeStyle>" + "        <Rule>" + "          <Name>SmallPop</Name>" + "          <Title>Less Than 200,000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>200000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PolygonSymbolizer>" + "            <Fill>" + "              <CssParameter name=\"fill\">#66FF66</CssParameter>" + "            </Fill>" + "          </PolygonSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>MediumPop</Name>" + "          <Title>200,000 to 500,000</Title>" + "          <ogc:Filter>" + "            <ogc:And>" + "              <ogc:PropertyIsGreaterThanOrEqualTo>" + "                <ogc:PropertyName>pop</ogc:PropertyName>" + "                <ogc:Literal>200000</ogc:Literal>" + "              </ogc:PropertyIsGreaterThanOrEqualTo>" + "              <ogc:PropertyIsLessThan>" + "                <ogc:PropertyName>pop</ogc:PropertyName>" + "                <ogc:Literal>500000</ogc:Literal>" + "              </ogc:PropertyIsLessThan>" + "            </ogc:And>" + "          </ogc:Filter>" + "          <PolygonSymbolizer>" + "            <Fill>" + "              <CssParameter name=\"fill\">#33CC33</CssParameter>" + "            </Fill>" + "          </PolygonSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>LargePop</Name>" + "          <Title>Greater Than 500,000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsGreaterThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>500000</ogc:Literal>" + "            </ogc:PropertyIsGreaterThan>" + "          </ogc:Filter>" + "          <PolygonSymbolizer>" + "            <Fill>" + "              <CssParameter name=\"fill\">#009900</CssParameter>" + "            </Fill>" + "          </PolygonSymbolizer>" + "        </Rule>" + "      </FeatureTypeStyle>" + "    </UserStyle>" + "  </NamedLayer>" + "</StyledLayerDescriptor>";
    SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
    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 SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class RasterReader method createRasterSLDData.

/**
 * Creates the raster sld.
 *
 * @param rasterFile the raster file
 * @return the styled layer descriptor
 */
@Override
public SLDDataInterface createRasterSLDData(File rasterFile) {
    if (rasterFile == null) {
        return null;
    }
    StyledLayerDescriptor sld = null;
    AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
    AbstractGridCoverage2DReader reader = null;
    try {
        reader = format.getReader(rasterFile);
    } catch (UnsupportedOperationException e) {
        ConsoleManager.getInstance().error(this, Localisation.getField(RasterTool.class, "RasterReader.unknownFormat") + rasterFile.getAbsolutePath());
        return null;
    }
    BufferedImage img = null;
    try {
        img = ImageIO.read(rasterFile);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
        return null;
    }
    WritableRaster raster = img.getRaster();
    Style style = createRGBStyle(reader, raster);
    sld = sf.createStyledLayerDescriptor();
    NamedLayer namedLayer = sf.createNamedLayer();
    namedLayer.addStyle(style);
    sld.addStyledLayer(namedLayer);
    File sldFilename = ExternalFilenames.createSLDFilename(rasterFile);
    StyleWrapper styleWrapper = new StyleWrapper(sldFilename.getName());
    String sldContents = sldWriter.encodeSLD(null, sld);
    SLDData sldData = new SLDData(styleWrapper, sldContents);
    sldData.setSLDFile(sldFilename);
    sldData.setReadOnly(false);
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) WritableRaster(java.awt.image.WritableRaster) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) Style(org.geotools.styling.Style) NamedLayer(org.geotools.styling.NamedLayer) File(java.io.File)

Example 58 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class FileSystemInputTest method testCopyNodes.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#copyNodes(com.sldeditor.common.NodeInterface, java.util.Map)}.
 */
@Test
public void testCopyNodes() {
    FileSystemInput input = new FileSystemInput(null);
    URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
    List<SLDDataInterface> sldDataList = input.open(url);
    assertEquals(1, sldDataList.size());
    try {
        Path tempFolder = Files.createTempDirectory(getClass().getSimpleName());
        File tempFolderFile = tempFolder.toFile();
        FileTreeNode destinationTreeNode = new FileTreeNode(tempFolderFile.getParentFile(), tempFolderFile.getName());
        Map<NodeInterface, List<SLDDataInterface>> copyDataMap = new HashMap<NodeInterface, List<SLDDataInterface>>();
        copyDataMap.put(destinationTreeNode, sldDataList);
        assertTrue(input.copyNodes(destinationTreeNode, copyDataMap));
        SLDData sldData = (SLDData) sldDataList.get(0);
        sldData.setSLDFile(new File(tempFolderFile, "point_attribute.sld"));
        input.deleteNodes(destinationTreeNode, sldDataList);
        tempFolderFile.deleteOnExit();
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) SLDData(com.sldeditor.common.data.SLDData) HashMap(java.util.HashMap) IOException(java.io.IOException) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) List(java.util.List) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 59 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class RasterFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new RasterFileHandler().getSLDContents(null));
    URL url = RasterFileHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        RasterFileHandler handler = new RasterFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertNull(sldDataList);
        // Try with valid vector file
        FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.tif");
        sldDataList = handler.getSLDContents(fileTreeNode2);
        assertTrue(sldDataList.isEmpty());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = new SLDData(null, "");
        sldData.setSLDFile(saveFile);
        assertFalse(handler.save(null));
        assertFalse(handler.save(sldData));
        saveFile.delete();
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RasterFileHandler(com.sldeditor.extension.filesystem.file.raster.RasterFileHandler) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 60 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class SLDFileHandlerTest method testGetSLDName.

/**
 * Check SLD name
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDName() {
    SLDFileHandler handler = new SLDFileHandler();
    assertTrue(handler.getSLDName(null).compareTo("") == 0);
    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), "sldContents");
    String sldName = handler.getSLDName(sldData);
    assertTrue(sldName.compareTo("layer.sld") == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) SLDFileHandler(com.sldeditor.extension.filesystem.file.sld.SLDFileHandler) Test(org.junit.Test)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4