Search in sources :

Example 1 with FindTreeChild

use of org.locationtech.geogig.api.plumbing.FindTreeChild in project GeoGig by boundlessgeo.

the class RevTreeBuilderTest method testPutRandomGet.

@Test
public void testPutRandomGet() throws Exception {
    final int numEntries = 2 * RevTree.NORMALIZED_SIZE_LIMIT + 1500;
    final ObjectId treeId;
    Stopwatch sw;
    sw = Stopwatch.createStarted();
    treeId = createAndSaveTree(numEntries, true);
    sw.stop();
    System.err.println("Stored " + numEntries + " tree entries in " + sw + " (" + Math.round(numEntries / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)");
    sw.reset().start();
    final RevTree tree = odb.getTree(treeId);
    sw.stop();
    System.err.println("Retrieved tree in " + sw);
    {
        Map<Integer, Node> randomEdits = Maps.newHashMap();
        Random randGen = new Random();
        for (int i = 0; i < tree.size() / 2; i++) {
            int random;
            while (randomEdits.containsKey(random = randGen.nextInt(numEntries))) {
                // $codepro.audit.disable extraSemicolon
                ;
            }
            String name = "Feature." + random;
            ObjectId newid = ObjectId.forString(name + "changed");
            Node ref = Node.create(name, newid, ObjectId.NULL, TYPE.FEATURE, null);
            randomEdits.put(random, ref);
        }
        RevTreeBuilder mutable = tree.builder(odb);
        sw.reset().start();
        for (Node ref : randomEdits.values()) {
            mutable.put(ref);
        }
        mutable.build();
        sw.stop();
        System.err.println(randomEdits.size() + " random modifications in " + sw);
    }
    // CharSequence treeStr =
    // repo.command(CatObject.class).setObject(Suppliers.ofInstance(tree))
    // .call();
    // System.out.println(treeStr);
    final FindTreeChild childFinder = repo.command(FindTreeChild.class).setParent(tree);
    sw.reset().start();
    System.err.println("Reading " + numEntries + " entries....");
    for (int i = 0; i < numEntries; i++) {
        if ((i + 1) % (numEntries / 10) == 0) {
            System.err.print("#" + (i + 1));
        } else if ((i + 1) % (numEntries / 100) == 0) {
            System.err.print('.');
        }
        String key = "Feature." + i;
        // ObjectId oid = ObjectId.forString(key);
        Optional<NodeRef> ref = childFinder.setChildPath(key).call();
        assertTrue(key, ref.isPresent());
    // assertEquals(key, ref.get().getPath());
    // assertEquals(key, oid, ref.get().getObjectId());
    }
    sw.stop();
    System.err.println("\nGot " + numEntries + " in " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms (" + Math.round(numEntries / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)\n");
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Random(java.util.Random) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Stopwatch(com.google.common.base.Stopwatch) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Map(java.util.Map) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 2 with FindTreeChild

use of org.locationtech.geogig.api.plumbing.FindTreeChild in project GeoGig by boundlessgeo.

the class OSMHistoryImport method parseGeometry.

/**
     * @param primitive
     * @param thisChangePointCache
     * @return
     */
private Geometry parseGeometry(GeoGIG geogig, Primitive primitive, Map<Long, Coordinate> thisChangePointCache) {
    if (primitive instanceof Relation) {
        return null;
    }
    if (primitive instanceof Node) {
        Optional<Point> location = ((Node) primitive).getLocation();
        return location.orNull();
    }
    final Way way = (Way) primitive;
    final ImmutableList<Long> nodes = way.getNodes();
    StagingArea index = geogig.getRepository().index();
    FeatureBuilder featureBuilder = new FeatureBuilder(NODE_REV_TYPE);
    List<Coordinate> coordinates = Lists.newArrayList(nodes.size());
    FindTreeChild findTreeChild = geogig.command(FindTreeChild.class);
    findTreeChild.setIndex(true);
    ObjectId rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(Ref.HEAD).call().get();
    if (!rootTreeId.isNull()) {
        RevTree headTree = geogig.command(RevObjectParse.class).setObjectId(rootTreeId).call(RevTree.class).get();
        findTreeChild.setParent(headTree);
    }
    for (Long nodeId : nodes) {
        Coordinate coord = thisChangePointCache.get(nodeId);
        if (coord == null) {
            String fid = String.valueOf(nodeId);
            String path = NodeRef.appendChild(NODE_TYPE_NAME, fid);
            Optional<org.locationtech.geogig.api.Node> ref = index.findStaged(path);
            if (!ref.isPresent()) {
                Optional<NodeRef> nodeRef = findTreeChild.setChildPath(path).call();
                if (nodeRef.isPresent()) {
                    ref = Optional.of(nodeRef.get().getNode());
                } else {
                    ref = Optional.absent();
                }
            }
            if (ref.isPresent()) {
                org.locationtech.geogig.api.Node nodeRef = ref.get();
                RevFeature revFeature = index.getDatabase().getFeature(nodeRef.getObjectId());
                String id = NodeRef.nodeFromPath(nodeRef.getName());
                Feature feature = featureBuilder.build(id, revFeature);
                Point p = (Point) ((SimpleFeature) feature).getAttribute("location");
                if (p != null) {
                    coord = p.getCoordinate();
                    thisChangePointCache.put(Long.valueOf(nodeId), coord);
                }
            }
        }
        if (coord != null) {
            coordinates.add(coord);
        }
    }
    if (coordinates.size() < 2) {
        return null;
    }
    return GEOMF.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
Also used : SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) Node(org.locationtech.geogig.osm.internal.history.Node) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) Way(org.locationtech.geogig.osm.internal.history.Way) NodeRef(org.locationtech.geogig.api.NodeRef) Relation(javax.management.relation.Relation) ResolveTreeish(org.locationtech.geogig.api.plumbing.ResolveTreeish) RevFeature(org.locationtech.geogig.api.RevFeature) ObjectId(org.locationtech.geogig.api.ObjectId) StagingArea(org.locationtech.geogig.repository.StagingArea) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Point(com.vividsolutions.jts.geom.Point) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)2 ObjectId (org.locationtech.geogig.api.ObjectId)2 RevTree (org.locationtech.geogig.api.RevTree)2 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)2 Stopwatch (com.google.common.base.Stopwatch)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Point (com.vividsolutions.jts.geom.Point)1 Map (java.util.Map)1 Random (java.util.Random)1 Relation (javax.management.relation.Relation)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 Test (org.junit.Test)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 Node (org.locationtech.geogig.api.Node)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)1 ResolveTreeish (org.locationtech.geogig.api.plumbing.ResolveTreeish)1 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)1 Node (org.locationtech.geogig.osm.internal.history.Node)1 Way (org.locationtech.geogig.osm.internal.history.Way)1