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;
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations