use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingWays.
@Test
public void testMappingWays() throws Exception {
// import and check that we have both ways and nodes
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertTrue(unstaged > 0);
unstaged = workTree.countUnstaged("node").count();
assertTrue(unstaged > 0);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
// Define mapping
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filter = Maps.newHashMap();
filter.put("oneway", Lists.newArrayList("yes"));
fields.put("geom", new AttributeDefinition("geom", FieldType.LINESTRING));
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("onewaystreets", filter, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
// Check that mapping was correctly performed
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:onewaystreets/31045880").call(RevFeature.class);
assertTrue(revFeature.isPresent());
ImmutableList<Optional<Object>> values = revFeature.get().getValues();
assertEquals(4, values.size());
String wkt = "LINESTRING (7.1923367 50.7395887, 7.1923127 50.7396946, 7.1923444 50.7397419, 7.1924199 50.7397781)";
assertEquals(wkt, values.get(2).get().toString());
assertEquals("yes", values.get(1).get());
// Check that the corresponding log files have been added
File osmMapFolder = geogig.command(ResolveOSMMappingLogFolder.class).call();
file = new File(osmMapFolder, "onewaystreets");
assertTrue(file.exists());
file = new File(osmMapFolder, geogig.getRepository().workingTree().getTree().getId().toString());
assertTrue(file.exists());
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingDefaultFields.
@Test
public void testMappingDefaultFields() throws Exception {
// import and check that we have both ways and nodes
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertTrue(unstaged > 0);
unstaged = workTree.countUnstaged("node").count();
assertTrue(unstaged > 0);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
// Define mapping
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filter = Maps.newHashMap();
filter.put("oneway", Lists.newArrayList("yes"));
fields.put("geom", new AttributeDefinition("geom", FieldType.LINESTRING));
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
ArrayList<DefaultField> defaultFields = Lists.newArrayList();
defaultFields.add(DefaultField.timestamp);
defaultFields.add(DefaultField.visible);
MappingRule mappingRule = new MappingRule("onewaystreets", filter, null, fields, defaultFields);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
// Check that mapping was correctly performed
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:onewaystreets/31045880").call(RevFeature.class);
assertTrue(revFeature.isPresent());
ImmutableList<Optional<Object>> values = revFeature.get().getValues();
assertEquals(6, values.size());
String wkt = "LINESTRING (7.1923367 50.7395887, 7.1923127 50.7396946, 7.1923444 50.7397419, 7.1924199 50.7397781)";
assertEquals(wkt, values.get(4).get().toString());
assertEquals("yes", values.get(3).get());
assertEquals(true, values.get(2).get());
assertEquals(1318750940000L, values.get(1).get());
Optional<RevFeatureType> revFeatureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:onewaystreets/31045880").call();
assertTrue(revFeatureType.isPresent());
ImmutableList<PropertyDescriptor> descriptors = revFeatureType.get().sortedDescriptors();
assertEquals("timestamp", descriptors.get(1).getName().toString());
assertEquals("visible", descriptors.get(2).getName().toString());
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingWithNoFilter.
@Test
public void testMappingWithNoFilter() throws Exception {
// Test that if no filter is specified in a mapping rule, all entities pass the filter
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertTrue(unstaged > 0);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filters = Maps.newHashMap();
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
fields.put("geom", new AttributeDefinition("geom", FieldType.LINESTRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("allways", filters, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Iterator<NodeRef> allways = geogig.command(LsTreeOp.class).setReference("HEAD:allways").call();
assertTrue(allways.hasNext());
Iterator<NodeRef> ways = geogig.command(LsTreeOp.class).setReference("HEAD:allways").call();
ArrayList<NodeRef> listWays = Lists.newArrayList(ways);
ArrayList<NodeRef> listAllways = Lists.newArrayList(allways);
assertEquals(listWays.size(), listAllways.size());
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingWithEmptyTagValueList.
@Test
public void testMappingWithEmptyTagValueList() throws Exception {
// Test that when no tags are specified, all entities pass the filter
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertTrue(unstaged > 0);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filters = Maps.newHashMap();
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
filters.put("highway", new ArrayList<String>());
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("mapped", filters, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference("HEAD:mapped").call();
ArrayList<NodeRef> list = Lists.newArrayList(iter);
assertEquals(4, list.size());
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class GlobalState method insert.
public static List<ObjectId> insert(Feature... features) throws Exception {
geogigCLI.close();
GeoGIG geogig = geogigCLI.newGeoGIG(Hints.readWrite());
Preconditions.checkNotNull(geogig);
List<ObjectId> ids = Lists.newArrayListWithCapacity(features.length);
try {
Repository repository = geogig.getRepository();
final WorkingTree workTree = repository.workingTree();
for (Feature f : features) {
Name name = f.getType().getName();
String parentPath = name.getLocalPart();
Node ref = workTree.insert(parentPath, f);
ObjectId objectId = ref.getObjectId();
ids.add(objectId);
}
} finally {
geogig.close();
}
return ids;
}
Aggregations