Search in sources :

Example 21 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class FidQueryTest method testDeleteFeature.

@Test
public void testDeleteFeature() throws Exception {
    FeatureIterator features = ds.getFeatureReader(new Query(name));
    Feature feature;
    try {
        feature = features.next();
    } finally {
        if (features != null)
            features.close();
    }
    final ResourceId createFidFilter = FeatureExt.getId(feature);
    session.removeFeatures(name.toString(), createFidFilter);
    session.commit();
    fids.remove(FeatureExt.getId(feature).getIdentifier());
    assertEquals(fids.size(), ds.getCount(new Query(name)));
    features = ds.getFeatureReader(Query.filtered(name.toString(), createFidFilter));
    try {
        assertFalse(features.hasNext());
    } finally {
        if (features != null)
            features.close();
    }
    this.assertFidsMatch();
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Query(org.geotoolkit.storage.feature.query.Query) ResourceId(org.opengis.filter.ResourceId) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 22 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class FidQueryTest method testAddFeature.

@Test
@Ignore
public void testAddFeature() throws Exception {
    final FeatureType schema = ds.getFeatureType(ds.getName().toString());
    final Feature newFeature = schema.newInstance();
    final GeometryFactory gf = org.geotoolkit.geometry.jts.JTS.getFactory();
    newFeature.setPropertyValue("a", gf.createPoint((new Coordinate(0, 0))));
    newFeature.setPropertyValue("b", new Long(0));
    newFeature.setPropertyValue("c", new Long(0));
    newFeature.setPropertyValue("d", "Hey");
    final Collection<Feature> collection = new ArrayList<>();
    collection.add(newFeature);
    final List<ResourceId> newFids;
    try (FeatureWriter writer = ds.getFeatureWriter(Query.filtered(name.toString(), Filter.exclude()))) {
        newFids = FeatureStoreUtilities.write(writer, collection);
    }
    assertEquals(1, newFids.size());
    // this.assertFidsMatch();
    final Filter filter = newFids.iterator().next();
    final Query query = new Query();
    query.setTypeName(schema.getName());
    query.setSelection(filter);
    final FeatureIterator features = ds.getFeatureReader(query);
    try {
        final Feature feature = features.next();
        for (PropertyType desc : schema.getProperties(true)) {
            final Object value = feature.getPropertyValue(desc.getName().toString());
            final Object newValue = newFeature.getPropertyValue(desc.getName().toString());
            if (value instanceof Geometry) {
                assertTrue(((Geometry) newValue).equals((Geometry) value));
            } else {
                assertEquals(newValue, value);
            }
        }
        assertFalse(features.hasNext());
    } finally {
        if (features != null)
            features.close();
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureWriter(org.geotoolkit.storage.feature.FeatureWriter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Query(org.geotoolkit.storage.feature.query.Query) ArrayList(java.util.ArrayList) PropertyType(org.opengis.feature.PropertyType) Feature(org.opengis.feature.Feature) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) ResourceId(org.opengis.filter.ResourceId) Filter(org.opengis.filter.Filter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class JDBCAddDelta method commit.

@Override
public Map<String, String> commit(FeatureStore store) throws DataStoreException {
    final DefaultJDBCFeatureStore jdbcstore = (DefaultJDBCFeatureStore) store;
    final Connection cnx = ((JDBCSession) session).getTransaction();
    final List<ResourceId> createdIds = jdbcstore.addFeatures(type, features, cnx, null);
    // iterator and list should have the same size
    final Map<String, String> updates = new HashMap<>();
    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 = (String) f.getPropertyValue(AttributeConvention.IDENTIFIER);
                updates.put(id, createdIds.get(i).getIdentifier());
                i++;
            }
        }
    } finally {
        ite.close();
    }
    features.clear();
    return updates;
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) DefaultJDBCFeatureStore(org.geotoolkit.db.DefaultJDBCFeatureStore) ResourceId(org.opengis.filter.ResourceId) HashMap(java.util.HashMap) Connection(java.sql.Connection) Feature(org.opengis.feature.Feature)

Example 24 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class JDBCSession method removeFeatures.

/**
 * {@inheritDoc }
 * Override here split remove query in order to avoid
 * "stack depth limit exceeded" exception.
 */
@Override
public void removeFeatures(final String groupName, final Filter filter) throws DataStoreException {
    checkVersion();
    // will raise an error if the name doesn't exist
    store.getFeatureType(groupName);
    if (isAsynchrone()) {
        List<Filter<Object>> removeIdFilters = new ArrayList<>();
        // split Id filter
        if (filter instanceof ResourceId) {
            final ResourceId removed = (ResourceId) filter;
            removeIdFilters.add(removed);
        } else {
            Set<ResourceId<Object>> identifiers = new HashSet<>();
            final Query qb = new Query(groupName);
            qb.setSelection(filter);
            final FeatureIterator ite = getFeatureIterator(qb);
            try {
                while (ite.hasNext()) {
                    identifiers.add(FeatureExt.getId(ite.next()));
                    // flush in list of filters
                    if (identifiers.size() == MAX_ID_IN_REQUEST) {
                        removeIdFilters.addAll(identifiers);
                        identifiers.clear();
                    }
                }
                if (!identifiers.isEmpty()) {
                    removeIdFilters.addAll(identifiers);
                }
            } finally {
                ite.close();
            }
            if (removeIdFilters.isEmpty()) {
                // no feature match this filter, no need to create to remove delta
                return;
            }
        }
        for (final Filter removeIdFilter : removeIdFilters) {
            getDiff().add(createRemoveDelta(this, groupName, removeIdFilter));
        }
        fireSessionChanged();
    } else {
        store.removeFeatures(groupName, filter);
    }
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Query(org.geotoolkit.storage.feature.query.Query) Filter(org.opengis.filter.Filter) ResourceId(org.opengis.filter.ResourceId)

Example 25 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class ListingPropertyVisitor method visit.

@Override
public Object visit(final FeatureTypeStyle featureTypeStyle, Object data) {
    final ResourceId ids = featureTypeStyle.getFeatureInstanceIDs();
    if (ids != null) {
        visit(ids, (Collection<String>) data);
    }
    final List<? extends Rule> rules = featureTypeStyle.rules();
    if (rules != null) {
        for (Rule r : rules) {
            data = r.accept(this, data);
        }
    }
    return data;
}
Also used : ResourceId(org.opengis.filter.ResourceId) Rule(org.opengis.style.Rule)

Aggregations

ResourceId (org.opengis.filter.ResourceId)45 Feature (org.opengis.feature.Feature)26 Test (org.junit.Test)23 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)20 FeatureType (org.opengis.feature.FeatureType)20 Query (org.geotoolkit.storage.feature.query.Query)18 HashMap (java.util.HashMap)11 Coordinate (org.locationtech.jts.geom.Coordinate)11 Point (org.locationtech.jts.geom.Point)10 Filter (org.opengis.filter.Filter)10 DataStoreException (org.apache.sis.storage.DataStoreException)9 Session (org.geotoolkit.storage.feature.session.Session)9 Geometry (org.locationtech.jts.geom.Geometry)9 Date (java.util.Date)8 PropertyType (org.opengis.feature.PropertyType)8 ArrayList (java.util.ArrayList)7 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)7 Version (org.geotoolkit.version.Version)6 VersionControl (org.geotoolkit.version.VersionControl)6 IOException (java.io.IOException)5