Search in sources :

Example 16 with RevFeatureType

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();
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) FeatureType(org.opengis.feature.type.FeatureType) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) FindOrCreateSubtree(org.locationtech.geogig.api.plumbing.FindOrCreateSubtree) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 17 with RevFeatureType

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;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 18 with RevFeatureType

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();
}
Also used : ReadOSMMapping(org.locationtech.geogig.osm.internal.log.ReadOSMMapping) LineString(com.vividsolutions.jts.geom.LineString) ReadOSMMappingLogEntry(org.locationtech.geogig.osm.internal.log.ReadOSMMappingLogEntry) OSMMappingLogEntry(org.locationtech.geogig.osm.internal.log.OSMMappingLogEntry) NodeRef(org.locationtech.geogig.api.NodeRef) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 19 with RevFeatureType

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;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 20 with RevFeatureType

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;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DefaultEngineeringCRS(org.geotools.referencing.crs.DefaultEngineeringCRS)

Aggregations

RevFeatureType (org.locationtech.geogig.api.RevFeatureType)88 RevFeature (org.locationtech.geogig.api.RevFeature)49 NodeRef (org.locationtech.geogig.api.NodeRef)40 ObjectId (org.locationtech.geogig.api.ObjectId)34 Test (org.junit.Test)31 Optional (com.google.common.base.Optional)28 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)26 RevObject (org.locationtech.geogig.api.RevObject)24 RevTree (org.locationtech.geogig.api.RevTree)24 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)22 SimpleFeature (org.opengis.feature.simple.SimpleFeature)19 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)17 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)14 ImmutableList (com.google.common.collect.ImmutableList)13 File (java.io.File)13 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)13 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)13 List (java.util.List)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)12 AddOp (org.locationtech.geogig.api.porcelain.AddOp)12