All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.graphhopper.matching.cli.GetBoundsCommand Maven / Gradle / Ivy

There is a newer version: 2.0-pre3
Show newest version
package com.graphhopper.matching.cli;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.graphhopper.matching.Observation;
import com.graphhopper.matching.gpx.Gpx;
import com.graphhopper.matching.gpx.Trk;
import com.graphhopper.util.shapes.BBox;
import io.dropwizard.cli.Command;
import io.dropwizard.setup.Bootstrap;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class GetBoundsCommand extends Command {

    public GetBoundsCommand() {
        super("getbounds", "");
    }

    @Override
    public void configure(Subparser subparser) {
        subparser.addArgument("gpx")
            .type(File.class)
            .required(true)
            .nargs("+")
            .help("GPX file");
    }

    @Override
    public void run(Bootstrap bootstrap, Namespace args) {
        XmlMapper xmlMapper = new XmlMapper();
        BBox bbox = BBox.createInverse(false);
        for (File gpxFile : args.getList("gpx")) {
            try {
                Gpx gpx = xmlMapper.readValue(gpxFile, Gpx.class);
                for (Trk trk : gpx.trk) {
                    List inputGPXEntries = trk.getEntries();
                    for (Observation entry : inputGPXEntries) {
                        bbox.update(entry.getPoint().getLat(), entry.getPoint().getLon());
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        System.out.println("bounds: " + bbox);

        // show download only for small areas
        if (bbox.maxLat - bbox.minLat < 0.1 && bbox.maxLon - bbox.minLon < 0.1) {
            double delta = 0.01;
            System.out.println("Get small areas via\n"
                    + "wget -O extract.osm 'http://overpass-api.de/api/map?bbox="
                    + (bbox.minLon - delta) + "," + (bbox.minLat - delta) + ","
                    + (bbox.maxLon + delta) + "," + (bbox.maxLat + delta) + "'");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy