Skip to content

AugmentedDiff#

This class is used to represent an OSM Augmented Diff. For more information about OSM Augmented Diffs, see the Augmented Diff page on the OpenStreetMap Wiki.

Basic usage:

>>> from osmdiff import AugmentedDiff
>>> ad = AugmentedDiff()
>>> ad.get_state()
True
>>> ad.sequence_number
6509700
>>> ad.retrieve()
200
>>> ad.sequence_number
6509701
>>> ad
AugmentedDiff (2776 created, 927 modified, 6999 deleted)
>>> ad.retrieve()
200
>>> ad.sequence_number
6509702
>>> ad
AugmentedDiff (3191 created, 1724 modified, 7077 deleted)  # the results of the two calls to retrieve() are merged

osmdiff.augmenteddiff.AugmentedDiff #

Bases: object

An Augmented Diff representation for OpenStreetMap changes.

This class handles the retrieval and parsing of OpenStreetMap augmented diffs, which contain detailed information about changes made to OSM data, including creations, modifications, and deletions.

Parameters:

Name Type Description Default
minlon float | None

Minimum longitude of bounding box

None
minlat float | None

Minimum latitude of bounding box

None
maxlon float | None

Maximum longitude of bounding box

None
maxlat float | None

Maximum latitude of bounding box

None
file str | None

Path to an augmented diff file to parse

None
sequence_number int | None

Sequence number of the augmented diff

None
timestamp datetime | None

Timestamp of the augmented diff

None

Attributes:

Name Type Description
base_url

Base URL for the Overpass API

create

List of created OSM objects

modify

List of modified OSM objects (containing old and new versions)

delete

List of deleted OSM objects

remarks

List of remarks from the augmented diff

timestamp

Timestamp of the augmented diff

Raises:

Type Description
Exception

If an invalid bounding box is provided

ValueError

If sequence_number is not parseable as an integer

Example
# Create an AugmentedDiff instance with a bounding box
adiff = AugmentedDiff(
    minlon=-0.489,
    minlat=51.28,
    maxlon=0.236,
    maxlat=51.686
)

# Get the current state
adiff.get_state()

# Retrieve the diff
status = adiff.retrieve()
if status == 200:
    print(f"Created: {len(adiff.create)}")
    print(f"Modified: {len(adiff.modify)}")
    print(f"Deleted: {len(adiff.delete)}")

__exit__(exc_type, exc_val, exc_tb) #

Clear all changes when exiting context.

get_state() #

Get the current state from the OSM API.

Returns:

Type Description
bool

True if state was successfully retrieved, False otherwise

retrieve(clear_cache=False, timeout=None, auto_increment=True, max_retries=3) #

Retrieve the Augmented diff corresponding to the sequence_number.

Parameters:

Name Type Description Default
clear_cache bool

Whether to clear existing data before retrieval.

False
timeout Optional[int]

Request timeout in seconds.

None
auto_increment bool

Whether to automatically increment sequence number after retrieval.

True
max_retries int

Maximum number of retry attempts for failed requests.

3

Returns:

Type Description
int

HTTP status code of the request (200 for success)

Raises:

Type Description
Exception

If sequence_number is not set

RequestException

If all retry attempts fail