Search in sources :

Example 1 with CountryListTwoWayStringConverter

use of org.openstreetmap.atlas.geography.boundary.converters.CountryListTwoWayStringConverter in project atlas by osmlab.

the class AtlasDebugTool method onRun.

@Override
protected int onRun(final CommandMap command) {
    final File pbf = (File) command.get(PBF);
    final File atlasFile = (File) command.get(ATLAS);
    final File geojson = (File) command.get(GEOJSON);
    final File text = (File) command.get(TEXT);
    final java.io.File boundaryFile = (java.io.File) command.get(BOUNDARY);
    final String country = (String) command.get(COUNTRY);
    final Rectangle bound = (Rectangle) command.get(BOUND);
    final MultiPolygon inputMultipolygon = (MultiPolygon) command.get(MULTIPOLYGON);
    @SuppressWarnings("unchecked") final List<Location> startEndRoute = (List<Location>) command.get(ROUTE);
    Atlas atlas;
    if (pbf != null && pbf.exists()) {
        final AtlasLoadingOption option;
        MultiPolygon multiPolygon = MultiPolygon.forPolygon(Rectangle.MAXIMUM);
        if (boundaryFile != null) {
            final CountryBoundaryMap boundaryMap = CountryBoundaryMap.fromShapeFile(boundaryFile);
            option = AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap);
            if (country != null) {
                if (new CountryListTwoWayStringConverter().convert(country).size() == 1) {
                    multiPolygon = boundaryMap.countryBoundary(country).get(0).getBoundary();
                }
                option.setCountryCode(country);
            }
        } else {
            option = AtlasLoadingOption.createOptionWithNoSlicing();
        }
        if (bound != null) {
            multiPolygon = MultiPolygon.forPolygon(bound);
        }
        if (inputMultipolygon != null) {
            multiPolygon = inputMultipolygon;
        }
        atlas = new RawAtlasGenerator(pbf, option, multiPolygon).build();
        if (option.isCountrySlicing()) {
            atlas = new RawAtlasSlicer(option, atlas).slice();
        }
        atlas = new WaySectionProcessor(atlas, option).run();
        atlas.save(atlasFile);
    } else if (atlasFile != null && atlasFile.exists()) {
        atlas = new AtlasResourceLoader().load(atlasFile);
    } else {
        logger.error("Must have at least one source, -pbf or -atlas");
        atlas = null;
        System.exit(1);
    }
    logger.info("Loaded {}", atlas.summary());
    if (geojson != null) {
        atlas.saveAsGeoJson(geojson);
    }
    if (text != null) {
        atlas.saveAsText(text);
    }
    if (startEndRoute != null) {
        logger.info("Route between {} and {} = {}", startEndRoute.get(0), startEndRoute.get(1), AStarRouter.dijkstra(atlas, Distance.TEN_MILES).route(startEndRoute.get(0), startEndRoute.get(1)));
    }
    return 0;
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) Rectangle(org.openstreetmap.atlas.geography.Rectangle) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator) AtlasResourceLoader(org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) ArrayList(java.util.ArrayList) List(java.util.List) StringList(org.openstreetmap.atlas.utilities.collections.StringList) AtlasLoadingOption(org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) CountryListTwoWayStringConverter(org.openstreetmap.atlas.geography.boundary.converters.CountryListTwoWayStringConverter) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) File(org.openstreetmap.atlas.streaming.resource.File) Location(org.openstreetmap.atlas.geography.Location)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Location (org.openstreetmap.atlas.geography.Location)1 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)1 Rectangle (org.openstreetmap.atlas.geography.Rectangle)1 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)1 AtlasResourceLoader (org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader)1 AtlasLoadingOption (org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption)1 RawAtlasGenerator (org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator)1 WaySectionProcessor (org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor)1 RawAtlasSlicer (org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer)1 CountryBoundaryMap (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)1 CountryListTwoWayStringConverter (org.openstreetmap.atlas.geography.boundary.converters.CountryListTwoWayStringConverter)1 File (org.openstreetmap.atlas.streaming.resource.File)1 StringList (org.openstreetmap.atlas.utilities.collections.StringList)1