Search in sources :

Example 11 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class DefaultStepDefinitions method I_have_a_patch_file.

@Given("^I have a patch file$")
public void I_have_a_patch_file() throws Throwable {
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
    map.put(pointsType.getDescriptor("sp"), diff);
    FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(feaureDiff);
    File file = new File(platform.pwd(), "test.patch");
    BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
    PatchSerializer.write(writer, patch);
    writer.flush();
    writer.close();
}
Also used : FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Given(cucumber.annotation.en.Given)

Example 12 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class RevFeatureTypeImpl method toString.

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("FeatureType[");
    builder.append(getId().toString());
    builder.append("; ");
    boolean first = true;
    for (PropertyDescriptor desc : sortedDescriptors()) {
        if (first) {
            first = false;
        } else {
            builder.append(", ");
        }
        builder.append(desc.getName().getLocalPart());
        builder.append(": ");
        builder.append(desc.getType().getBinding().getSimpleName());
    }
    builder.append(']');
    return builder.toString();
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor)

Example 13 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class DescribeFeatureTypeTest method testDescribeFeatureType.

@Test
public void testDescribeFeatureType() throws Exception {
    DescribeFeatureType describe = new DescribeFeatureType();
    ImmutableSet<PropertyDescriptor> properties = describe.setFeatureType(featureType).call();
    for (PropertyDescriptor prop : properties) {
        assertTrue(pointsType.getDescriptors().contains(prop));
    }
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Test(org.junit.Test)

Example 14 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class ApplyPatchOp method applyPatch.

private void applyPatch(Patch patch) {
    final WorkingTree workTree = workingTree();
    final StagingDatabase indexDb = stagingDatabase();
    if (reverse) {
        patch = patch.reversed();
    }
    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
    }
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        String path = diff.getPath();
        DepthSearch depthSearch = new DepthSearch(indexDb);
        Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
        RevFeatureType oldRevFeatureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();
        RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
        ImmutableList<Optional<Object>> values = feature.getValues();
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Optional<?>> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = values.get(i);
                attrs.put(descriptor.getName(), value);
            }
        }
        Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator.hasNext(); ) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
                Optional<?> oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext(); ) {
            Entry<Name, Optional<?>> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue().orNull());
        }
        SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        workTree.insert(NodeRef.parentPath(path), featureToInsert);
    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        Optional<RevFeatureType> featureType;
        if (diff.getOldFeatureType().isNull()) {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.createTypeTree(diff.getPath(), featureType.get().type());
        } else if (diff.getNewFeatureType().isNull()) {
            workTree.delete(diff.getPath());
        } else {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.updateTypeTree(diff.getPath(), featureType.get().type());
        }
    }
}
Also used : FeatureInfo(org.locationtech.geogig.api.FeatureInfo) Name(org.opengis.feature.type.Name) WorkingTree(org.locationtech.geogig.repository.WorkingTree) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) NodeRef(org.locationtech.geogig.api.NodeRef) Entry(java.util.Map.Entry) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DepthSearch(org.locationtech.geogig.repository.DepthSearch) FeatureTypeDiff(org.locationtech.geogig.api.plumbing.diff.FeatureTypeDiff) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 15 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class ApplyPatchOp method getFeatureType.

private RevFeatureType getFeatureType(FeatureDiff diff, RevFeature oldFeature, RevFeatureType oldRevFeatureType) {
    List<String> removed = Lists.newArrayList();
    List<AttributeDescriptor> added = Lists.newArrayList();
    Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
    for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator.hasNext(); ) {
        Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
        if (entry.getValue().getType() == TYPE.REMOVED) {
            removed.add(entry.getKey().getName().getLocalPart());
        } else if (entry.getValue().getType() == TYPE.ADDED) {
            PropertyDescriptor pd = entry.getKey();
            added.add((AttributeDescriptor) pd);
        }
    }
    SimpleFeatureType sft = (SimpleFeatureType) oldRevFeatureType.type();
    List<AttributeDescriptor> descriptors = (sft).getAttributeDescriptors();
    SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
    featureTypeBuilder.setCRS(sft.getCoordinateReferenceSystem());
    featureTypeBuilder.setDefaultGeometry(sft.getGeometryDescriptor().getLocalName());
    featureTypeBuilder.setName(sft.getName());
    for (int i = 0; i < descriptors.size(); i++) {
        AttributeDescriptor descriptor = descriptors.get(i);
        if (!removed.contains(descriptor.getName().getLocalPart())) {
            featureTypeBuilder.add(descriptor);
        }
    }
    for (AttributeDescriptor descriptor : added) {
        featureTypeBuilder.add(descriptor);
    }
    SimpleFeatureType featureType = featureTypeBuilder.buildFeatureType();
    return RevFeatureTypeImpl.build(featureType);
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Entry(java.util.Map.Entry) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff)

Aggregations

PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)47 RevFeature (org.locationtech.geogig.api.RevFeature)24 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)23 Optional (com.google.common.base.Optional)18 AttributeDiff (org.locationtech.geogig.api.plumbing.diff.AttributeDiff)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 FeatureDiff (org.locationtech.geogig.api.plumbing.diff.FeatureDiff)15 Test (org.junit.Test)12 RevObject (org.locationtech.geogig.api.RevObject)12 GenericAttributeDiffImpl (org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl)11 NodeRef (org.locationtech.geogig.api.NodeRef)10 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)10 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)9 ObjectId (org.locationtech.geogig.api.ObjectId)8 Entry (java.util.Map.Entry)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)6 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)6 GeometryType (org.opengis.feature.type.GeometryType)6 PropertyType (org.opengis.feature.type.PropertyType)6