Search in sources :

Example 11 with FeatureType

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();
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Geometry(org.locationtech.jts.geom.Geometry) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Feature(org.opengis.feature.Feature)

Example 12 with FeatureType

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));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Fill(org.opengis.style.Fill) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) MapLayer(org.apache.sis.portrayal.MapLayer) Point(org.locationtech.jts.geom.Point) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) MutableStyle(org.geotoolkit.style.MutableStyle) Coordinate(org.locationtech.jts.geom.Coordinate) Expression(org.opengis.filter.Expression) SceneDef(org.geotoolkit.display2d.service.SceneDef) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 13 with FeatureType

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);
}
Also used : FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) Fill(org.opengis.style.Fill) Description(org.opengis.style.Description) Hints(org.geotoolkit.factory.Hints) GO2Hints(org.geotoolkit.display2d.GO2Hints) MapLayer(org.apache.sis.portrayal.MapLayer) Unit(javax.measure.Unit) Feature(org.opengis.feature.Feature) Font(org.opengis.style.Font) BufferedImage(java.awt.image.BufferedImage) MutableStyle(org.geotoolkit.style.MutableStyle) SceneDef(org.geotoolkit.display2d.service.SceneDef) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) Raster(java.awt.image.Raster) Point(org.locationtech.jts.geom.Point) Dimension(java.awt.Dimension) Point(org.locationtech.jts.geom.Point) LabelPlacement(org.opengis.style.LabelPlacement) Coordinate(org.locationtech.jts.geom.Coordinate) Expression(org.opengis.filter.Expression) TextSymbolizer(org.opengis.style.TextSymbolizer) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) Halo(org.opengis.style.Halo) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 14 with FeatureType

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);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) MapLayer(org.apache.sis.portrayal.MapLayer) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) BufferedImage(java.awt.image.BufferedImage) MutableStyle(org.geotoolkit.style.MutableStyle) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) SceneDef(org.geotoolkit.display2d.service.SceneDef) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 15 with FeatureType

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();
            }
        }
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) ReprojectMapper(org.geotoolkit.feature.ReprojectMapper) Feature(org.opengis.feature.Feature)

Aggregations

FeatureType (org.opengis.feature.FeatureType)303 Feature (org.opengis.feature.Feature)146 Test (org.junit.Test)122 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)100 GenericName (org.opengis.util.GenericName)70 ArrayList (java.util.ArrayList)65 DataStoreException (org.apache.sis.storage.DataStoreException)56 PropertyType (org.opengis.feature.PropertyType)51 Coordinate (org.locationtech.jts.geom.Coordinate)50 Point (org.locationtech.jts.geom.Point)41 FeatureSet (org.apache.sis.storage.FeatureSet)37 Query (org.geotoolkit.storage.feature.query.Query)36 AttributeType (org.opengis.feature.AttributeType)36 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)33 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)32 WritableFeatureSet (org.apache.sis.storage.WritableFeatureSet)31 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)27 Geometry (org.locationtech.jts.geom.Geometry)27 URL (java.net.URL)26 HashMap (java.util.HashMap)26