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());
}
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);
}
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;
}
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);
*/
}
}
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;
}
Aggregations