use of org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption in project atlas by osmlab.
the class AbstractAtlas method createAndSaveOsmPbfWithSlicing.
/**
* Create an {@link Atlas} from an OSM protobuf that has already been sliced and save it to a
* resource
*
* @param osmPbf
* The OSM protobuf
* @param atlasResource
* The {@link WritableResource} to save the {@link Atlas} to
* @param boundaryMap
* The {@link CountryBoundaryMap} to use for country-slicing
* @return The created {@link Atlas}
*/
public static Atlas createAndSaveOsmPbfWithSlicing(final Resource osmPbf, final WritableResource atlasResource, final CountryBoundaryMap boundaryMap) {
Atlas atlas = new RawAtlasGenerator(osmPbf).build();
final AtlasLoadingOption loadingOption = AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap);
atlas = new RawAtlasSlicer(loadingOption, atlas).slice();
atlas = new WaySectionProcessor(atlas, AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();
atlas.save(atlasResource);
return atlas;
}
use of org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption in project atlas by osmlab.
the class AtlasIntegrationTest method loadBahamas.
protected Atlas loadBahamas(final Polygon polygon) {
final String path = OsmPbfIngestIntegrationTest.class.getResource("BHS-6-18-27.pbf").getPath();
final AtlasLoadingOption loadingOption = AtlasLoadingOption.createOptionWithOnlySectioning().setLoadWaysSpanningCountryBoundaries(false);
final Atlas atlas = new RawAtlasGenerator(new File(path), loadingOption, MultiPolygon.forPolygon(polygon)).build();
return new WaySectionProcessor(atlas, loadingOption).run();
}
use of org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption 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;
}
use of org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption in project atlas by osmlab.
the class OsmPbfToAtlasSubCommand method execute.
@Override
public int execute(final CommandMap map) {
final AtlasLoadingOption options = this.getAtlasLoadingOption(map);
Atlas atlas = new RawAtlasGenerator((File) map.get(INPUT_PARAMETER), options, MultiPolygon.MAXIMUM).build();
if (options.isCountrySlicing()) {
atlas = new RawAtlasSlicer(options, atlas).slice();
}
atlas = new WaySectionProcessor(atlas, options).run();
atlas.save((File) map.get(OUTPUT_PARAMETER));
return 0;
}
use of org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption in project atlas by osmlab.
the class TestAtlasHandler method buildAtlasFromPbf.
/**
* Builds an {@link Atlas} from the given pbf resource, using the raw atlas flow. This does NOT
* country-slice the pbf resource since no corresponding boundary file is supplied and the flow
* is not meant to test slicing logic.
*
* @param pbfResource
* The pbf input resource to use
* @param iso
* ISO code to be applied to all features
* @return the resulting Atlas
*/
private static Atlas buildAtlasFromPbf(final Resource pbfResource, final Optional<String> iso) {
// Create raw Atlas
final AtlasLoadingOption loadingOption = AtlasLoadingOption.withNoFilter();
if (iso.isPresent()) {
loadingOption.setCountrySlicing(true);
loadingOption.setCountryBoundaryMap(CountryBoundaryMap.fromBoundaryMap(Collections.singletonMap(iso.get(), MultiPolygon.MAXIMUM)));
}
final Atlas rawAtlas = new RawAtlasGenerator(pbfResource, loadingOption, MultiPolygon.MAXIMUM).build();
// Country Slice and Way-Section
return new WaySectionProcessor(iso.isPresent() ? new RawAtlasSlicer(loadingOption, rawAtlas).slice() : rawAtlas, loadingOption).run();
}
Aggregations