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;
}
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();
}
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;
}
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;
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class RevFeatureTypeSerializationTest method testSerializationWGS84.
@Test
public void testSerializationWGS84() throws Exception {
SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
ftb.add("geom", Polygon.class, DefaultGeographicCRS.WGS84);
ftb.setName("type");
SimpleFeatureType ftype = ftb.buildFeatureType();
RevFeatureType revFeatureType = RevFeatureTypeImpl.build(ftype);
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);
FeatureType serializedFeatureType = rft.type();
assertEquals("EPSG:4326", CRS.toSRS(serializedFeatureType.getCoordinateReferenceSystem()));
}
Aggregations