Search in sources :

Example 1 with FeatureId

use of org.opengis.filter.identity.FeatureId in project spatial-portal by AtlasOfLivingAustralia.

the class AreaUploadShapefileWizardController method onClick$btnRefresh.

public void onClick$btnRefresh(Event event) {
    Iterator<Listitem> it = lAttributes.getSelectedItems().iterator();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    Set<FeatureId> fids = new HashSet<FeatureId>();
    while (it.hasNext()) {
        Listitem li = it.next();
        fids.add(ff.featureId(li.getValue().toString()));
    }
    executeShapeImageRenderer(ff.id(fids));
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) FilterFactory2(org.opengis.filter.FilterFactory2)

Example 2 with FeatureId

use of org.opengis.filter.identity.FeatureId in project GeoGig by boundlessgeo.

the class FeatureBuilder method buildLazy.

public Feature buildLazy(final String id, final Node node, final RevObjectParse parser) {
    Supplier<? extends List<Optional<Object>>> valueSupplier = new LazyFeatureLoader(node.getObjectId(), parser);
    valueSupplier = Suppliers.memoize(valueSupplier);
    final FeatureId fid = new LazyVersionedFeatureId(id, node.getObjectId());
    GeogigSimpleFeature feature = new GeogigSimpleFeature(valueSupplier, (SimpleFeatureType) featureType, fid, attNameToRevTypeIndex, node);
    return feature;
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) Optional(com.google.common.base.Optional)

Example 3 with FeatureId

use of org.opengis.filter.identity.FeatureId in project GeoGig by boundlessgeo.

the class GeoGigFeatureStoreTest method testAddFeaturesOnASeparateBranch.

@Test
public void testAddFeaturesOnASeparateBranch() throws Exception {
    final String branchName = "addtest";
    final Ref branchRef = geogig.command(BranchCreateOp.class).setName(branchName).call();
    dataStore.setHead(branchName);
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
    collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
    Transaction tx = new DefaultTransaction();
    points.setTransaction(tx);
    assertSame(tx, points.getTransaction());
    try {
        List<FeatureId> addedFeatures = points.addFeatures(collection);
        assertNotNull(addedFeatures);
        assertEquals(3, addedFeatures.size());
        // assert transaction isolation
        assertEquals(3, points.getFeatures().size());
        assertEquals(0, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
        tx.commit();
        assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) Ref(org.locationtech.geogig.api.Ref) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Example 4 with FeatureId

use of org.opengis.filter.identity.FeatureId in project GeoGig by boundlessgeo.

the class GeoGigFeatureStoreTest method testUseProvidedFIDSupported.

@Test
public void testUseProvidedFIDSupported() throws Exception {
    assertTrue(points.getQueryCapabilities().isUseProvidedFIDSupported());
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
    collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
    Transaction tx = new DefaultTransaction();
    points.setTransaction(tx);
    try {
        List<FeatureId> newFids = points.addFeatures(collection);
        assertNotNull(newFids);
        assertEquals(3, newFids.size());
        FeatureId fid1 = newFids.get(0);
        FeatureId fid2 = newFids.get(1);
        FeatureId fid3 = newFids.get(2);
        // new ids should have been generated...
        assertFalse(idP1.equals(fid1.getID()));
        assertFalse(idP1.equals(fid1.getID()));
        assertFalse(idP1.equals(fid1.getID()));
        // now force the use of provided feature ids
        points1.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
        points2.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
        points3.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
        List<FeatureId> providedFids = points.addFeatures(collection);
        assertNotNull(providedFids);
        assertEquals(3, providedFids.size());
        FeatureId fid11 = providedFids.get(0);
        FeatureId fid21 = providedFids.get(1);
        FeatureId fid31 = providedFids.get(2);
        // ids should match provided
        assertEquals(idP1, fid11.getID());
        assertEquals(idP2, fid21.getID());
        assertEquals(idP3, fid31.getID());
        tx.commit();
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid1))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid2))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid3))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid11))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid21))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid31))).size());
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Example 5 with FeatureId

use of org.opengis.filter.identity.FeatureId in project GeoGig by boundlessgeo.

the class GeoGigFeatureStoreTest method testAddFeatures.

@Test
public void testAddFeatures() throws Exception {
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
    collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
    try {
        points.addFeatures(collection);
        fail("Expected UnsupportedOperationException on AUTO_COMMIT");
    } catch (UnsupportedOperationException e) {
        assertTrue(e.getMessage().contains("AUTO_COMMIT"));
    }
    Transaction tx = new DefaultTransaction();
    points.setTransaction(tx);
    assertSame(tx, points.getTransaction());
    try {
        List<FeatureId> addedFeatures = points.addFeatures(collection);
        assertNotNull(addedFeatures);
        assertEquals(3, addedFeatures.size());
        for (FeatureId id : addedFeatures) {
            assertFalse(id instanceof ResourceId);
            assertNotNull(id.getFeatureVersion());
        }
        // assert transaction isolation
        assertEquals(3, points.getFeatures().size());
        assertEquals(0, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
        tx.commit();
        assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) ResourceId(org.opengis.filter.identity.ResourceId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Aggregations

FeatureId (org.opengis.filter.identity.FeatureId)13 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)6 Test (org.junit.Test)5 DefaultTransaction (org.geotools.data.DefaultTransaction)4 Transaction (org.geotools.data.Transaction)4 IOException (java.io.IOException)3 Feature (org.opengis.feature.Feature)3 Optional (com.google.common.base.Optional)2 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)2 Property (org.opengis.feature.Property)2 ResourceId (org.opengis.filter.identity.ResourceId)2 ParseException (com.vividsolutions.jts.io.ParseException)1 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1