|
| 1 | +""" |
| 2 | +Exploratory script for reformatting OSM data into a tabular format. |
| 3 | +
|
| 4 | +This script: |
| 5 | +1. Reads in the OSM versions and changes data from CSV files. |
| 6 | +2. Reconfigures POI changesets into 'observations', which are either changes to the |
| 7 | + relevant POI tag or confirmation that the tag is unchanged. |
| 8 | +3. Saves the observations to a new CSV file. |
| 9 | +""" |
| 10 | + |
| 11 | +import pandas as pd |
| 12 | +from pathlib import Path |
| 13 | + |
| 14 | +from openpois.osm.format_observations import format_observations |
| 15 | + |
| 16 | + |
| 17 | +# ---------------------------------------------------------------------------------------- |
| 18 | +# Configuration constants |
| 19 | +# ---------------------------------------------------------------------------------------- |
| 20 | + |
| 21 | +DATA_VERSION = "20260129" |
| 22 | +SAVE_DIR = Path("~/data/openpois").expanduser() / DATA_VERSION |
| 23 | +OSM_KEYS = ["amenity", "shop", "healthcare", "leisure"] |
| 24 | +TAG_KEY = "shop" |
| 25 | + |
| 26 | + |
| 27 | +# ---------------------------------------------------------------------------------------- |
| 28 | +# Main workflow |
| 29 | +# ---------------------------------------------------------------------------------------- |
| 30 | + |
| 31 | +if __name__ == "__main__": |
| 32 | + # Read files |
| 33 | + changes_df = pd.read_csv(SAVE_DIR / "osm_changes.csv") |
| 34 | + versions_df = pd.read_csv(SAVE_DIR / "osm_versions.csv") |
| 35 | + |
| 36 | + # Format changes and versions into observations |
| 37 | + observations_df = format_observations( |
| 38 | + changes_df = changes_df, |
| 39 | + versions_df = versions_df, |
| 40 | + tag_key = TAG_KEY, |
| 41 | + keep_keys = OSM_KEYS, |
| 42 | + ) |
| 43 | + |
| 44 | + # Save observations |
| 45 | + observations_df.to_csv( |
| 46 | + SAVE_DIR / f"osm_observations_{TAG_KEY}.csv", |
| 47 | + index = False, |
| 48 | + ) |
| 49 | + print(f"Saved {len(observations_df)} observations to {out_fp}") |
0 commit comments