Search in sources :

Example 1 with Name

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

the class FormatCommonV2 method readAttributeDescriptor.

private static AttributeDescriptor readAttributeDescriptor(DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    final Name name = readName(in);
    final boolean nillable = in.readBoolean();
    final int minOccurs = in.readInt();
    final int maxOccurs = in.readInt();
    final AttributeType type = readAttributeType(in, typeFactory);
    if (type instanceof GeometryType)
        return typeFactory.createGeometryDescriptor((GeometryType) type, name, minOccurs, maxOccurs, nillable, null);
    else
        return typeFactory.createAttributeDescriptor(type, name, minOccurs, maxOccurs, nillable, null);
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) AttributeType(org.opengis.feature.type.AttributeType) Name(org.opengis.feature.type.Name)

Example 2 with Name

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

the class FormatCommonV2 method readFeatureType.

public static RevFeatureType readFeatureType(ObjectId id, DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    Name name = readName(in);
    int propertyCount = readUnsignedVarInt(in);
    List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
    for (int i = 0; i < propertyCount; i++) {
        attributes.add(readAttributeDescriptor(in, typeFactory));
    }
    SimpleFeatureType ftype = typeFactory.createSimpleFeatureType(name, attributes, null, false, Collections.<Filter>emptyList(), BasicFeatureTypes.FEATURE, null);
    return new RevFeatureTypeImpl(id, ftype);
}
Also used : RevFeatureTypeImpl(org.locationtech.geogig.api.RevFeatureTypeImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ArrayList(java.util.ArrayList) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Name(org.opengis.feature.type.Name)

Example 3 with Name

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

the class WorkingTreeTest method testDeleteCollectionOfFeaturesNotPresent.

@Test
public void testDeleteCollectionOfFeaturesNotPresent() throws Exception {
    List<Feature> featureList = new LinkedList<Feature>();
    featureList.add(points1);
    featureList.add(points2);
    workTree.insert(pointsName, featureList.iterator(), LISTENER, null, 3);
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP1)).isPresent());
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP2)).isPresent());
    assertFalse(workTree.findUnstaged(appendChild(pointsName, idP3)).isPresent());
    List<Feature> deleteFeatures = new LinkedList<Feature>();
    deleteFeatures.add(points3);
    Name typeName = points1.getName();
    workTree.delete(typeName, null, deleteFeatures.iterator());
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP1)).isPresent());
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP2)).isPresent());
    assertFalse(workTree.findUnstaged(appendChild(pointsName, idP3)).isPresent());
}
Also used : SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) Name(org.opengis.feature.type.Name) Test(org.junit.Test)

Example 4 with Name

use of org.opengis.feature.type.Name 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 5 with Name

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

the class DiffOpTest method testReportRename.

@Test
public void testReportRename() throws Exception {
    insertAndAdd(lines1);
    final RevCommit commit1 = geogig.command(CommitOp.class).setAll(true).call();
    Feature lines1B = feature(linesType, idL2, "StringProp2_1", new Integer(1000), "LINESTRING (1 1, 2 2)");
    delete(lines1);
    // insert(lines2);
    WorkingTree workTree = repo.workingTree();
    Name name = lines1.getType().getName();
    String parentPath = name.getLocalPart();
    @SuppressWarnings("unused") Node ref = workTree.insert(parentPath, lines1B);
    geogig.command(AddOp.class).call();
    RevCommit commit2 = geogig.command(CommitOp.class).setAll(true).call();
    List<DiffEntry> diffs;
    diffOp.setOldVersion(commit1.getId());
    diffOp.setNewVersion(commit2.getId());
    diffs = toList(diffOp.call());
    // this is reported as an addition and a removal, with both
    assertEquals(2, diffs.size());
    // nodes pointing to same ObjectId
    assertEquals(diffs.get(0).newObjectId(), diffs.get(1).oldObjectId());
    assertEquals(diffs.get(1).newObjectId(), diffs.get(0).oldObjectId());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Node(org.locationtech.geogig.api.Node) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevCommit(org.locationtech.geogig.api.RevCommit) Name(org.opengis.feature.type.Name) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Aggregations

Name (org.opengis.feature.type.Name)26 WorkingTree (org.locationtech.geogig.repository.WorkingTree)9 Test (org.junit.Test)6 Node (org.locationtech.geogig.api.Node)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 ObjectId (org.locationtech.geogig.api.ObjectId)4 Feature (org.opengis.feature.Feature)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 ArrayList (java.util.ArrayList)3 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)3 Optional (com.google.common.base.Optional)2 LinkedList (java.util.LinkedList)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 RevFeatureTypeImpl (org.locationtech.geogig.api.RevFeatureTypeImpl)2 FieldType (org.locationtech.geogig.storage.FieldType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 AttributeType (org.opengis.feature.type.AttributeType)2 GeometryType (org.opengis.feature.type.GeometryType)2 FactoryException (org.opengis.referencing.FactoryException)2