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;
}
Aggregations