use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.
the class RasterSymbolizerRenderer method outline.
private Stream<Presentation> outline(MapLayer layer, GridGeometry gridGeom) throws PortrayalException {
if (symbol.getOutLine() != null) {
final CoordinateReferenceSystem crs2d = CRS.getHorizontalComponent(gridGeom.getCoordinateReferenceSystem());
final Geometry geom = GeometricUtilities.toJTSGeometry(gridGeom.getEnvelope(), GeometricUtilities.WrapResolution.NONE);
geom.setUserData(crs2d);
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("border");
ftb.addAttribute(Geometry.class).setName("geom").setCRS(crs2d).addRole(AttributeRole.DEFAULT_GEOMETRY);
ftb.addAttribute(Integer.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
final FeatureType type = ftb.build();
final Feature feature = type.newInstance();
feature.setPropertyValue("id", 0);
feature.setPropertyValue("geom", geom);
final SymbolizerRendererService service = GO2Utilities.findRenderer(symbol.getOutLine());
final SymbolizerRenderer renderer = service.createRenderer(symbol, renderingContext);
return renderer.presentations(layer, feature);
}
return Stream.empty();
}
use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.
the class GeometryExpressionTest method bufferTest.
/**
* Test a buffer expression around geometry.
*/
@Test
public void bufferTest() throws PortrayalException, IOException {
final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(Point.class).setName("geom").setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = ftb.build();
final Point point = GO2Utilities.JTS_FACTORY.createPoint(new Coordinate(0, 0));
JTS.setCRS(point, crs);
final Feature feature = type.newInstance();
feature.setPropertyValue("geom", point);
final Expression geomExp = FF.function("buffer", FF.property("geom"), FF.literal(10));
final Fill fill = SF.fill(Color.RED);
final PolygonSymbolizer symbolizer = SF.polygonSymbolizer("", geomExp, DEFAULT_DESCRIPTION, DEFAULT_UOM, null, fill, DEFAULT_DISPLACEMENT, LITERAL_ZERO_FLOAT);
final MutableStyle style = SF.style(symbolizer);
final MapLayers context = MapBuilder.createContext();
final MapLayer fml = MapBuilder.createLayer(FeatureStoreUtilities.collection(feature));
fml.setStyle(style);
context.getComponents().add(fml);
final GeneralEnvelope env = new GeneralEnvelope(crs);
env.setRange(0, -20, +20);
env.setRange(1, -20, +20);
final CanvasDef canvasDef = new CanvasDef();
canvasDef.setEnvelope(env);
canvasDef.setDimension(new Dimension(40, 40));
canvasDef.setBackground(Color.WHITE);
final SceneDef sceneDef = new SceneDef(context);
final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
// we must obtain a red point of 10pixel width at image center
final int red = Color.RED.getRGB();
final int white = Color.WHITE.getRGB();
Assert.assertEquals(white, image.getRGB(20, 9));
Assert.assertEquals(red, image.getRGB(20, 11));
Assert.assertEquals(red, image.getRGB(20, 20));
Assert.assertEquals(red, image.getRGB(20, 29));
Assert.assertEquals(white, image.getRGB(20, 31));
Assert.assertEquals(white, image.getRGB(9, 20));
Assert.assertEquals(red, image.getRGB(11, 20));
Assert.assertEquals(red, image.getRGB(20, 20));
Assert.assertEquals(red, image.getRGB(29, 20));
Assert.assertEquals(white, image.getRGB(31, 20));
}
use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.
the class TextSymbolizerTest method pointLabelTest.
/**
* Render a label at check it is correctly located in the image.
*/
@Test
public void pointLabelTest() throws Exception {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(Point.class).setName("geom").setCRS(CommonCRS.defaultGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = ftb.build();
final Feature feature = type.newInstance();
feature.setPropertyValue("geom", GF.createPoint(new Coordinate(0, 0)));
final FeatureSet collection = new InMemoryFeatureSet(type, Arrays.asList(feature));
// text symbolizer style
final String name = "mySymbol";
final Description desc = DEFAULT_DESCRIPTION;
// use the default geometry of the feature
final String geometry = null;
final Unit unit = Units.POINT;
final Expression label = FF.literal("LABEL");
final Font font = SF.font(FF.literal("Arial"), FONT_STYLE_ITALIC, FONT_WEIGHT_BOLD, FF.literal(14));
final LabelPlacement placement = SF.pointPlacement();
final Halo halo = SF.halo(Color.WHITE, 0);
final Fill fill = SF.fill(Color.BLUE);
final TextSymbolizer symbol = SF.textSymbolizer(name, geometry, desc, unit, label, font, placement, halo, fill);
final MutableStyle style = SF.style(symbol);
final MapLayer layer = MapBuilder.createLayer(collection);
layer.setStyle(style);
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(layer);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.defaultGeographic());
env.setRange(0, -180, +180);
env.setRange(1, -90, +90);
final Hints hints = new Hints();
hints.put(GO2Hints.KEY_COLOR_MODEL, ColorModel.getRGBdefault());
final SceneDef scenedef = new SceneDef(context, hints);
final CanvasDef canvasdef = new CanvasDef(new Dimension(360, 180), env);
canvasdef.setBackground(Color.WHITE);
final BufferedImage buffer = DefaultPortrayalService.portray(canvasdef, scenedef);
// ImageIO.write(buffer, "PNG", new File("test.png"));
// we expect to have a blue label at the center of the image
final int[] pixel = new int[4];
final int[] blue = new int[] { 0, 0, 255, 255 };
final Raster raster = buffer.getData();
boolean found = false;
for (int x = 160; x < 200; x++) {
// should be exactly at the center
raster.getPixel(x, 90, pixel);
if (Arrays.equals(blue, pixel)) {
found = true;
}
}
assertTrue("label not found", found);
}
use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.
the class GraduationTest method renderGraduationTest.
/**
* Sanity test, only ensure the rendering is successfull without errors not the final result.
*/
@Test
public void renderGraduationTest() throws PortrayalException, FactoryException {
final CoordinateReferenceSystem crs = CRS.forCode("EPSG:2154");
final GraduationSymbolizer gs = new GraduationSymbolizer();
final GraduationSymbolizer.Graduation gra = new GraduationSymbolizer.Graduation();
gs.getGraduations().add(gra);
final MutableStyle style = GO2Utilities.STYLE_FACTORY.style(gs);
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(String.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
ftb.addAttribute(LineString.class).setName("geom").setCRS(crs);
final FeatureType type = ftb.build();
final LineString geom = org.geotoolkit.geometry.jts.JTS.getFactory().createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(100, 0) });
geom.setUserData(crs);
final Feature f = type.newInstance();
f.setPropertyValue("id", "id-0");
f.setPropertyValue("geom", geom);
final MapLayer layer = MapBuilder.createLayer(FeatureStoreUtilities.collection(f));
layer.setStyle(style);
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(layer);
final SceneDef sdef = new SceneDef(context);
final CanvasDef cdef = new CanvasDef();
cdef.setDimension(new Dimension(100, 100));
cdef.setBackground(Color.darkGray);
cdef.setEnvelope(CRS.getDomainOfValidity(crs));
final BufferedImage img = DefaultPortrayalService.portray(cdef, sdef);
Assert.assertNotNull(img);
}
use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.
the class MIFFeatureSet method add.
@Override
public void add(Iterator<? extends Feature> newFeatures) throws DataStoreException {
final FeatureType ft = getType();
final MIFReader reader = new MIFReader(store.manager, ft);
try (final MIFWriter writer = new MIFWriter(store.manager, reader)) {
// We remove the features as we get them. We don't need to write them as the default writing behaviour is append mode.
while (writer.hasNext()) {
writer.next();
writer.remove();
}
if (store.manager.getWrittenCRS() != null) {
ReprojectMapper mapper = null;
while (newFeatures.hasNext()) {
Feature f = newFeatures.next();
if (mapper == null) {
final FeatureType type = f.getType();
mapper = new ReprojectMapper(type, store.manager.getWrittenCRS());
}
f = mapper.apply(f);
final Feature candidate = writer.next();
FeatureExt.copy(f, candidate, false);
writer.write();
}
} else {
while (newFeatures.hasNext()) {
final Feature f = newFeatures.next();
final Feature candidate = writer.next();
FeatureExt.copy(f, candidate, false);
writer.write();
}
}
}
}
Aggregations