Search in sources :

Example 46 with FeatureCollection

use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.

the class DifferenceGeometryTest method buildResultList.

private static FeatureCollection buildResultList() throws FactoryException {
    type = createSimpleResultType();
    final FeatureCollection featureList = FeatureStoreUtilities.collection("noname", type);
    geometryFactory = org.geotoolkit.geometry.jts.JTS.getFactory();
    Feature myFeature2 = type.newInstance();
    LinearRing ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(8.0, 6.0), new Coordinate(8.0, 7.0), new Coordinate(11.0, 7.0), new Coordinate(11.0, 4.0), new Coordinate(10.0, 4.0), new Coordinate(10.0, 6.0), new Coordinate(8.0, 6.0) });
    myFeature2.setPropertyValue(AttributeConvention.IDENTIFIER, "id-02");
    myFeature2.setPropertyValue("name", "Building2");
    myFeature2.setPropertyValue("height", 12);
    myFeature2.setPropertyValue("position", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature2);
    Feature myFeature3 = type.newInstance();
    ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(10.0, 1.0), new Coordinate(13.0, 1.0), new Coordinate(13.0, -2.0), new Coordinate(6.0, -2.0), new Coordinate(6.0, 1.0), new Coordinate(10.0, 1.0) });
    myFeature3.setPropertyValue(AttributeConvention.IDENTIFIER, "id-03");
    myFeature3.setPropertyValue("name", "Building3");
    myFeature3.setPropertyValue("height", 12);
    myFeature3.setPropertyValue("position", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature3);
    Feature myFeature4 = type.newInstance();
    ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(3.0, 6.0), new Coordinate(0.0, 6.0), new Coordinate(0.0, 9.0), new Coordinate(3.0, 9.0), new Coordinate(3.0, 6.0) });
    myFeature4.setPropertyValue(AttributeConvention.IDENTIFIER, "id-04");
    myFeature4.setPropertyValue("name", "Building4");
    myFeature4.setPropertyValue("height", 12);
    myFeature4.setPropertyValue("position", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature4);
    Feature myFeature5 = type.newInstance();
    ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(-4.0, 1.0), new Coordinate(-1.0, 1.0), new Coordinate(-1.0, 3.0), new Coordinate(-4.0, 3.0), new Coordinate(-4.0, 1.0) });
    myFeature5.setPropertyValue(AttributeConvention.IDENTIFIER, "id-05");
    myFeature5.setPropertyValue("name", "Building5");
    myFeature5.setPropertyValue("height", 12);
    myFeature5.setPropertyValue("position", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature5);
    return featureList;
}
Also used : FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Feature(org.opengis.feature.Feature)

Example 47 with FeatureCollection

use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.

the class UnionTest method testUnion.

@Test
public void testUnion() throws ProcessException, NoSuchIdentifierException, FactoryException {
    // Inputs
    final FeatureCollection featureList = buildFeatureList();
    final FeatureCollection featureUnionList = buildFeatureUnionList();
    // Process
    ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, "vector:union");
    ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("feature_in").setValue(featureList);
    in.parameter("feature_union").setValue(featureUnionList);
    in.parameter("input_geometry_name").setValue("geom1");
    org.geotoolkit.process.Process proc = desc.createProcess(in);
    // Features out
    final FeatureCollection featureListOut = (FeatureCollection) proc.call().parameter("feature_out").getValue();
    // Expected Features out
    final FeatureCollection featureListResult = buildResultList();
    compare(featureListResult, featureListOut);
}
Also used : FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) AbstractProcessTest(org.geotoolkit.processing.vector.AbstractProcessTest) Test(org.junit.Test)

Example 48 with FeatureCollection

use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.

the class ReportDemo method main.

public static void main(String[] args) throws Exception {
    Demos.init();
    final InputStream template = ReportDemo.class.getResourceAsStream("/data/report/complexReport.jrxml");
    final Entry<JasperReport, FeatureType> entry = JasperReportService.prepareTemplate(template);
    final JasperReport report = entry.getKey();
    final FeatureType type = entry.getValue();
    System.out.println(type);
    // source to make an atlas ----------------------------------------------------
    final FeatureStore store = (FeatureStore) DataStores.open((Map) Collections.singletonMap("path", ReportDemo.class.getResource("/data/world/Countries.shp").toURI()));
    final GenericName name = store.getNames().iterator().next();
    final FeatureCollection countries = store.createSession(true).getFeatureCollection(new Query(name));
    // Iterator over all the countries --------------------------------------------
    final FeatureIterator ite = countries.iterator();
    // We map the feature type to the report type ---------------------------------
    final GenericMappingFeatureIterator mapped = new GenericMappingFeatureIterator(ite, new FeatureMapper() {

        @Override
        public FeatureType getSourceType() {
            return countries.getType();
        }

        @Override
        public FeatureType getTargetType() {
            return type;
        }

        @Override
        public Feature transform(Feature feature) {
            final Feature modified = type.newInstance();
            // create the main map with a single feature ------------------
            final FeatureCollection col = FeatureStoreUtilities.collection(feature);
            final MapLayers context = MapBuilder.createContext();
            final MutableStyle style = RandomStyleBuilder.createRandomVectorStyle(col.getType());
            final MapLayer layer = MapBuilder.createLayer(col);
            layer.setStyle(style);
            context.getComponents().add(layer);
            try {
                // add a custom decoration on our map.
                final GridTemplate gridTemplate = new DefaultGridTemplate(CommonCRS.WGS84.normalizedGeographic(), new BasicStroke(1.5f), new Color(120, 120, 120, 200), new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3, new float[] { 5, 5 }, 0), new Color(120, 120, 120, 60), new Font("serial", Font.BOLD, 12), Color.GRAY, 0, Color.WHITE, new Font("serial", Font.ITALIC, 10), Color.GRAY, 0, Color.WHITE);
                final PortrayalExtension ext = new PortrayalExtension() {

                    @Override
                    public void completeCanvas(J2DCanvas canvas) throws PortrayalException {
                        canvas.getContainer().getRoot().getChildren().add(new GraphicGridJ2D(canvas, gridTemplate));
                    }
                };
                final CanvasDef canvasDef = new CanvasDef(new Dimension(1, 1), null);
                canvasDef.setBackground(Color.WHITE);
                canvasDef.setStretchImage(false);
                canvasDef.setEnvelope(Envelopes.transform(context.getEnvelope().get(), CRS.forCode("EPSG:3395")));
                final SceneDef sceneDef = new SceneDef(context, null, ext);
                final MapDef mapdef = new MapDef(canvasDef, sceneDef, null);
                modified.setPropertyValue("map3", mapdef);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            // casual attributs -------------------
            modified.setPropertyValue("CNTRY_NAME", feature.getProperty("CNTRY_NAME").getValue());
            modified.setPropertyValue("POP_CNTRY", feature.getProperty("POP_CNTRY").getValue());
            // chart -------------------------
            final DefaultPieDataset pds = new DefaultPieDataset();
            pds.setValue((Comparable) feature.getProperty("SOVEREIGN").getValue(), Math.random());
            pds.setValue((Comparable) feature.getProperty("ISO_3DIGIT").getValue(), Math.random());
            final JFreeChart chart = ChartFactory.createPieChart("Info", pds, true, true, Locale.FRENCH);
            modified.setPropertyValue("chart4", new ChartDef(chart));
            // legend --------------------------
            modified.setPropertyValue("legend5", new LegendDef());
            // scale bar -------------------
            modified.setPropertyValue("scalebar6", new ScaleBarDef());
            // north arow -------------------
            modified.setPropertyValue("northarrow7", new NorthArrowDef());
            // subtable --------------
            final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
            ftb.setName("subdata");
            ftb.addAttribute(Integer.class).setName("men");
            ftb.addAttribute(Integer.class).setName("women");
            ftb.addAttribute(String.class).setName("desc");
            final FeatureType subType = ftb.build();
            final FeatureCollection subcol = FeatureStoreUtilities.collection("sub", subType);
            try {
                FeatureWriter fw = subcol.getSession().getFeatureStore().getFeatureWriter(Query.filtered(subType.getName().toString(), Filter.exclude()));
                for (int i = 0, n = new Random().nextInt(20); i < n; i++) {
                    Feature f = fw.next();
                    f.setPropertyValue("men", new Random().nextInt());
                    f.setPropertyValue("women", new Random().nextInt());
                    f.setPropertyValue("desc", "some text from attribut");
                    fw.write();
                }
                fw.close();
            } catch (DataStoreException ex) {
                ex.printStackTrace();
            }
            modified.setPropertyValue("table8", new CollectionDataSource(subcol));
            return modified;
        }
    });
    // Generate the report --------------------------------------------------------
    final OutputDef output = new OutputDef(JasperReportService.MIME_PDF, new File("atlas.pdf"));
    JasperReportService.generateReport(report, mapped, null, output);
}
Also used : BasicStroke(java.awt.BasicStroke) FeatureType(org.opengis.feature.FeatureType) FeatureWriter(org.geotoolkit.storage.feature.FeatureWriter) Query(org.geotoolkit.storage.feature.query.Query) ScaleBarDef(org.geotoolkit.report.graphic.scalebar.ScaleBarDef) MapLayer(org.apache.sis.portrayal.MapLayer) LegendDef(org.geotoolkit.report.graphic.legend.LegendDef) CollectionDataSource(org.geotoolkit.report.CollectionDataSource) JasperReport(net.sf.jasperreports.engine.JasperReport) DefaultGridTemplate(org.geotoolkit.display2d.ext.grid.DefaultGridTemplate) GridTemplate(org.geotoolkit.display2d.ext.grid.GridTemplate) Feature(org.opengis.feature.Feature) Font(java.awt.Font) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) GenericMappingFeatureIterator(org.geotoolkit.storage.memory.GenericMappingFeatureIterator) GenericName(org.opengis.util.GenericName) MutableStyle(org.geotoolkit.style.MutableStyle) Random(java.util.Random) SceneDef(org.geotoolkit.display2d.service.SceneDef) MapDef(org.geotoolkit.report.graphic.map.MapDef) PortrayalExtension(org.geotoolkit.display2d.service.PortrayalExtension) FeatureMapper(org.geotoolkit.storage.memory.mapping.FeatureMapper) J2DCanvas(org.geotoolkit.display2d.canvas.J2DCanvas) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) ChartDef(org.geotoolkit.report.graphic.chart.ChartDef) GraphicGridJ2D(org.geotoolkit.display2d.ext.grid.GraphicGridJ2D) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) DataStoreException(org.apache.sis.storage.DataStoreException) InputStream(java.io.InputStream) DefaultGridTemplate(org.geotoolkit.display2d.ext.grid.DefaultGridTemplate) Color(java.awt.Color) GenericMappingFeatureIterator(org.geotoolkit.storage.memory.GenericMappingFeatureIterator) Dimension(java.awt.Dimension) NorthArrowDef(org.geotoolkit.report.graphic.northarrow.NorthArrowDef) PortrayalException(org.geotoolkit.display.PortrayalException) DataStoreException(org.apache.sis.storage.DataStoreException) JFreeChart(org.jfree.chart.JFreeChart) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) OutputDef(org.geotoolkit.display2d.service.OutputDef) Map(java.util.Map) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) File(java.io.File) MapLayers(org.apache.sis.portrayal.MapLayers) PortrayalException(org.geotoolkit.display.PortrayalException)

Example 49 with FeatureCollection

use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.

the class UnionDemo method buildFeatureList.

/**
 * Build the first FeatureCollection usind createSimpleType() as FeatureType.
 * It define 4 features with basic geometry and property.
 * @return FeatureCollection
 */
private static FeatureCollection buildFeatureList() {
    try {
        type = createSimpleType();
    } catch (FactoryException ex) {
        Logger.getLogger("org.geotoolkit.pending.demo.processing").log(Level.WARNING, null, ex);
    }
    final FeatureCollection featureList = FeatureStoreUtilities.collection("", type);
    Feature myFeature1 = type.newInstance();
    LinearRing ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(3.0, 5.0), new Coordinate(3.0, 7.0), new Coordinate(6.0, 7.0), new Coordinate(6.0, 5.0), new Coordinate(3.0, 5.0) });
    myFeature1.setPropertyValue("id", "id-01");
    myFeature1.setPropertyValue("name", "feature1");
    myFeature1.setPropertyValue("geom1", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature1);
    Feature myFeature2 = type.newInstance();
    ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(6.0, 5.0), new Coordinate(6.0, 7.0), new Coordinate(8.0, 7.0), new Coordinate(8.0, 5.0), new Coordinate(6.0, 5.0) });
    myFeature2.setPropertyValue("id", "id-02");
    myFeature2.setPropertyValue("name", "feature2");
    myFeature2.setPropertyValue("geom1", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature2);
    Feature myFeature3 = type.newInstance();
    ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(6.0, 2.0), new Coordinate(6.0, 5.0), new Coordinate(8.0, 5.0), new Coordinate(8.0, 2.0), new Coordinate(6.0, 2.0) });
    myFeature3.setPropertyValue("id", "id-03");
    myFeature3.setPropertyValue("name", "feature3");
    myFeature3.setPropertyValue("geom1", geometryFactory.createPolygon(ring, null));
    // sfb.set("geom2", line);
    featureList.add(myFeature3);
    Feature myFeature4 = type.newInstance();
    ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(2.0, 3.0), new Coordinate(2.0, 4.0), new Coordinate(3.0, 4.0), new Coordinate(3.0, 3.0), new Coordinate(2.0, 3.0) });
    myFeature4.setPropertyValue("id", "id-04");
    myFeature4.setPropertyValue("name", "feature4");
    myFeature4.setPropertyValue("geom1", geometryFactory.createPolygon(ring, null));
    featureList.add(myFeature4);
    return featureList;
}
Also used : FactoryException(org.opengis.util.FactoryException) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Feature(org.opengis.feature.Feature)

Example 50 with FeatureCollection

use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.

the class UnionDemo method main.

public static void main(String[] args) throws ProcessException, NoSuchIdentifierException {
    Demos.init();
    // Inputs
    final FeatureCollection featureList = buildFeatureList();
    System.out.println("Input FeatureCollection 1 : " + featureList);
    System.out.println("----------------------------------------------------------------------------------------");
    final FeatureCollection featureUnionList = buildFeatureUnionList();
    System.out.println("Input FeatureCollection 2 : " + featureUnionList);
    // get the description of the process we want
    ProcessDescriptor descriptor = ProcessFinder.getProcessDescriptor("geotoolkit", "vector:union");
    // fill process input from process descriptor
    ParameterValueGroup in = descriptor.getInputDescriptor().createValue();
    in.parameter("feature_in").setValue(featureList);
    in.parameter("feature_union").setValue(featureUnionList);
    // the name of the geometry used for the union.
    in.parameter("input_geometry_name").setValue("geom1");
    // create a process with input
    org.geotoolkit.process.Process process = descriptor.createProcess(in);
    // get the result
    final FeatureCollection featuresOut = (FeatureCollection) process.call().parameter("feature_out").getValue();
    System.out.println("----------------------------------------------------------------------------------------");
    System.out.println("Resulting FeatureCollection : " + featuresOut);
}
Also used : FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Aggregations

FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)131 Feature (org.opengis.feature.Feature)75 Test (org.junit.Test)49 Coordinate (org.locationtech.jts.geom.Coordinate)49 LinearRing (org.locationtech.jts.geom.LinearRing)39 Query (org.geotoolkit.storage.feature.query.Query)31 FeatureType (org.opengis.feature.FeatureType)27 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)24 LineString (org.locationtech.jts.geom.LineString)23 MultiPoint (org.locationtech.jts.geom.MultiPoint)16 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)15 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)15 Geometry (org.locationtech.jts.geom.Geometry)14 AbstractProcessTest (org.geotoolkit.processing.vector.AbstractProcessTest)13 Session (org.geotoolkit.storage.feature.session.Session)12 CheckCloseFeatureIterator (org.geotoolkit.storage.feature.CheckCloseFeatureIterator)10 Point (org.locationtech.jts.geom.Point)10 GenericName (org.opengis.util.GenericName)10 NoSuchElementException (java.util.NoSuchElementException)8 File (java.io.File)7