Search in sources :

Example 36 with WorkingTree

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ResolveOSMMappingLogFolder(org.locationtech.geogig.osm.internal.log.ResolveOSMMappingLogFolder) Optional(com.google.common.base.Optional) WorkingTree(org.locationtech.geogig.repository.WorkingTree) RevFeature(org.locationtech.geogig.api.RevFeature) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 37 with WorkingTree

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) WorkingTree(org.locationtech.geogig.repository.WorkingTree) RevFeature(org.locationtech.geogig.api.RevFeature) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultField(org.locationtech.geogig.osm.internal.MappingRule.DefaultField) File(java.io.File) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 38 with WorkingTree

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 39 with WorkingTree

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 40 with WorkingTree

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;
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) Repository(org.locationtech.geogig.repository.Repository) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Feature(org.opengis.feature.Feature) GeoGIG(org.locationtech.geogig.api.GeoGIG) Name(org.opengis.feature.type.Name)

Aggregations

WorkingTree (org.locationtech.geogig.repository.WorkingTree)54 Test (org.junit.Test)32 AddOp (org.locationtech.geogig.api.porcelain.AddOp)25 List (java.util.List)18 ImmutableList (com.google.common.collect.ImmutableList)17 File (java.io.File)17 ArrayList (java.util.ArrayList)16 RevFeature (org.locationtech.geogig.api.RevFeature)15 Optional (com.google.common.base.Optional)12 SimpleFeature (org.opengis.feature.simple.SimpleFeature)12 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)11 NodeRef (org.locationtech.geogig.api.NodeRef)10 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)9 Name (org.opengis.feature.type.Name)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)7 Node (org.locationtech.geogig.api.Node)7 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5