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