Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.GeoGIG


        return newGeoGIG(Hints.readWrite());
    }

    public GeoGIG newGeoGIG(Hints hints) {
        Context inj = newGeogigInjector(hints);
        GeoGIG geogig = new GeoGIG(inj, platform.pwd());
        try {
            geogig.getRepository();
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
        return geogig;
    }
View Full Code Here


     */
    private String[] unalias(String[] args) {
        final String aliasedCommand = args[0];
        String configParam = "alias." + aliasedCommand;
        boolean closeGeogig = false;
        GeoGIG geogig = this.providedGeogig == null ? this.geogig : this.providedGeogig;
        if (geogig == null) { // in case the repo is not initialized yet
            closeGeogig = true;
            geogig = newGeoGIG(Hints.readOnly());
        }
        try {
            Optional<String> unaliased = Optional.absent();
            if (geogig.command(ResolveGeogigDir.class).call().isPresent()) {
                unaliased = geogig.command(ConfigGet.class).setName(configParam).call();
            }
            if (!unaliased.isPresent()) {
                unaliased = geogig.command(ConfigGet.class).setGlobal(true).setName(configParam)
                        .call();
            }
            if (!unaliased.isPresent()) {
                return args;
            }
            Iterable<String> tokens = Splitter.on(" ").split(unaliased.get());
            List<String> allArgs = Lists.newArrayList(tokens);
            allArgs.addAll(Lists.newArrayList(Arrays.copyOfRange(args, 1, args.length)));
            return allArgs.toArray(new String[0]);
        } catch (ConfigException e) {
            return args;
        } finally {
            if (closeGeogig) {
                geogig.close();
            }
        }
    }
View Full Code Here

        File workingDirectory = tmp.newFolder("repo");
        File userHomeDirectory = tmp.newFolder("home");
        TestPlatform platform = new TestPlatform(workingDirectory);
        platform.setUserHome(userHomeDirectory);
        Context injector = new CLITestContextBuilder(platform).build();
        GeoGIG geogig = new GeoGIG(injector);
        geogig.command(InitOp.class).call();
        geogig.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.name")
                .setValue("gabriel").call();
        geogig.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.email")
                .setValue("gabriel@roldan.example.com").call();

        store = new GeoGigDataStore(geogig);

        store.createSchema(pointType);
View Full Code Here

            refspec = "WORK_HEAD:" + path;
        }

        checkParameter(!refspec.endsWith(":"), "No path specified.");

        final GeoGIG geogig = cli.getGeogig();

        Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class)
                .setTreeish(refspec.split(":")[0]).call();

        checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec
                + "' to a treeish object");

        RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
        Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class)
                .setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();

        checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1]
                + "' did not match any valid path");
View Full Code Here

        if (!interactive) {
            return;
        }
        String currentDir = new File(".").getCanonicalPath();
        String currentHead = "";
        GeoGIG geogig;
        try {
            geogig = cli.newGeoGIG(Hints.readOnly());
        } catch (Exception e) {
            geogig = null;
        }
        if (geogig != null) {
            Optional<URL> dir = geogig.command(ResolveGeogigDir.class).call();
            if (dir.isPresent()) {
                try {
                    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.HEAD).call();
                    if (ref.isPresent()) {
                        if (ref.get() instanceof SymRef) {
                            currentHead = ((SymRef) ref.get()).getTarget();
                            int idx = currentHead.lastIndexOf("/");
                            if (idx != -1) {
                                currentHead = currentHead.substring(idx + 1);
                            }
                        } else {
                            currentHead = ref.get().getObjectId().toString().substring(0, 7);
                        }
                        currentHead = " (" + currentHead + ")";
                    }
                } finally {
                    geogig.close();
                }
            }
        }
        String prompt = "(geogig):" + currentDir + currentHead + " $ ";
        cli.getConsole().setPrompt(prompt);
View Full Code Here

        final String osmAPIUrl = resolveAPIURL();

        final long startIndex;
        final long endIndex = args.endIndex;
        if (args.resume) {
            GeoGIG geogig = cli.getGeogig();
            long lastChangeset = getCurrentBranchChangeset(geogig);
            startIndex = 1 + lastChangeset;
        } else {
            startIndex = args.startIndex;
        }
View Full Code Here

    private void importOsmHistory(GeogigCLI cli, ConsoleReader console,
            HistoryDownloader downloader, @Nullable Envelope featureFilter) throws IOException {

        Iterator<Changeset> changesets = downloader.fetchChangesets();

        GeoGIG geogig = cli.getGeogig();
        WorkingTree workingTree = geogig.getContext().workingTree();

        while (changesets.hasNext()) {
            Changeset changeset = changesets.next();
            if (changeset.isOpen()) {
                throw new CommandFailedException("Can't import past changeset " + changeset.getId()
                        + " as it is still open.");
            }
            String desc = String.format("obtaining osm changeset %,d...", changeset.getId());
            console.print(desc);
            console.flush();

            Optional<Iterator<Change>> opchanges = changeset.getChanges().get();
            if (!opchanges.isPresent()) {
                updateBranchChangeset(geogig, changeset.getId());
                console.println(" does not apply.");
                console.flush();
                continue;
            }
            Iterator<Change> changes = opchanges.get();
            console.print("applying...");
            console.flush();

            ObjectId workTreeId = workingTree.getTree().getId();
            long changeCount = insertChanges(cli, changes, featureFilter);
            console.print(String.format("Applied %,d changes, staging...", changeCount));
            console.flush();
            ObjectId afterTreeId = workingTree.getTree().getId();

            DiffObjectCount diffCount = geogig.command(DiffCount.class)
                    .setOldVersion(workTreeId.toString()).setNewVersion(afterTreeId.toString())
                    .call();

            geogig.command(AddOp.class).call();
            console.println(String.format("done. %,d changes actually applied.",
                    diffCount.featureCount()));
            console.flush();

            commit(cli, changeset);
View Full Code Here

        Preconditions.checkArgument(!changeset.isOpen());
        ConsoleReader console = cli.getConsole();
        console.print("Committing changeset " + changeset.getId() + "...");
        console.flush();

        GeoGIG geogig = cli.getGeogig();
        CommitOp command = geogig.command(CommitOp.class);
        command.setAllowEmpty(true);
        String message = "";
        if (changeset.getComment().isPresent()) {
            message = changeset.getComment().get() + "\nchangeset " + changeset.getId();
        } else {
            message = "changeset " + changeset.getId();
        }
        command.setMessage(message);
        final String userName = changeset.getUserName();
        command.setAuthor(userName, null);
        command.setAuthorTimestamp(changeset.getCreated());
        command.setAuthorTimeZoneOffset(0);// osm timestamps are in GMT

        if (userName != null) {
            command.setCommitter(userName, null);
        }
        command.setCommitterTimestamp(changeset.getClosed().get());
        command.setCommitterTimeZoneOffset(0);// osm timestamps are in GMT

        ProgressListener listener = cli.getProgressListener();
        listener.setProgress(0f);
        listener.started();
        command.setProgressListener(listener);
        try {
            RevCommit commit = command.call();
            Ref head = geogig.command(RefParse.class).setName(Ref.HEAD).call().get();
            Preconditions.checkState(commit.getId().equals(head.getObjectId()));
            updateBranchChangeset(geogig, changeset.getId());
            listener.complete();
            console.println("Commit " + commit.getId().toString());
            console.flush();
View Full Code Here

     * @throws IOException
     */
    private long insertChanges(GeogigCLI cli, final Iterator<Change> changes,
            @Nullable Envelope featureFilter) throws IOException {

        final GeoGIG geogig = cli.getGeogig();
        final Repository repository = geogig.getRepository();
        final WorkingTree workTree = repository.workingTree();

        Map<Long, Coordinate> thisChangePointCache = new LinkedHashMap<Long, Coordinate>() {
            /** serialVersionUID */
            private static final long serialVersionUID = 1277795218777240552L;
View Full Code Here

    }

    private void printRaw(GeogigCLI cli) throws IOException {
        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();
        for (String ref : refs) {
            Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
            if (!obj.isPresent()) {
                ref = getFullRef(ref);
                obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
            }
            checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
            RevObject revObject = obj.get();
            if (revObject instanceof RevFeature) {
                Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class)
                        .setRefSpec(ref).call();
                if (opt.isPresent()) {
                    RevFeatureType ft = opt.get();
                    ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                    RevFeature feature = (RevFeature) revObject;
                    Ansi ansi = super.newAnsi(console.getTerminal());
                    ansi.a(ref).newline();
                    ansi.a(feature.getId().toString()).newline();
                    ImmutableList<Optional<Object>> values = feature.getValues();
                    int i = 0;
                    for (Optional<Object> value : values) {
                        PropertyDescriptor attrib = attribs.get(i);
                        ansi.a(attrib.getName()).newline();
                        PropertyType attrType = attrib.getType();
                        String typeName = FieldType.forBinding(attrType.getBinding()).name();
                        if (attrType instanceof GeometryType) {
                            GeometryType gt = (GeometryType) attrType;
                            CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                            String crsText = CrsTextSerializer.serialize(crs);
                            ansi.a(typeName).a(" ").a(crsText).newline();
                        } else {
                            ansi.a(typeName).newline();
                        }
                        ansi.a(value.or("[NULL]").toString()).newline();
                        i++;
                    }
                    console.println(ansi.toString());
                } else {
                    CharSequence s = geogig.command(CatObject.class)
                            .setObject(Suppliers.ofInstance(revObject)).call();
                    console.println(s);
                }
            } else {
                CharSequence s = geogig.command(CatObject.class)
                        .setObject(Suppliers.ofInstance(revObject)).call();
                console.println(s);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.GeoGIG

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.