Search in sources :

Example 6 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 7 with FeatureId

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

the class AreaUploadShapefileWizardController method loadShape.

private void loadShape(String filename) {
    CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    try {
        FileDataStore store = FileDataStoreFinder.getDataStore(new File(filename));
        source = store.getFeatureSource();
        features = source.getFeatures();
        Listhead lhd = new Listhead();
        SimpleFeatureType schema = features.getSchema();
        Listheader lh = new Listheader(StringConstants.ID);
        lh.setParent(lhd);
        for (AttributeType at : schema.getTypes()) {
            if (schema.getDescriptor(at.getName()) == null) {
                continue;
            }
            lh = new Listheader(at.getName().toString());
            lh.setParent(lhd);
        }
        lhd.setParent(lAttributes);
        SimpleFeatureIterator fi = features.features();
        while (fi.hasNext()) {
            SimpleFeature f = fi.next();
            Listitem li = new Listitem();
            Listcell lc;
            String value;
            //add identifier
            lc = new Listcell(f.getIdentifier().getID());
            lc.setParent(li);
            for (AttributeType at : schema.getTypes()) {
                if (schema.getDescriptor(at.getName()) == null) {
                    continue;
                }
                Object obj = f.getAttribute(at.getName());
                if (obj == null) {
                    value = f.getID();
                } else {
                    value = String.valueOf(obj);
                }
                lc = new Listcell(value);
                lc.setParent(li);
            }
            li.setValue(f.getIdentifier());
            li.setParent(lAttributes);
        }
        // loadFeatures
        // check if only a single feature,
        // if so, then select it and map it automatically
        LOGGER.debug("features.size(): " + features.size());
        if (features.size() > 1) {
            executeShapeImageRenderer(null);
        } else {
            LOGGER.debug("only a single feature, bypassing wizard...");
            fi = features.features();
            Set<FeatureId> ids = new HashSet<FeatureId>();
            ids.add(fi.next().getIdentifier());
            loadOnMap(ids, filename);
            //echo detach
            Events.echoEvent("onClick$btnCancel", this, null);
        }
        try {
            fi.close();
        } catch (Exception e) {
        }
    } catch (IOException e) {
        LOGGER.debug("IO Exception ", e);
    } catch (Exception e) {
        LOGGER.debug("Generic exception", e);
    }
}
Also used : IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ParseException(com.vividsolutions.jts.io.ParseException) IOException(java.io.IOException) FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeType(org.opengis.feature.type.AttributeType) FileDataStore(org.geotools.data.FileDataStore) File(java.io.File)

Example 8 with FeatureId

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

the class GeoGigFeatureStoreTest method testAddFeaturesWhileNotOnABranch.

@Test
public void testAddFeaturesWhileNotOnABranch() throws Exception {
    boolean gotIllegalStateException = false;
    final ObjectId head = geogig.command(RevParse.class).setRefSpec("HEAD").call().get();
    dataStore.setHead(head.toString());
    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 (IllegalStateException e) {
        tx.rollback();
        gotIllegalStateException = true;
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
    assertTrue("Should throw IllegalStateException when trying to modify data in geogig datastore when it is not configured with a branch.", gotIllegalStateException);
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Example 9 with FeatureId

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

the class FeatureBuilder method build.

/**
     * Builds a {@link Feature} from the provided {@link RevFeature}.
     * 
     * @param id the id of the new feature
     * @param revFeature the {@code RevFeature} with the property values for the feature
     * @return the constructed {@code Feature}
     */
public Feature build(final String id, final RevFeature revFeature) {
    Preconditions.checkNotNull(id);
    Preconditions.checkNotNull(revFeature);
    final FeatureId fid = new LazyVersionedFeatureId(id, revFeature.getId());
    ImmutableList<Optional<Object>> values = revFeature.getValues();
    GeogigSimpleFeature feature = new GeogigSimpleFeature(values, (SimpleFeatureType) featureType, fid, attNameToRevTypeIndex);
    return feature;
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) Optional(com.google.common.base.Optional)

Example 10 with FeatureId

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

the class GeogigFeatureStore method addFeatures.

@Override
public final List<FeatureId> addFeatures(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection) throws IOException {
    if (Transaction.AUTO_COMMIT.equals(getTransaction())) {
        throw new UnsupportedOperationException("GeoGIG does not support AUTO_COMMIT");
    }
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    final WorkingTree workingTree = delegate.getWorkingTree();
    final String path = delegate.getTypeTreePath();
    ProgressListener listener = new DefaultProgressListener();
    final List<FeatureId> insertedFids = Lists.newArrayList();
    List<Node> deferringTarget = new AbstractList<Node>() {

        @Override
        public boolean add(Node node) {
            String fid = node.getName();
            String version = node.getObjectId().toString();
            insertedFids.add(new FeatureIdVersionedImpl(fid, version));
            return true;
        }

        @Override
        public Node get(int index) {
            throw new UnsupportedOperationException();
        }

        @Override
        public int size() {
            return 0;
        }
    };
    Integer count = (Integer) null;
    FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
    try {
        Iterator<SimpleFeature> features;
        features = new FeatureIteratorIterator<SimpleFeature>(featureIterator);
        /*
             * Make sure to transform the incoming features to the native schema to avoid situations
             * where geogig would change the metadataId of the RevFeature nodes due to small
             * differences in the default and incoming schema such as namespace or missing
             * properties
             */
        final SimpleFeatureType nativeSchema = delegate.getNativeType();
        features = Iterators.transform(features, new SchemaInforcer(nativeSchema));
        workingTree.insert(path, features, listener, deferringTarget, count);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        featureIterator.close();
    }
    return insertedFids;
}
Also used : AbstractList(java.util.AbstractList) Node(org.locationtech.geogig.api.Node) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) FeatureId(org.opengis.filter.identity.FeatureId) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) ProgressListener(org.locationtech.geogig.api.ProgressListener) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureIdVersionedImpl(org.geotools.filter.identity.FeatureIdVersionedImpl)

Aggregations

FeatureId (org.opengis.filter.identity.FeatureId)10 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)6 Test (org.junit.Test)5 DefaultTransaction (org.geotools.data.DefaultTransaction)4 Transaction (org.geotools.data.Transaction)4 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)2 ResourceId (org.opengis.filter.identity.ResourceId)2 ParseException (com.vividsolutions.jts.io.ParseException)1 File (java.io.File)1 AbstractList (java.util.AbstractList)1 HashMap (java.util.HashMap)1 FileDataStore (org.geotools.data.FileDataStore)1 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)1 FeatureIdVersionedImpl (org.geotools.filter.identity.FeatureIdVersionedImpl)1 DefaultProgressListener (org.locationtech.geogig.api.DefaultProgressListener)1 Node (org.locationtech.geogig.api.Node)1 NodeRef (org.locationtech.geogig.api.NodeRef)1