OSMChange#
Core class for retrieving and parsing OpenStreetMap changesets in OSMChange format.
For working with the Augmented Diff format, we have AugmentedDiff and ContinuousAugmentedDiff.
Features#
- Retrieves changesets from OSM replication servers
- Parses OSMChange XML format
- Handles create/modify/delete actions
- Supports both remote and local file sources
- Context manager support
- Sequence number management
Basic Usage#
from osmdiff import OSMChange
# Create with sequence number
osm_change = OSMChange(sequence_number=12345)
# Retrieve and process changes
status = osm_change.retrieve()
if status == 200:
creations = osm_change.actions["create"]
modifications = osm_change.actions["modify"]
deletions = osm_change.actions["delete"]
print(f"Created: {len(creations)} features")
print(f"Modified: {len(modifications)} features")
print(f"Deleted: {len(deletions)} features")
API Reference#
Bases: object
Handles OpenStreetMap changesets in OSMChange format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
Optional[str]
|
Base URL of OSM replication server |
None
|
frequency
|
str
|
Replication frequency (‘minute’, ‘hour’, or ‘day’) |
'minute'
|
file
|
Optional[str]
|
Path to local OSMChange XML file |
None
|
sequence_number
|
Optional[int]
|
Sequence number of the diff |
None
|
timeout
|
Optional[int]
|
Request timeout in seconds |
None
|
Note
Follows the OSM replication protocol.
Source code in src/osmdiff/osmchange.py
sequence_number
property
writable
#
frequency
property
writable
#
actions
property
#
Get all actions combined in a single list.
get_state()
#
Retrieve the current state from the OSM API.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if state was successfully retrieved, False otherwise |
Raises:
Type | Description |
---|---|
RequestException
|
If the API request fails |
Source code in src/osmdiff/osmchange.py
retrieve(clear_cache=False, timeout=None)
#
Retrieve the OSM diff corresponding to the OSMChange sequence_number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clear_cache
|
bool
|
clear the cache |
False
|
timeout
|
int
|
request timeout |
None
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
HTTP status code |
Raises:
Type | Description |
---|---|
Exception
|
If an invalid sequence number is provided |
Source code in src/osmdiff/osmchange.py
__repr__()
#
See Also#
- AugmentedDiff - For augmented diffs with additional metadata