Search in sources :

Example 6 with Mapping

use of org.locationtech.geogig.osm.internal.Mapping in project GeoGig by boundlessgeo.

the class OSMExportShp method runInternal.

/**
     * Executes the export command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    Preconditions.checkNotNull(mappingFile != null, "A data mapping file must be specified");
    if (args == null || args.isEmpty() || args.size() != 1) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    String shapefile = args.get(0);
    final File file = new File(shapefile);
    final Mapping mapping = Mapping.fromFile(mappingFile);
    List<MappingRule> rules = mapping.getRules();
    checkParameter(!rules.isEmpty(), "No rules are defined in the specified mapping");
    for (MappingRule rule : rules) {
        File targetFile = file;
        if (rules.size() > 1) {
            String name = getNameWithoutExtension(file.getName()) + "_" + rule.getName() + ".shp";
            targetFile = new File(file.getParentFile(), name);
        }
        exportRule(rule, cli, targetFile);
    }
}
Also used : Mapping(org.locationtech.geogig.osm.internal.Mapping) File(java.io.File) MappingRule(org.locationtech.geogig.osm.internal.MappingRule) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 7 with Mapping

use of org.locationtech.geogig.osm.internal.Mapping in project GeoGig by boundlessgeo.

the class OSMMap method runInternal.

/**
     * Executes the map command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args == null || args.isEmpty() || args.size() != 1) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    checkState(cli.getGeogig().getRepository().index().isClean() && cli.getGeogig().getRepository().workingTree().isClean(), "Working tree and index are not clean");
    String mappingFilepath = args.get(0);
    Mapping mapping = Mapping.fromFile(mappingFilepath);
    geogig = cli.getGeogig();
    ObjectId oldTreeId = geogig.getRepository().workingTree().getTree().getId();
    message = message == null ? "Applied mapping " + new File(mappingFilepath).getName() : message;
    ObjectId newTreeId = geogig.command(OSMMapOp.class).setMapping(mapping).setMessage(message).call().getId();
    ConsoleReader console = cli.getConsole();
    if (newTreeId.equals(oldTreeId)) {
        console.println("No features matched the specified filter, or they provided no updated data.\n" + "No changes have been made to the working tree");
    } else {
    // print something?
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId) Mapping(org.locationtech.geogig.osm.internal.Mapping) File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Aggregations

Mapping (org.locationtech.geogig.osm.internal.Mapping)7 File (java.io.File)4 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)4 MappingRule (org.locationtech.geogig.osm.internal.MappingRule)3 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)2 Function (com.google.common.base.Function)1 URL (java.net.URL)1 Nullable (javax.annotation.Nullable)1 ConsoleReader (jline.console.ConsoleReader)1 DataStore (org.geotools.data.DataStore)1 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)1 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)1 Context (org.locationtech.geogig.api.Context)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)1 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)1 EmptyOSMDownloadException (org.locationtech.geogig.osm.internal.EmptyOSMDownloadException)1 OSMReport (org.locationtech.geogig.osm.internal.OSMReport)1