You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user_manual/02-Extracting-Object-Data.md
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,8 @@ Finally, there is a type for changesets, which contains information about
14
14
edits in the OSM database. It can only appear in special changeset files
15
15
and explained in more detail [below](#changeset).
16
16
17
-
The FileProcessor may return any of these objects, when iterating over a file.
17
+
When iterating over a file, then the FileProcessor may return any of these
18
+
objects.
18
19
Therefore, a script will usually first need to determine the type of object
19
20
received. There are a couple of ways to do this.
20
21
@@ -83,7 +84,7 @@ You can simply test for this object type:
83
84
## Reading object tags
84
85
85
86
Every object has a list of properties, the tags. They can be accessed through
86
-
the `tags` property, which provides a simple dictionary-like view of the tags.
87
+
the `tags` property. It provides a simple dictionary-like view of the tags.
87
88
You can use the bracket notation to access a specific tag or use the more
88
89
explicit `get()` function. Just like for Python dictionaries, an access by
89
90
bracket raises a `ValueError` when the key you are looking for does not exist,
@@ -140,7 +141,23 @@ list into a Python dictionary:
140
141
## Other common meta information
141
142
142
143
Next to the tags, every OSM object also carries some meta information
143
-
describing its ID, version and information regarding the editor.
144
+
which all can be accessed through read-only properties.
145
+
146
+
The most important meta information is the object's ID in the `id` property.
147
+
This is the ID used when objects reference each other.
148
+
149
+
The other meta fields contain information when and by whom the objet was edited.
150
+
The following table gives a quick overview over these fields:
151
+
152
+
| Property | Description |
153
+
|-----------|--------------------------|
154
+
| version | Version of the object. A newly created object starts with version 1. |
155
+
| deleted | A boolean property stating if the object should be used or ignored. Only relevant for [change](08-Working-With-Change-Files.md) and [history](09-Working-With-History-Files.md) files. |
156
+
| changeset | The ID of the change set this object was created with. A change set contains a set of edits that have been uploaded by an editor in a single session. |
157
+
| timestamp | UTC time at which the object was created, or more precisely, added to the database. |
158
+
| uid | The ID of the user who created this version of the object. User IDs are univocal and prepetual. |
159
+
| user | The name of the user who created this version of the object. This is the name the user had when the object was created. User names may be changed over time. The same name in different objects doesn't necessarily reference the same user. |
Copy file name to clipboardExpand all lines: docs/user_manual/06-Writing-Data.md
+57-3Lines changed: 57 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,18 @@ pyosmium will refuse to overwrite any existing files. Either make sure to
18
18
delete the files before instantiating a writer or use the parameter
19
19
`overwrite=true`.
20
20
21
+
All writers are [context managers](https://docs.python.org/3/reference/datamodel.html#context-managers) and to ensure that the file is properly closed in the
22
+
end, the recommended way to use them is in a with statement:
23
+
24
+
!!! example
25
+
```python
26
+
with osmium.SimpleWriter('my_extra_data.osm.pbf') as writer:
27
+
# do stuff here
28
+
```
29
+
30
+
When not used inside a with block, then don't forget to call the `close()`
31
+
function explicitly to close the writer.
32
+
21
33
Once a writer is instantiated, one of the `add*` functions can be used to
22
34
add an OSM object to the file. You can either use one of the
23
35
`add_node/way/relation` functions to force writing a specific type of
@@ -27,9 +39,6 @@ they are given to the writer object. It is your responsibility as a user to
27
39
make sure that the order is correct with respect to the
28
40
[conventions for object order][order-in-osm-files].
29
41
30
-
After writing all data the writer needs to be closed using the `close()`
31
-
function. It is usually easier to use a writer as a context manager.
32
-
33
42
Here is a complete example for a script that converts a file from OPL format
34
43
to PBF format:
35
44
@@ -129,3 +138,48 @@ pyosmium implements three different writer classes: the basic
129
138
the two reference-completing writers
130
139
[ForwardReferenceWriter][osmium.ForwardReferenceWriter] and
0 commit comments