def test_query_utm_crs_info__aoi_contains(): aoi = BBox(west=41, south=50, east=42, north=51) crs_info_list = query_utm_crs_info( area_of_interest=AreaOfInterest( west_lon_degree=aoi.west, south_lat_degree=aoi.south, east_lon_degree=aoi.east, north_lat_degree=aoi.north, ), contains=True, ) assert crs_info_list for crs_info in crs_info_list: assert BBox(*crs_info.area_of_use.bounds).contains(aoi) assert "UTM zone" in crs_info.name assert crs_info.auth_name == "EPSG" assert crs_info.type == PJType.PROJECTED_CRS assert not crs_info.deprecated
def test_get_transform_grid_list__bbox__out_of_bounds(): grids = get_transform_grid_list(bbox=BBox(170, -90, 190, 90), include_already_downloaded=True) assert len(grids) > 10 source_ids = set() for grid in grids: source_ids.add(grid["properties"]["source_id"]) assert sorted(source_ids) == [ "au_ga", "nc_dittt", "nz_linz", "us_nga", "us_noaa" ]
def test_query_crs_info__aoi_contains(): aoi = BBox(west=-40, south=50, east=-20, north=70) crs_info_list = query_crs_info( auth_name="IGNF", pj_types=[PJType.PROJECTED_CRS], area_of_interest=AreaOfInterest( west_lon_degree=aoi.west, south_lat_degree=aoi.south, east_lon_degree=aoi.east, north_lat_degree=aoi.north, ), contains=True, ) assert crs_info_list for crs_info in crs_info_list: assert BBox(*crs_info.area_of_use.bounds).contains(aoi) assert crs_info.auth_name == "IGNF" assert crs_info.type == PJType.PROJECTED_CRS assert not crs_info.deprecated
def test_query_utm_crs_info__aoi_datum_name(datum_name): aoi = BBox(west=-93.581543, south=42.032974, east=-93.581543, north=42.032974) crs_info_list = query_utm_crs_info( datum_name=datum_name, area_of_interest=AreaOfInterest( west_lon_degree=aoi.west, south_lat_degree=aoi.south, east_lon_degree=aoi.east, north_lat_degree=aoi.north, ), ) assert len(crs_info_list) == 1 crs_info = crs_info_list[0] bbox = BBox(*crs_info.area_of_use.bounds) assert bbox.intersects(aoi) assert "UTM zone" in crs_info.name assert datum_name.replace(" ", "") in crs_info.name.replace(" ", "") assert crs_info.auth_name == "EPSG" assert crs_info.type == PJType.PROJECTED_CRS assert not crs_info.deprecated
def test_get_transform_grid_list__contains(): grids = get_transform_grid_list( bbox=BBox(170, -90, -170, 90), spatial_test="contains", include_already_downloaded=True, ) assert len(grids) > 5 source_ids = set() for grid in grids: source_ids.add(grid["properties"]["source_id"]) assert sorted(source_ids) == ["nz_linz"]
def test_get_transform_grid_list__source_id(): grids = get_transform_grid_list( bbox=BBox(170, -90, -170, 90), source_id="us_noaa", include_already_downloaded=True, ) assert len(grids) > 5 source_ids = set() for grid in grids: source_ids.add(grid["properties"]["source_id"]) assert sorted(source_ids) == ["us_noaa"]
def test_query_crs_info__aoi(): aoi = BBox(west=-40, south=50, east=-20, north=70) crs_info_list = query_crs_info( auth_name="ESRI", pj_types=PJType.PROJECTED_CRS, area_of_interest=AreaOfInterest( west_lon_degree=aoi.west, south_lat_degree=aoi.south, east_lon_degree=aoi.east, north_lat_degree=aoi.north, ), ) assert crs_info_list not_contains_present = False for crs_info in crs_info_list: bbox = BBox(*crs_info.area_of_use.bounds) assert bbox.intersects(aoi) assert crs_info.auth_name == "ESRI" assert crs_info.type == PJType.PROJECTED_CRS assert not crs_info.deprecated if not bbox.contains(aoi): not_contains_present = True assert not_contains_present
def _bbox_from_coords(coords: List) -> Optional[BBox]: """ Get the bounding box from coordinates """ try: xx, yy = zip(*coords) return BBox(west=min(xx), south=min(yy), east=max(xx), north=max(yy)) except ValueError: pass coord_bbox = None for coord_set in coords: bbox = _bbox_from_coords(coord_set) if coord_bbox is None: coord_bbox = bbox else: coord_bbox.west = min(coord_bbox.west, bbox.west) coord_bbox.south = min(coord_bbox.south, bbox.south) coord_bbox.north = max(coord_bbox.north, bbox.north) coord_bbox.east = max(coord_bbox.east, bbox.east) return coord_bbox
def test_not_intersects(): assert not BBox(1, 1, 4, 4).intersects(BBox(10, 10, 20, 20))
def test_intersects(): assert BBox(1, 1, 4, 4).intersects(BBox(2, 2, 5, 5))
def test_not_contains(): assert not BBox(1, 1, 4, 4).contains(BBox(2, 2, 5, 5))
def test_contains(): assert BBox(1, 1, 4, 4).contains(BBox(2, 2, 3, 3))
def main(): args = parser.parse_args() if hasattr(args, "bbox") and any(( args.bbox, args.list_files, args.all, args.source_id, args.area_of_use, args.file, )): if args.all and (args.list_files or args.source_id or args.area_of_use or args.file or args.bbox): raise RuntimeError( "Cannot use '--all' with '--list-files', '--source-id'," "'--area-of-use', '--bbox', or '--file'.") bbox = None if args.bbox is not None: west, south, east, north = args.bbox.split(",") bbox = BBox( west=float(west), south=float(south), east=float(east), north=float(north), ) if args.target_directory and args.system_directory: raise RuntimeError( "Cannot set both --target-directory and --system-directory.") target_directory = args.target_directory if args.system_directory: target_directory = get_data_dir().split(os.path.sep)[0] elif not target_directory: target_directory = get_user_data_dir(True) grids = get_transform_grid_list( source_id=args.source_id, area_of_use=args.area_of_use, filename=args.file, bbox=bbox, spatial_test=args.spatial_test, include_world_coverage=not args.exclude_world_coverage, include_already_downloaded=args.include_already_downloaded, target_directory=target_directory, ) if args.list_files: print("filename | source_id | area_of_use") print("----------------------------------") else: endpoint = get_proj_endpoint() for grid in grids: if args.list_files: print( grid["properties"]["name"], grid["properties"]["source_id"], grid["properties"].get("area_of_use"), sep=" | ", ) else: filename = grid["properties"]["name"] _download_resource_file( file_url=f"{endpoint}/{filename}", short_name=filename, directory=target_directory, verbose=args.verbose, sha256=grid["properties"]["sha256sum"], ) elif not hasattr(args, "bbox") and args.verbose: _show_versions.show_versions() elif hasattr(args, "bbox"): sync_parser.print_help() else: parser.print_help()