mapreader.download.sheet_downloader

Module Contents

Classes

SheetDownloader

A class to download map sheets using metadata.

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)

get_polygons()

For each map in metadata, creates a polygon from map geometry and saves to features dictionary.

Return type:

None

get_grid_bb(zoom_level=14)

For each map in metadata, creates a grid bounding box from map polygons and saves to features dictionary.

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()

For each map in metadata, extracts WFS ID numbers from WFS information and saves to features dictionary.

Return type:

None

extract_published_dates(date_col=None)

For each map in metadata, extracts publication date and saves to features dictionary.

Parameters:

date_col (str or list, optional) –

A key or list of keys which map to the metadata field containing the publication date. Multilayer keys should be passed as a list. e.g.:

  • ”key1” will extract self.features[i]["key1"]

  • [“key1”,”key2”] will search for self.features[i]["key1"]["key2"]

If None, [“properties”][“WFS_TITLE”] will be used as keys. 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 list or, if False, start a new list. 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 list or, if False, start a new list. 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 list or, if False, start a new list. 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 list or, if False, start a new list. 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, keys=None, append=False, print=False)

Find map sheets by searching for a string in a chosen metadata field.

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

  • keys (str or list, optional) –

    A key or list of keys used to get the metadata field to search in.

    Key(s) will be passed to each features dictionary. Multilayer keys should be passed as a list. e.g. [“key1”,”key2”] will search for self.features[i]["key1"]["key2"].

    If None, will search in all metadata fields. By default None.

  • append (bool, optional) – Whether to append to current query results list or, if False, start a new list. 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, keys=None, path_save='maps', metadata_fname='metadata.csv', overwrite=False, download_in_parallel=True, **kwargs)

Download map sheets by searching for a string in a chosen metadata field.

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

  • keys (str or list, optional) –

    A key or list of keys used to get the metadata field to search in.

    Key(s) will be passed to each features dictionary. Multilayer keys should be passed as a list. e.g. [“key1”,”key2”] will search for self.features[i]["key1"]["key2"].

    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

hist_published_dates(**kwargs)

Plots a histogram of the publication dates of maps in metadata.

Parameters:

**kwargs (dict, optional) –

A dictionary containing keyword arguments to pass to plotting function. See matplotlib.pyplot.hist() for acceptable values.

e.g. **dict(fc='c', ec='k')

Return type:

None

Notes

bins and range already set when plotting so are invalid kwargs.

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

Plots boundaries of map sheets on a map using cartopy library, (if available).

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 True.

  • features (list)

Return type:

None

plot_all_metadata_on_map(map_extent=None, add_id=True)

Plots boundaries of all map sheets in metadata on a map using cartopy library (if available).

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 True.

Return type:

None

plot_queries_on_map(map_extent=None, add_id=True)

Plots boundaries of query results on a map using cartopy library (if available).

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 True.

Return type:

None