use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.
the class PatternRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
if (!(resource instanceof GridCoverageResource)) {
return Stream.empty();
}
final GridCoverageResource gcr = (GridCoverageResource) resource;
GridCoverage dataCoverage;
try {
dataCoverage = gcr.read(renderingContext.getGridGeometry());
} catch (NoSuchDataException ex) {
return Stream.empty();
} catch (DataStoreException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(resource);
return Stream.of(ep);
}
if (!Utilities.equalsIgnoreMetadata(CRS.getHorizontalComponent(dataCoverage.getCoordinateReferenceSystem()), renderingContext.getObjectiveCRS())) {
// coverage is not in objective crs, resample it
try {
// we resample the native view of the coverage only, the style will be applied later.
dataCoverage = new ResampleProcess(dataCoverage, renderingContext.getObjectiveCRS(), null, InterpolationCase.NEIGHBOR, null).executeNow();
} catch (Exception ex) {
LOGGER.log(Level.WARNING, "ERROR resample in raster symbolizer renderer", ex);
}
}
final Map.Entry<FeatureSet, MutableStyle> entry;
try {
entry = symbol.getMasks(dataCoverage);
} catch (IOException | TransformException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(resource);
return Stream.of(ep);
}
final MapLayer subLayer = MapBuilder.createLayer(entry.getKey());
subLayer.setStyle(entry.getValue());
return DefaultPortrayalService.present(subLayer, entry.getKey(), renderingContext);
}
use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.
the class InlineImageTest method readImage.
@Test
public void readImage() throws Exception {
final BufferedImage image = new BufferedImage(20, 10, BufferedImage.TYPE_INT_ARGB);
final String geometry = null;
final ExternalGraphic external = SF.externalGraphic(new ImageIcon(image), Collections.EMPTY_LIST);
final Graphic graphic = SF.graphic(Collections.singletonList((GraphicalSymbol) external), LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT);
final PointSymbolizer ips = SF.pointSymbolizer("", geometry, DEFAULT_DESCRIPTION, Units.POINT, graphic);
final MutableStyle style = SF.style(ips);
final File f = File.createTempFile("sld", ".xml");
f.deleteOnExit();
final StyleXmlIO io = new StyleXmlIO();
io.writeStyle(f, style, Specification.StyledLayerDescriptor.V_1_1_0);
final MutableStyle result = io.readStyle(f, Specification.SymbologyEncoding.V_1_1_0);
final Symbolizer s = result.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertTrue(s instanceof PointSymbolizer);
final PointSymbolizer ps = (PointSymbolizer) s;
final ExternalGraphic eg = (ExternalGraphic) ps.getGraphic().graphicalSymbols().get(0);
assertNotNull(eg);
final Icon ri = eg.getInlineContent();
assertNotNull(ri);
assertEquals(20, ri.getIconWidth());
assertEquals(10, ri.getIconHeight());
}
use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.
the class SEforSLD100Test method testStyle.
// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR STYLE ORDERING //////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testStyle() throws JAXBException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_STYLE);
assertNotNull(obj);
UserStyle jax = (UserStyle) obj;
MutableStyle style = TRANSFORMER_GT.visitUserStyle(jax);
assertNotNull(style);
assertEquals(style.getName(), valueName);
assertEquals(style.getDescription().getTitle().toString(), valueTitle);
assertEquals(style.getDescription().getAbstract().toString(), valueAbstract);
assertEquals(style.isDefault(), true);
assertEquals(style.featureTypeStyles().size(), 3);
// Write test
UserStyle pvt = TRANSFORMER_OGC.visit(style, null);
assertNotNull(pvt);
assertEquals(pvt.getName(), valueName);
assertEquals(pvt.getTitle(), valueTitle);
assertEquals(pvt.getAbstract(), valueAbstract);
assertEquals(pvt.isIsDefault(), Boolean.TRUE);
assertEquals(pvt.getFeatureTypeStyle().size(), 3);
MARSHALLER.marshal(pvt, TEST_FILE_SE_STYLE);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.
the class SEforSLD110Test method testStyle.
// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR STYLE ORDERING //////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testStyle() throws JAXBException, FactoryException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_STYLE);
assertNotNull(obj);
UserStyle jax = (UserStyle) obj;
MutableStyle style = TRANSFORMER_GT.visitUserStyle(jax);
assertNotNull(style);
assertEquals(style.getName(), valueName);
assertEquals(style.getDescription().getTitle().toString(), valueTitle);
assertEquals(style.getDescription().getAbstract().toString(), valueAbstract);
assertEquals(style.isDefault(), true);
assertEquals(style.featureTypeStyles().size(), 3);
// Write test
UserStyle pvt = TRANSFORMER_OGC.visit(style, null);
assertNotNull(pvt);
assertEquals(pvt.getName(), valueName);
assertEquals(String.valueOf(pvt.getDescription().getTitle()), valueTitle);
assertEquals(String.valueOf(pvt.getDescription().getAbstract()), valueAbstract);
assertEquals(pvt.isIsDefault(), Boolean.TRUE);
assertEquals(pvt.getFeatureTypeStyleOrCoverageStyleOrOnlineResource().size(), 3);
MARSHALLER.marshal(pvt, TEST_FILE_SE_STYLE);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.
the class CopyStyleVisitor method visit.
@Override
public MutableStyle visit(Style style, Object data) {
final MutableStyle copy = SF.style();
copy.setDefault(style.isDefault());
copy.setDefaultSpecification(style.getDefaultSpecification());
copy.setDescription(style.getDescription());
copy.setName(style.getName());
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
copy.featureTypeStyles().add((MutableFeatureTypeStyle) fts.accept(this, data));
}
return copy;
}
Aggregations