Search in sources :

Example 11 with FeatureIterator

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

the class PostgresVersioningTest method testTrimVersioning.

@Test
public void testTrimVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Feature feature;
    ResourceId fid;
    Version v0;
    Version v1;
    Version v2;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    // get identifier
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make a 2nd update ///////////////////////////////////////////////////////
    final Point thirdPoint = GF.createPoint(new Coordinate(145, -221));
    final Map<String, Object> updates2 = new HashMap<>();
    updates2.put("boolean", Boolean.FALSE);
    updates2.put("integer", 150);
    updates2.put("point", thirdPoint);
    updates2.put("string", "secondtextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates2);
    // get all versions organized in increase dates order.
    versions = vc.list();
    assertEquals(3, versions.size());
    v0 = versions.get(0);
    v1 = versions.get(1);
    v2 = versions.get(2);
    /* first trim between v1 date and v2 date (named middle date) to verify
         * deletion of first version and update v1 date at trim date.*/
    final Date middle = new Date((v1.getDate().getTime() + v2.getDate().getTime()) >> 1);
    vc.trim(middle);
    versions = vc.list();
    assertEquals(2, versions.size());
    // ensure version 0 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v0.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure version v1 begin at middle date.
    assertEquals(vc.list().get(0).getDate().getTime(), middle.getTime());
    /* second trim at exactely the begining of the third version to verify,
         * deletion of second version and third version existence.*/
    vc.trim(v2);
    versions = vc.list();
    assertEquals(1, versions.size());
    // ensure version 1 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure version v2 begin time doesn't change.
    assertEquals(vc.list().get(0).getDate().getTime(), v2.getDate().getTime());
    /* third trim just after v3 version date, to verify that v3
         * version date become trim date */
    final long lastDate = v2.getDate().getTime() + 400;
    vc.trim(new Date(lastDate));
    versions = vc.list();
    assertEquals(1, versions.size());
    // ensure version v2 begin time become lastDate.
    assertEquals(vc.list().get(0).getDate().getTime(), lastDate);
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Test(org.junit.Test)

Example 12 with FeatureIterator

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

the class PostgresVersioningTest method testRevertVersioning.

@Test
public void testRevertVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Feature feature;
    ResourceId fid;
    Version v0;
    Version v1;
    Version v2;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    // get identifier
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make a remove ///////////////////////////////////////////////////////
    store.removeFeatures(refType.getName().toString(), fid);
    // ensure test table is empty
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // get all versions organized in increase dates order.
    versions = vc.list();
    assertEquals(3, versions.size());
    v0 = versions.get(0);
    v1 = versions.get(1);
    v2 = versions.get(2);
    /* first revert between v1 date and v2 date (named middle date) to verify
         * re - insertion of feature in the original base and update v2 ending date become null.*/
    // =/2
    final Date middle = new Date((v1.getDate().getTime() + v2.getDate().getTime()) >> 1);
    vc.revert(middle);
    versions = vc.list();
    assertEquals(2, versions.size());
    // ensure version v2 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure test table contain feature from version 1
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertFalse(store.createSession(true).getFeatureCollection(qb).isEmpty());
    Feature featV1;
    Feature feat;
    // feature from test base result.
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feat = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // feature from version v1.
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        featV1 = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    assertTrue(feat.getProperty("boolean").equals(featV1.getProperty("boolean")));
    assertTrue(feat.getProperty("integer").equals(featV1.getProperty("integer")));
    assertTrue(feat.getProperty("point").equals(featV1.getProperty("point")));
    assertTrue(feat.getProperty("string").equals(featV1.getProperty("string")));
    /* second revert at v0 begin date to verify update roll back, and verify
         * feature update from history table into original base.*/
    vc.revert(v0.getDate());
    versions = vc.list();
    assertEquals(1, versions.size());
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure test table contain feature from version 1
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertFalse(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // feature from test base result.
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feat = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // feature from version v1.
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v0.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        featV1 = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    assertTrue(feat.getProperty("boolean").equals(featV1.getProperty("boolean")));
    assertTrue(feat.getProperty("integer").equals(featV1.getProperty("integer")));
    assertTrue(feat.getProperty("point").equals(featV1.getProperty("point")));
    assertTrue(feat.getProperty("string").equals(featV1.getProperty("string")));
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Test(org.junit.Test)

Example 13 with FeatureIterator

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

the class PostgresVersioningTest method testSimpleTypeVersioning.

@Test
public void testSimpleTypeVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Version version;
    Feature feature;
    ResourceId fid;
    Version v1;
    Version v2;
    Version v3;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    assertNotNull(store.getQueryCapabilities());
    assertTrue(store.getQueryCapabilities().handleVersioning());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // //////////////////////////////////////////////////////////////////////
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // check the version table is not visible in the feature types
    store.refreshMetaModel();
    final Set<GenericName> names = store.getNames();
    assertEquals(1, names.size());
    // //////////////////////////////////////////////////////////////////////
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    version = versions.get(0);
    Date date = version.getDate();
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // ensure normal reading is correct with version-------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(version.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // //////////////////////////////////////////////////////////////////////
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    // we should have two versions
    versions = vc.list();
    assertEquals(2, versions.size());
    v1 = versions.get(0);
    v2 = versions.get(1);
    // should be ordered starting from the oldest
    assertTrue(v1.getDate().compareTo(v2.getDate()) < 0);
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getPropertyValue("boolean"));
        assertEquals(-3, feature.getPropertyValue("integer"));
        assertEquals(secondPoint, feature.getPropertyValue("point"));
        assertEquals("anothertextupdated", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure normal reading is correct with version-------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getPropertyValue("boolean"));
        assertEquals(-3, feature.getPropertyValue("integer"));
        assertEquals(secondPoint, feature.getPropertyValue("point"));
        assertEquals("anothertextupdated", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure reading a previous version works ------------------------------
    qb = new Query();
    ;
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure reading a previous version using not exact date----------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionDate(new Date(v1.getDate().getTime() + 400));
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // delete record ////////////////////////////////////////////////////////
    store.removeFeatures(refType.getName().toString(), fid);
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertEquals(0, store.getCount(qb));
    // we should have three versions
    versions = vc.list();
    assertEquals(3, versions.size());
    v1 = versions.get(0);
    v2 = versions.get(1);
    v3 = versions.get(2);
    // should be ordered starting from the oldest
    assertTrue(v2.getDate().compareTo(v1.getDate()) > 0);
    assertTrue(v3.getDate().compareTo(v2.getDate()) > 0);
    // ensure we have nothing if no version set -----------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure we have nothing if latest version set -------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v3.getLabel());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure we have nothing with date after deletion ----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionDate(new Date(v3.getDate().getTime() + 400));
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure reading version 1 works ---------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getProperty("boolean").getValue());
        assertEquals(14, feature.getProperty("integer").getValue());
        assertEquals(firstPoint, feature.getProperty("point").getValue());
        assertEquals("someteststring", feature.getProperty("string").getValue());
    } finally {
        ite.close();
    }
    // ensure reading version 2 works ---------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getProperty("boolean").getValue());
        assertEquals(-3, feature.getProperty("integer").getValue());
        assertEquals(secondPoint, feature.getProperty("point").getValue());
        assertEquals("anothertextupdated", feature.getProperty("string").getValue());
    } finally {
        ite.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // drop versioning //////////////////////////////////////////////////////
    vc.dropVersioning();
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // ensure we have no record----------------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) GenericName(org.opengis.util.GenericName) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) Test(org.junit.Test)

Example 14 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator 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 15 with FeatureIterator

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

the class AddDelta method commit.

/**
 * {@inheritDoc }
 */
@Override
public Map<String, String> commit(final FeatureStore store) throws DataStoreException {
    final List<ResourceId> createdIds = store.addFeatures(type.toString(), features);
    // iterator and list should have the same size
    final Map<String, String> updates = new HashMap<String, String>();
    final FeatureIterator ite = features.iterator();
    int i = 0;
    try {
        if (createdIds != null && !createdIds.isEmpty()) {
            while (ite.hasNext()) {
                final Feature f = ite.next();
                final String id = FeatureExt.getId(f).getIdentifier();
                updates.put(id, createdIds.get(i).getIdentifier());
                i++;
            }
        }
    } finally {
        ite.close();
    }
    features.clear();
    return updates;
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) ResourceId(org.opengis.filter.ResourceId) HashMap(java.util.HashMap) Feature(org.opengis.feature.Feature)

Aggregations

FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)53 Feature (org.opengis.feature.Feature)41 Test (org.junit.Test)34 Query (org.geotoolkit.storage.feature.query.Query)30 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)24 FeatureType (org.opengis.feature.FeatureType)20 ResourceId (org.opengis.filter.ResourceId)20 Coordinate (org.locationtech.jts.geom.Coordinate)11 Point (org.locationtech.jts.geom.Point)11 Session (org.geotoolkit.storage.feature.session.Session)10 Geometry (org.locationtech.jts.geom.Geometry)10 HashMap (java.util.HashMap)9 CheckCloseFeatureIterator (org.geotoolkit.storage.feature.CheckCloseFeatureIterator)9 ArrayList (java.util.ArrayList)8 Date (java.util.Date)7 NoSuchElementException (java.util.NoSuchElementException)7 Filter (org.opengis.filter.Filter)7 File (java.io.File)6 Version (org.geotoolkit.version.Version)6 VersionControl (org.geotoolkit.version.VersionControl)6