use of org.locationtech.geogig.osm.internal.MappingRule.DefaultField in project GeoGig by boundlessgeo.
the class OSMUnmapOpTest method testMappingAndUnmappingOfNodesWithDefaultFieds.
@Test
public void testMappingAndUnmappingOfNodesWithDefaultFieds() throws Exception {
// Import
String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
// Map
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> mappings = Maps.newHashMap();
mappings.put("highway", Lists.newArrayList("bus_stop"));
fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
fields.put("name", new AttributeDefinition("name_alias", FieldType.STRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
ArrayList<DefaultField> defaultFields = Lists.newArrayList(DefaultField.tags, DefaultField.timestamp);
MappingRule mappingRule = new MappingRule("busstops", mappings, filterExclude, fields, defaultFields);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(revFeature.isPresent());
Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:busstops/507464799").call();
assertTrue(featureType.isPresent());
ImmutableList<Optional<Object>> values = revFeature.get().getValues();
assertEquals(5, values.size());
String wkt = "POINT (7.1959361 50.739397)";
assertEquals(wkt, values.get(4).get().toString());
assertEquals(507464799l, values.get(0).get());
// Modify a node
GeometryFactory gf = new GeometryFactory();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) featureType.get().type());
fb.set("geom", gf.createPoint(new Coordinate(0, 1)));
fb.set("name_alias", "newname");
fb.set("id", 507464799l);
fb.set("tags", "VRS:gemeinde:BONN|VRS:ortsteil:Hoholz|VRS:ref:68566|bus:yes|highway:bus_stop|name:Gielgen|public_transport:platform");
fb.set("timestamp", 1355097351000l);
SimpleFeature newFeature = fb.buildFeature("507464799");
geogig.getRepository().workingTree().insert("busstops", newFeature);
// check that it was correctly inserted in the working tree
Optional<RevFeature> mapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(mapped.isPresent());
values = mapped.get().getValues();
assertEquals("POINT (0 1)", values.get(4).get().toString());
assertEquals(507464799l, ((Long) values.get(0).get()).longValue());
assertEquals("newname", values.get(3).get().toString());
assertEquals("1355097351000", values.get(2).get().toString());
assertEquals("VRS:gemeinde:BONN|VRS:ortsteil:Hoholz|VRS:ref:68566|bus:yes|highway:bus_stop|name:Gielgen|public_transport:platform", values.get(1).get().toString());
// unmap
geogig.command(OSMUnmapOp.class).setPath("busstops").call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("node").featureCount();
assertEquals(1, unstaged);
// check that the unmapped node has the changes we introduced
Optional<RevFeature> unmapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/507464799").call(RevFeature.class);
assertTrue(unmapped.isPresent());
values = unmapped.get().getValues();
assertEquals("POINT (0 1)", values.get(6).get().toString());
assertEquals("bus:yes|public_transport:platform|highway:bus_stop|VRS:ortsteil:Hoholz|name:newname|VRS:ref:68566|VRS:gemeinde:BONN", values.get(3).get().toString());
// check that unchanged nodes keep their attributes
Optional<RevFeature> unchanged = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/1633594723").call(RevFeature.class);
values = unchanged.get().getValues();
assertEquals("14220478", values.get(4).get().toString());
assertEquals("1355097351000", values.get(2).get().toString());
assertEquals("2", values.get(1).get().toString());
}
use of org.locationtech.geogig.osm.internal.MappingRule.DefaultField 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.osm.internal.MappingRule.DefaultField in project GeoGig by boundlessgeo.
the class MappingTest method TestJsonSerialization.
@Test
public void TestJsonSerialization() {
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filters = Maps.newHashMap();
Map<String, List<String>> exclude = Maps.newHashMap();
List<DefaultField> defaultFields = Lists.newArrayList();
filters.put("highway", Lists.newArrayList("bus_stop"));
exclude.put("public_transport", Lists.newArrayList("platform"));
defaultFields.add(DefaultField.timestamp);
defaultFields.add(DefaultField.changeset);
fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
fields.put("name", new AttributeDefinition("name_alias", FieldType.STRING));
MappingRule mappingRule = new MappingRule("busstops", filters, exclude, fields, defaultFields);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
Gson gson = gsonBuilder.create();
String s = gson.toJson(mapping);
System.out.println(s);
Mapping unmarshalledMapping = gson.fromJson(s, Mapping.class);
assertEquals(mapping, unmarshalledMapping);
}
Aggregations