Search in sources :

Example 46 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class RevFeatureTypeSerializationTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
    ObjectWriter<RevFeatureType> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    writer.write(revFeatureType, output);
    byte[] data = output.toByteArray();
    assertTrue(data.length > 0);
    ObjectReader<RevFeatureType> reader = factory.createObjectReader(TYPE.FEATURETYPE);
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    RevFeatureType rft = reader.read(revFeatureType.getId(), input);
    assertNotNull(rft);
    SimpleFeatureType serializedFeatureType = (SimpleFeatureType) rft.type();
    assertEquals(serializedFeatureType.getDescriptors().size(), featureType.getDescriptors().size());
    for (int i = 0; i < featureType.getDescriptors().size(); i++) {
        assertEquals(featureType.getDescriptor(i), serializedFeatureType.getDescriptor(i));
    }
    assertEquals(featureType.getGeometryDescriptor(), serializedFeatureType.getGeometryDescriptor());
    assertEquals(featureType.getCoordinateReferenceSystem(), serializedFeatureType.getCoordinateReferenceSystem());
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 47 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class ImportOpTest method testAdaptFeatureType.

@Test
public void testAdaptFeatureType() throws Exception {
    ImportOp importOp = geogig.command(ImportOp.class);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setTable("shpLikeTable");
    importOp.setDestinationPath("table");
    importOp.call();
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    RevFeatureType originalFeatureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
    importOp.setTable("shpLikeTable2");
    importOp.call();
    feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    RevFeatureType featureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
    assertEquals(originalFeatureType.getId(), featureType.getId());
    GeometryFactory gf = new GeometryFactory();
    ImmutableList<Optional<Object>> values = feature.get().getValues();
    assertEquals(values.get(0).get(), gf.createPoint(new Coordinate(0, 7)));
    assertEquals(values.get(1).get(), 3.2);
    assertEquals(values.get(2).get(), 1100.0);
    importOp.setTable("GeoJsonLikeTable");
    importOp.call();
    feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    featureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
    assertEquals(originalFeatureType.getId(), featureType.getId());
    values = feature.get().getValues();
    assertEquals(values.get(0).get(), gf.createPoint(new Coordinate(0, 8)));
    assertEquals(values.get(1).get(), 4.2);
    assertEquals(values.get(2).get(), 1200.0);
}
Also used : ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Optional(com.google.common.base.Optional) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 48 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class CreatePatchOp method _call.

@Override
protected Patch _call() {
    Patch patch = new Patch();
    Map<ObjectId, RevFeatureType> featureTypes = Maps.newHashMap();
    while (diffs.hasNext()) {
        DiffEntry diffEntry = diffs.next();
        final NodeRef newObject = diffEntry.getNewObject();
        final NodeRef oldObject = diffEntry.getOldObject();
        if (diffEntry.changeType() == ChangeType.MODIFIED) {
            RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.newObjectId()).call().get();
            if (revObject instanceof RevFeature) {
                FeatureDiff diff = command(DiffFeature.class).setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject())).setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call();
                patch.addModifiedFeature(diff);
            } else if (revObject instanceof RevTree) {
                RevFeatureType oldFeatureType = command(RevObjectParse.class).setObjectId(diffEntry.getOldObject().getMetadataId()).call(RevFeatureType.class).get();
                RevFeatureType newFeatureType = command(RevObjectParse.class).setObjectId(diffEntry.getNewObject().getMetadataId()).call(RevFeatureType.class).get();
                patch.addFeatureType(oldFeatureType);
                patch.addFeatureType(newFeatureType);
                patch.addAlteredTree(diffEntry);
            }
        } else if (diffEntry.changeType() == ChangeType.ADDED) {
            RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.newObjectId()).call().get();
            if (revObject instanceof RevFeature) {
                RevFeatureType featureType;
                if (featureTypes.containsKey(newObject.getMetadataId())) {
                    featureType = featureTypes.get(newObject.getMetadataId());
                } else {
                    featureType = command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call(RevFeatureType.class).get();
                    featureTypes.put(newObject.getMetadataId(), featureType);
                }
                FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
                Feature feature = featureBuilder.build(diffEntry.newObjectId().toString(), (RevFeature) revObject);
                String name = diffEntry.newPath();
                patch.addAddedFeature(name, feature, featureType);
            } else if (revObject instanceof RevTree) {
                ObjectId metadataId = diffEntry.getNewObject().getMetadataId();
                if (!metadataId.isNull()) {
                    RevFeatureType featureType = command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class).get();
                    patch.addAlteredTree(diffEntry);
                    patch.addFeatureType(featureType);
                }
            }
        } else if (diffEntry.changeType() == ChangeType.REMOVED) {
            RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.oldObjectId()).call().get();
            if (revObject instanceof RevFeature) {
                RevFeatureType featureType;
                if (featureTypes.containsKey(oldObject.getMetadataId())) {
                    featureType = featureTypes.get(oldObject.getMetadataId());
                } else {
                    featureType = command(RevObjectParse.class).setObjectId(oldObject.getMetadataId()).call(RevFeatureType.class).get();
                    featureTypes.put(oldObject.getMetadataId(), featureType);
                }
                FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
                Feature feature = featureBuilder.build(diffEntry.oldObjectId().toString(), (RevFeature) revObject);
                String name = diffEntry.oldPath();
                patch.addRemovedFeature(name, feature, featureType);
            } else if (revObject instanceof RevTree) {
                ObjectId metadataId = diffEntry.getOldObject().getMetadataId();
                if (!metadataId.isNull()) {
                    RevFeatureType featureType = command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class).get();
                    patch.addAlteredTree(diffEntry);
                    patch.addFeatureType(featureType);
                }
            }
        }
    }
    return patch;
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) DiffFeature(org.locationtech.geogig.api.plumbing.DiffFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) DiffFeature(org.locationtech.geogig.api.plumbing.DiffFeature) NodeRef(org.locationtech.geogig.api.NodeRef) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 49 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class FeatureNodeRefFromRefspec method _call.

@Override
protected Optional<NodeRef> _call() {
    Optional<RevFeature> feature = getFeatureFromRefSpec();
    if (feature.isPresent()) {
        RevFeatureType featureType = getFeatureTypeFromRefSpec();
        RevFeature feat = feature.get();
        Envelope bounds = SpatialOps.boundsOf(feat);
        Node node = Node.create(NodeRef.nodeFromPath(ref), feat.getId(), featureType.getId(), TYPE.FEATURE, bounds);
        return Optional.of(new NodeRef(node, NodeRef.parentPath(ref), featureType.getId()));
    } else {
        return Optional.absent();
    /*
             * new NodeRef(Node.create("", ObjectId.NULL, ObjectId.NULL, TYPE.FEATURE), "",
             * ObjectId.NULL);
             */
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevFeature(org.locationtech.geogig.api.RevFeature) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 50 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class FeatureNodeRefFromRefspec method getFeatureTypeFromRefSpec.

private RevFeatureType getFeatureTypeFromRefSpec() {
    String featureTypeRef = NodeRef.parentPath(ref);
    String fullRef;
    if (featureTypeRef.contains(":")) {
        fullRef = featureTypeRef;
    } else {
        fullRef = "WORK_HEAD:" + featureTypeRef;
    }
    String treeRef = fullRef.split(":")[0];
    String path = fullRef.split(":")[1];
    ObjectId revTreeId = command(ResolveTreeish.class).setTreeish(treeRef).call().get();
    RevTree revTree = command(RevObjectParse.class).setObjectId(revTreeId).call(RevTree.class).get();
    Optional<NodeRef> nodeRef = command(FindTreeChild.class).setParent(revTree).setChildPath(path).setIndex(true).call();
    Preconditions.checkArgument(nodeRef.isPresent(), "Invalid reference: %s", ref);
    RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(nodeRef.get().getMetadataId()).call(RevFeatureType.class).get();
    return revFeatureType;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) ResolveTreeish(org.locationtech.geogig.api.plumbing.ResolveTreeish) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

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