mapreader.download.sheet_downloader

Classes

SheetDownloader

A class to download map sheets using metadata.

Module Contents

class mapreader.download.sheet_downloader.SheetDownloader(metadata_path, download_url)

A class to download map sheets using metadata.

Parameters:
  • metadata_path (str)

  • download_url (str | list)

found_queries
merged_polygon = None
tile_server
crs
get_grid_bb(zoom_level=14)

Creates a grid bounding box for each map in metadata.

Parameters:

zoom_level (int, optional) – The zoom level to use when creating the grid bounding box. Later used when downloading maps, by default 14.

Return type:

None

extract_wfs_id_nos()

Extracts WFS ID numbers from metadata.

Return type:

None

extract_published_dates(date_col=None)

Extracts publication dates from metadata.

Parameters:

date_col (str or None, optional) – A string indicating the metadata column containing the publication date. If None, “WFS_TITLE” will be used. Date will then be extracted by regex searching for “Published: XXX”. By default None.

Return type:

None

get_merged_polygon()

Creates a multipolygon representing all maps in metadata.

Return type:

None

get_minmax_latlon()

Prints minimum and maximum latitudes and longitudes of all maps in metadata.

Return type:

None

query_map_sheets_by_wfs_ids(wfs_ids, append=False, print=False)

Find map sheets by WFS ID numbers.

Parameters:
  • wfs_ids (Union[list, int]) – The WFS ID numbers of the maps to download.

  • append (bool, optional) – Whether to append to current query results or start over. By default False

  • print (bool, optional) – Whether to print query results or not. By default False

Return type:

None

query_map_sheets_by_polygon(polygon, mode='within', append=False, print=False)

Find map sheets which are found within or intersecting with a defined polygon.

Parameters:
  • polygon (Polygon) – shapely Polygon

  • mode (str, optional) – The mode to use when finding maps. Options of "within", which returns all map sheets which are completely within the defined polygon, and "intersects"", which returns all map sheets which intersect/overlap with the defined polygon. By default “within”.

  • append (bool, optional) – Whether to append to current query results or start over. By default False

  • print (bool, optional) – Whether to print query results or not. By default False

Return type:

None

Notes

Use create_polygon_from_latlons() to create polygon.

query_map_sheets_by_coordinates(coords, append=False, print=False)

Find maps sheets which contain a defined set of coordinates. Coordinates are (x,y).

Parameters:
  • coords (tuple) – Coordinates in (x,y) format.

  • append (bool, optional) – Whether to append to current query results or start over. By default False

  • print (bool, optional) – Whether to print query results or not. By default False

Return type:

None

query_map_sheets_by_line(line, append=False, print=False)

Find maps sheets which intersect with a line.

Parameters:
  • line (LineString) – shapely LineString

  • append (bool, optional) – Whether to append to current query results or start over. By default False

  • print (bool, optional) – Whether to print query results or not. By default False

Return type:

None

Notes

Use create_line_from_latlons() to create line.

query_map_sheets_by_string(string, columns=None, append=False, print=False)

Find map sheets by searching for a string in the metadata.

Parameters:
  • string (str) – The string to search for. Can be raw string and use regular expressions.

  • columns (str or list, optional) – A column or list of columns to search in. If None, will search in all metadata fields.

  • append (bool, optional) – Whether to append to current query results or start over. By default False

  • print (bool, optional) – Whether to print query results or not. By default False

Return type:

None

Notes

string is case insensitive.

print_found_queries()

Prints query results.

Return type:

None

download_all_map_sheets(path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Downloads all map sheets in metadata.

Parameters:
  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False.

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

download_map_sheets_by_wfs_ids(wfs_ids, path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Downloads map sheets by WFS ID numbers.

Parameters:
  • wfs_ids (Union[list, int]) – The WFS ID numbers of the maps to download.

  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False.

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

download_map_sheets_by_polygon(polygon, path_save='maps', metadata_fname='metadata.csv', mode='within', overwrite=False, download_in_parallel=True, **kwargs)

Downloads any map sheets which are found within or intersecting with a defined polygon.

Parameters:
  • polygon (Polygon) – shapely Polygon

  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • mode (str, optional) – The mode to use when finding maps. Options of "within", which returns all map sheets which are completely within the defined polygon, and "intersects"", which returns all map sheets which intersect/overlap with the defined polygon. By default “within”.

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False.

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

Notes

Use create_polygon_from_latlons() to create polygon.

download_map_sheets_by_coordinates(coords, path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Downloads any maps sheets which contain a defined set of coordinates. Coordinates are (x,y).

Parameters:
  • coords (tuple) – Coordinates in (x,y) format.

  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False.

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

download_map_sheets_by_line(line, path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Downloads any maps sheets which intersect with a line.

Parameters:
  • line (LineString) – shapely LineString

  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

Notes

Use create_line_from_latlons() to create line.

download_map_sheets_by_string(string, columns=None, path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Download map sheets by searching for a string in the metadata.

Parameters:
  • string (str) – The string to search for. Can be raw string and use regular expressions.

  • columns (str or list or None, optional) – A column or list of columns to search in. If None, will search in all metadata fields. By default None.

  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False.

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

Notes

string is case insensitive.

download_map_sheets_by_queries(path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Downloads map sheets saved as query results.

Parameters:
  • path_save (str, optional) – Path to save map sheets, by default “maps”

  • metadata_fname (str, optional) – Name to use for metadata file, by default “metadata.csv”

  • overwrite (bool, optional) – Whether to overwrite existing maps, by default False.

  • download_in_parallel (bool, optional) – Whether to download tiles in parallel, by default True.

  • **kwargs (dict, optional) – Keyword arguments to pass to the _download_map_sheets() method.

Return type:

None

plot_features_on_map(features, map_extent=None, add_id=False)

Plot boundaries of map sheets on a map using cartopy.

Parameters:
  • map_extent (Union[str, list, tuple, None], optional) –

    The extent of the underlying map to be plotted.

    If a tuple or list, must be of the format [lon_min, lon_max, lat_min, lat_max]. If a string, only "uk", "UK" or "United Kingdom" are accepted and will limit the map extent to the UK’s boundaries. If None, the map extent will be set automatically. By default None.

  • add_id (bool, optional) – Whether to add an ID (WFS ID number) to each map sheet, by default False.

  • features (geopandas.GeoDataFrame)

Return type:

None

plot_all_metadata_on_map(map_extent=None, add_id=False)

Plots boundaries of all map sheets in metadata on a map using cartopy.

Parameters:
  • map_extent (Union[str, list, tuple, None], optional) –

    The extent of the underlying map to be plotted.

    If a tuple or list, must be of the format [lon_min, lon_max, lat_min, lat_max]. If a string, only "uk", "UK" or "United Kingdom" are accepted and will limit the map extent to the UK’s boundaries. If None, the map extent will be set automatically. By default None.

  • add_id (bool, optional) – Whether to add an ID (WFS ID number) to each map sheet, by default False.

Return type:

None

plot_queries_on_map(map_extent=None, add_id=False)

Plots boundaries of query results on a map using cartopy.

Parameters:
  • map_extent (Union[str, list, tuple, None], optional) –

    The extent of the underlying map to be plotted.

    If a tuple or list, must be of the format [lon_min, lon_max, lat_min, lat_max]. If a string, only "uk", "UK" or "United Kingdom" are accepted and will limit the map extent to the UK’s boundaries. If None, the map extent will be set automatically. By default None.

  • add_id (bool, optional) – Whether to add an ID (WFS ID number) to each map sheet, by default False.

Return type:

None