Search in sources :

Example 1 with CountryBoundaryMapGeoJsonConverter

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;
}
Also used : Path(java.nio.file.Path) AtlasShellToolsException(org.openstreetmap.atlas.utilities.command.AtlasShellToolsException) CountryBoundaryMapGeoJsonConverter(org.openstreetmap.atlas.geography.boundary.converters.CountryBoundaryMapGeoJsonConverter) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) File(org.openstreetmap.atlas.streaming.resource.File) HashSet(java.util.HashSet)

Aggregations

Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 CountryBoundaryMap (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)1 CountryBoundaryMapGeoJsonConverter (org.openstreetmap.atlas.geography.boundary.converters.CountryBoundaryMapGeoJsonConverter)1 File (org.openstreetmap.atlas.streaming.resource.File)1 AtlasShellToolsException (org.openstreetmap.atlas.utilities.command.AtlasShellToolsException)1