diff --git a/osm_fieldwork/basemapper.py b/osm_fieldwork/basemapper.py index 75648fcf..84d988d3 100755 --- a/osm_fieldwork/basemapper.py +++ b/osm_fieldwork/basemapper.py @@ -454,6 +454,12 @@ def create_basemap_file( f"tms={tms}" ) + # Validation + if not boundary: + err = "You need to specify a boundary! (file or bbox)" + log.error(err) + raise ValueError(err) + # Get all the zoom levels we want zoom_levels = list() if zooms: @@ -528,7 +534,15 @@ def main(): """This main function lets this class be run standalone by a bash script.""" parser = argparse.ArgumentParser(description="Create an tile basemap for ODK Collect") parser.add_argument("-v", "--verbose", action="store_true", help="verbose output") - parser.add_argument("-b", "--boundary", required=True, help="The boundary for the area you want") + parser.add_argument( + "-b", + "--boundary", + nargs="*", + required=True, + help=( + "The boundary for the area you want. " "Accepts path to geojson file or bbox string. " "Format min_x min_y max_x max_y" + ), + ) parser.add_argument("-t", "--tms", help="Custom TMS URL") parser.add_argument("--xy", default=False, help="Swap the X & Y coordinates when using a custom TMS") parser.add_argument( @@ -555,9 +569,26 @@ def main(): parser.print_help() quit() + if len(args.boundary) == 1: + if Path(args.boundary[0]).suffix not in [".json", ".geojson"]: + log.error("") + log.error("*Error*: the boundary file must have .json or .geojson extension") + log.error("") + parser.print_help() + quit() + boundary_parsed = args.boundary[0] + elif len(args.boundary) == 4: + boundary_parsed = ",".join(args.boundary) + else: + log.error("") + log.error("*Error*: the bounding box must have 4 coordinates") + log.error("") + parser.print_help() + quit() + create_basemap_file( verbose=args.verbose, - boundary=args.boundary, + boundary=boundary_parsed, tms=args.tms, xy=args.xy, outfile=args.outfile,