use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class OSMExport method getFeatures.
private Iterator<EntityContainer> getFeatures(String ref) {
Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(ref).call();
if (!id.isPresent()) {
return Iterators.emptyIterator();
}
LsTreeOp op = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
if (bbox != null) {
final Envelope env;
try {
env = new Envelope(Double.parseDouble(bbox.get(0)), Double.parseDouble(bbox.get(2)), Double.parseDouble(bbox.get(1)), Double.parseDouble(bbox.get(3)));
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Wrong bbox definition");
}
Predicate<Bounded> filter = new Predicate<Bounded>() {
@Override
public boolean apply(final Bounded bounded) {
boolean intersects = bounded.intersects(env);
return intersects;
}
};
op.setBoundsFilter(filter);
}
Iterator<NodeRef> iterator = op.call();
final EntityConverter converter = new EntityConverter();
Function<NodeRef, EntityContainer> function = new Function<NodeRef, EntityContainer>() {
@Override
@Nullable
public EntityContainer apply(@Nullable NodeRef ref) {
RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
SimpleFeatureType featureType;
if (ref.path().startsWith(OSMUtils.NODE_TYPE_NAME)) {
featureType = OSMUtils.nodeType();
} else {
featureType = OSMUtils.wayType();
}
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
SimpleFeature feature = featureBuilder.buildFeature(ref.name());
Entity entity = converter.toEntity(feature, null);
EntityContainer container;
if (entity instanceof Node) {
container = new NodeContainer((Node) entity);
} else {
container = new WayContainer((Way) entity);
}
return container;
}
};
return Iterators.transform(iterator, function);
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class ImportOpTest method testImportTable.
@Test
public void testImportTable() throws Exception {
ImportOp importOp = geogig.command(ImportOp.class);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setAll(false);
importOp.setTable("table1");
RevTree newWorkingTree = importOp.call();
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setParent(newWorkingTree).setChildPath("table1/feature1").setIndex(true).call();
assertTrue(ref.isPresent());
ref = geogig.command(FindTreeChild.class).setParent(newWorkingTree).setChildPath("table1/feature2").setIndex(true).call();
assertTrue(ref.isPresent());
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class ImportOpTest method testImportAll.
@Test
public void testImportAll() throws Exception {
ImportOp importOp = geogig.command(ImportOp.class);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setAll(true);
RevTree newWorkingTree = importOp.call();
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setParent(newWorkingTree).setChildPath("table1/feature1").setIndex(true).call();
assertTrue(ref.isPresent());
ref = geogig.command(FindTreeChild.class).setParent(newWorkingTree).setChildPath("table1/feature2").setIndex(true).call();
assertTrue(ref.isPresent());
ref = geogig.command(FindTreeChild.class).setParent(newWorkingTree).setChildPath("table2/feature3").setIndex(true).call();
assertTrue(ref.isPresent());
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class ImportOpTest method testAddUsingOriginalFeatureType.
@Test
public void testAddUsingOriginalFeatureType() throws Exception {
ImportOp importOp = geogig.command(ImportOp.class);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setTable("table1");
importOp.call();
importOp.setTable("table2");
importOp.setAdaptToDefaultFeatureType(false);
importOp.setDestinationPath("table1");
importOp.setOverwrite(false);
importOp.call();
Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
ArrayList<NodeRef> list = Lists.newArrayList(features);
assertEquals(3, list.size());
TreeSet<ObjectId> set = Sets.newTreeSet();
for (NodeRef node : list) {
set.add(node.getMetadataId());
}
assertEquals(2, set.size());
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class ImportOpTest method testImportAllWithDifferentFeatureTypesAndDestPathAndAdd.
@Test
public void testImportAllWithDifferentFeatureTypesAndDestPathAndAdd() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(CRS.decode("EPSG:4326"));
builder.add("geom", Point.class);
builder.add("label", String.class);
builder.setName("dest");
SimpleFeatureType type = builder.buildFeatureType();
GeometryFactory gf = new GeometryFactory();
SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(0, 0)), "feature0" }, "feature");
geogig.getRepository().workingTree().insert("dest", feature);
ImportOp importOp = geogig.command(ImportOp.class);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setAll(true);
importOp.setOverwrite(false);
importOp.setDestinationPath("dest");
importOp.setAdaptToDefaultFeatureType(false);
importOp.call();
Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
ArrayList<NodeRef> list = Lists.newArrayList(features);
assertEquals(5, list.size());
TreeSet<ObjectId> set = Sets.newTreeSet();
ArrayList<RevFeatureType> ftlist = new ArrayList<RevFeatureType>();
for (NodeRef node : list) {
Optional<RevFeatureType> ft = geogig.command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class);
assertTrue(ft.isPresent());
ftlist.add(ft.get());
set.add(node.getMetadataId());
}
assertEquals(4, set.size());
}
Aggregations