use of org.openstreetmap.atlas.geography.boundary.converters.CountryBoundaryMapGeoJsonConverter in project atlas by osmlab.
the class AnyToGeoJsonCommand method executeBoundaryContext.
private int executeBoundaryContext() {
Set<String> countries = new HashSet<>();
if (this.optionAndArgumentDelegate.hasOption(COUNTRIES_OPTION_LONG)) {
countries = this.optionAndArgumentDelegate.getOptionArgument(COUNTRIES_OPTION_LONG, this::parseCommaSeparatedCountries).orElse(new HashSet<>());
}
final boolean usePolygons = this.optionAndArgumentDelegate.hasOption(POLYGONS_OPTION_LONG);
Set<String> countriesDenyList = new HashSet<>();
if (this.optionAndArgumentDelegate.hasOption(COUNTRIES_DENY_LIST_OPTION_LONG)) {
countriesDenyList = this.optionAndArgumentDelegate.getOptionArgument(COUNTRIES_DENY_LIST_OPTION_LONG, this::parseCommaSeparatedCountries).orElse(new HashSet<>());
}
if (this.optionAndArgumentDelegate.hasVerboseOption()) {
this.outputDelegate.printlnCommandMessage("reading CountryBoundaryMap from file...");
}
final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new File(this.optionAndArgumentDelegate.getOptionArgument(COUNTRY_BOUNDARY_OPTION_LONG).orElseThrow(AtlasShellToolsException::new)));
final String boundaryJson;
if (countries.isEmpty()) {
boundaryJson = new CountryBoundaryMapGeoJsonConverter().prettyPrint(true).withCountryDenyList(countriesDenyList).usePolygons(usePolygons).convertToString(map);
} else {
boundaryJson = new CountryBoundaryMapGeoJsonConverter().withCountryAllowList(countries).withCountryDenyList(countriesDenyList).prettyPrint(true).usePolygons(usePolygons).convertToString(map);
}
if (this.optionAndArgumentDelegate.hasVerboseOption()) {
this.outputDelegate.printlnCommandMessage("converting boundary file to GeoJSON...");
}
if (this.optionAndArgumentDelegate.hasVerboseOption()) {
this.outputDelegate.printlnCommandMessage("writing the boundary file...");
}
final Path concatenatedPath = Paths.get(getOutputPath().toAbsolutePath().toString(), BOUNDARY_FILE);
new File(concatenatedPath.toAbsolutePath().toString()).writeAndClose(boundaryJson);
return 0;
}
Aggregations