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;
}
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;
}
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());
}
}
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());
}
}
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);
}
Aggregations