use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class WorkingTree method insert.
/**
* Insert a single feature into the working tree and updates the WORK_HEAD ref.
*
* @param parentTreePath path of the parent tree to insert the feature into
* @param feature the feature to insert
*/
public Node insert(final String parentTreePath, final Feature feature) {
final FeatureType featureType = feature.getType();
NodeRef treeRef;
Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(parentTreePath).call();
ObjectId metadataId;
if (typeTreeRef.isPresent()) {
treeRef = typeTreeRef.get();
RevFeatureType newFeatureType = RevFeatureTypeImpl.build(featureType);
metadataId = newFeatureType.getId().equals(treeRef.getMetadataId()) ? ObjectId.NULL : newFeatureType.getId();
if (!newFeatureType.getId().equals(treeRef.getMetadataId())) {
indexDatabase.put(newFeatureType);
}
} else {
treeRef = createTypeTree(parentTreePath, featureType);
// treeRef.getMetadataId();
metadataId = ObjectId.NULL;
}
// ObjectId metadataId = treeRef.getMetadataId();
final Node node = putInDatabase(feature, metadataId);
RevTreeBuilder parentTree = context.command(FindOrCreateSubtree.class).setIndex(true).setParent(Suppliers.ofInstance(Optional.of(getTree()))).setChildPath(parentTreePath).call().builder(indexDatabase);
parentTree.put(node);
final ObjectId treeMetadataId = treeRef.getMetadataId();
ObjectId newTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()).setChildPath(parentTreePath).setToIndex(true).setTree(parentTree.build()).setMetadataId(treeMetadataId).call();
updateWorkHead(newTree);
final String featurePath = NodeRef.appendChild(parentTreePath, node.getName());
Optional<NodeRef> featureRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(featurePath).call();
return featureRef.get().getNode();
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class RevTreeBuilder2 method putFeature.
public Node putFeature(final ObjectId id, final String name, @Nullable final BoundingBox bounds, final FeatureType type) {
Envelope bbox;
if (bounds == null) {
bbox = null;
} else if (bounds instanceof Envelope) {
bbox = (Envelope) bounds;
} else {
bbox = new Envelope(bounds.getMinimum(0), bounds.getMaximum(0), bounds.getMinimum(1), bounds.getMaximum(1));
}
RevFeatureType revFeatureType = revFeatureTypes.get(type.getName());
if (null == revFeatureType) {
revFeatureType = RevFeatureTypeImpl.build(type);
revFeatureTypes.put(type.getName(), revFeatureType);
}
ObjectId metadataId = revFeatureType.getId().equals(defaultMetadataId) ? ObjectId.NULL : revFeatureType.getId();
Node node = Node.create(name, id, metadataId, TYPE.FEATURE, bbox);
put(node);
return node;
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class OSMUnmapOp method _call.
@Override
protected RevTree _call() {
Optional<OSMMappingLogEntry> entry = command(ReadOSMMappingLogEntry.class).setPath(path).call();
if (entry.isPresent()) {
Optional<Mapping> opt = command(ReadOSMMapping.class).setEntry(entry.get()).call();
if (opt.isPresent()) {
mapping = opt.get();
}
}
Iterator<NodeRef> iter = command(LsTreeOp.class).setReference(path).setStrategy(Strategy.FEATURES_ONLY).call();
FeatureMapFlusher flusher = new FeatureMapFlusher(workingTree());
while (iter.hasNext()) {
NodeRef node = iter.next();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class).get();
List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
String id = null;
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
if (descriptor.getName().getLocalPart().equals("id")) {
id = values.get(i).get().toString();
}
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
Preconditions.checkNotNull(id, "No 'id' attribute found");
SimpleFeature feature = featureBuilder.buildFeature(id);
unmapFeature(feature, flusher);
}
flusher.flushAll();
if (entry.isPresent()) {
Iterator<DiffEntry> diffs = command(DiffTree.class).setPathFilter(path).setNewTree(workingTree().getTree().getId()).setOldTree(entry.get().getPostMappingId()).call();
while (diffs.hasNext()) {
DiffEntry diff = diffs.next();
if (diff.changeType().equals(DiffEntry.ChangeType.REMOVED)) {
ObjectId featureId = diff.getOldObject().getNode().getObjectId();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(featureId).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(diff.getOldObject().getMetadataId()).call(RevFeatureType.class).get();
List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
String id = null;
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
if (descriptor.getName().getLocalPart().equals("id")) {
id = values.get(i).get().toString();
}
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
Preconditions.checkNotNull(id, "No 'id' attribute found");
SimpleFeature feature = featureBuilder.buildFeature(id);
Class<?> clazz = feature.getDefaultGeometryProperty().getType().getBinding();
String deletePath = clazz.equals(Point.class) ? OSMUtils.NODE_TYPE_NAME : OSMUtils.WAY_TYPE_NAME;
workingTree().delete(deletePath, id);
}
}
}
return workingTree().getTree();
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class ResolveFeatureType method _call.
@Override
protected Optional<RevFeatureType> _call() {
Preconditions.checkState(refSpec != null, "ref spec has not been set.");
final String fullRefspec;
if (refSpec.contains(":")) {
fullRefspec = refSpec;
} else {
fullRefspec = Ref.WORK_HEAD + ":" + refSpec;
}
final String ref = fullRefspec.substring(0, fullRefspec.indexOf(':'));
final String path = fullRefspec.substring(fullRefspec.indexOf(':') + 1);
ObjectId parentId = command(ResolveTreeish.class).setTreeish(ref).call().get();
Optional<RevTree> parent = command(RevObjectParse.class).setObjectId(parentId).call(RevTree.class);
if (!parent.isPresent()) {
return Optional.absent();
}
Optional<NodeRef> node = command(FindTreeChild.class).setParent(parent.get()).setChildPath(path).setIndex(true).call();
if (!node.isPresent()) {
return Optional.absent();
}
NodeRef found = node.get();
ObjectId metadataID = found.getMetadataId();
Optional<RevFeatureType> ft = command(RevObjectParse.class).setObjectId(metadataID).call(RevFeatureType.class);
return ft;
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class BoundsFilteringDiffConsumer method createProjectedFilter.
private ReferencedEnvelope createProjectedFilter(ObjectId metadataId) {
final ReferencedEnvelope boundsFilter = this.boundsFilter;
RevFeatureType featureType = ftypeSource.getFeatureType(metadataId);
CoordinateReferenceSystem nativeCrs = featureType.type().getCoordinateReferenceSystem();
if (null == nativeCrs || nativeCrs instanceof DefaultEngineeringCRS) {
return boundsFilter;
}
ReferencedEnvelope transformedFilter;
try {
transformedFilter = boundsFilter.transform(nativeCrs, true);
} catch (TransformException | FactoryException e) {
throw Throwables.propagate(e);
}
return transformedFilter;
}
Aggregations