geo_sampling package¶
Submodules¶
geo_sampling.geo_roads module¶
Process geo roads data to sample road segments, generate BBBike extract links, and optionally plot the output.
- This script:
Downloads GADM boundaries if needed.
Downloads OSM data from BBBike.org.
Extracts road segments from a roads shapefile.
Splits long segments into chunks (default 500 m).
Writes output to a CSV file.
Optionally plots the segments.
- geo_sampling.geo_roads.bbbike_check_download_link(args)¶
Check for the download link on BBBike.org until it is ready or times out.
- Args:
args (argparse.Namespace): Parsed command-line arguments.
- Returns:
str: The download link if found; otherwise an empty string.
- geo_sampling.geo_roads.bbbike_generate_extract_link(args)¶
Generate a BBBike extract URL for a specified administrative boundary.
- Args:
args (argparse.Namespace): Parsed command-line arguments.
- Returns:
tuple: (city, URL) if successful; otherwise (None, None).
- geo_sampling.geo_roads.bbbike_submit_extract_link(args)¶
Submit the extract link to BBBike.org.
- Args:
args (argparse.Namespace): Parsed command-line arguments.
- Returns:
bool: True if submission is successful, False otherwise.
- geo_sampling.geo_roads.check_length(line_obj)¶
Print the lengths of segments in a LineString and the total length.
- geo_sampling.geo_roads.download_url(url, local_path)¶
Download a URL to a local file with error handling.
- Args:
url (str): The URL to download. local_path (str): Path to save the file.
- Raises:
requests.RequestException: If the download fails. IOError: If the file cannot be written.
- geo_sampling.geo_roads.gadm_download_country_data(ccode)¶
Download GADM boundary data for a country.
- Args:
ccode (str): Country code.
- Returns:
str: Local filename of downloaded data.
- geo_sampling.geo_roads.gadm_get_country_list()¶
Retrieve a list of countries and codes from GADM.
- Returns:
dict: Dictionary mapping country names to codes.
- Raises:
requests.RequestException: If the request to GADM fails. ValueError: If no countries are found in the response.
- geo_sampling.geo_roads.main(argv=None)¶
Main function for processing geo roads data and generating BBBike extract links.
- Args:
argv (list): Command-line arguments.
- Returns:
int: Exit code.
- geo_sampling.geo_roads.output_to_file(writer, uid, osm_id, osm_name, osm_type, line_obj)¶
Write segments of a LineString to CSV.
- Args:
writer (csv.DictWriter): CSV writer. uid (int): Current segment ID. osm_id: OSM identifier. osm_name: OSM name. osm_type: OSM type. line_obj (LineString): Shapely LineString object.
- Returns:
int: Updated segment ID.
- geo_sampling.geo_roads.redistribute_vertices(geom, distance)¶
Redistribute vertices along a LineString to achieve approximately equal segments of a given distance.
- Args:
geom (LineString): The original LineString. distance (float): Desired segment length in meters.
- Returns:
LineString: New LineString with redistributed vertices.
- Raises:
ValueError: If geometry type is unhandled.
geo_sampling.sample_roads module¶
This module samples road segments from an input file and optionally plots them.
- geo_sampling.sample_roads.main(argv=None)¶
Main function to parse arguments and sample road segments.