OpenStreetMap (OSM) XML Reader/Writer
Licensing options for this format begin with FME Professional Edition.
The OpenStreetMap (OSM) is a collaborative mapping project for creating a free and editable map of the whole world.
This section assumes familiarity with the OSM format. Further information on OSM can be found at http://www.openstreetmap.org.
Overview
OpenStreetMap data can be downloaded in a topologically structured XML format. The data primitives in an OSM data file are nodes, ways, and relations.
- A node is a lat/lon pair.
- A way is a list of at least two node references describing a linear feature. Ways can be closed, in which case the first and the last node are identical. Areas are not explicitly represented in OSM, but are identified via community-approved tags.
- Relations are a group of zero or more primitives with an associated role. All data in OSM are in the WGS-84 datum.
OSM has no explicit schema (feature type) definitions. Each node, way, and relation can have an arbitrary number of attributes (called tags in OSM). A tag is composed of a key and a value. The OpenStreetMap wiki does define a set of recommend tags that can be used to classify the nodes and ways into higher-level groupings (feature types).
The FME OSM reader provides some user settings to help influence the classification of the OSM data being read. This is needed for most GIS formats that have explicit schema definitions. The community-defined feature types can be found at http://wiki.openstreetmap.org/wiki/Map_Features.
Reader Overview
The OSM reader can interpret OSM XML files in several different ways. The reader may output un-categorized nodes, ways and relations, or it may categorize these data primitives according to the recommended interpretations found in http://wiki.openstreetmap.org/wiki/Map_Features.
The OSM reader provides a tree-view interface when directed to interpret the OSM data with the OSM community-approved feature types. The data can be interpreted using both broad and specific features.
For example, users can choose all broad features by selecting the top-level elements in the tree view (for example, highway, aerialway, etc.); and choose all specific features by expanding the broad features and selecting the specific features (such as highway_motorway, highway_primary, etc.). Users can also select combinations of broad and specific features.
The OSM reader also allows users to provide their own user configuration file. This user configuration file enables users to define their own feature types and also add any attributes or geometry types to them. In addition, the user file can be used to remove existing feature types, attributes, and geometry types.
Note that the reader provides an option to perform a schema scan on top of the selected features in the tree view. In this case, the reader will scan the entire data file and any features found that are also selected in the tree view will be constructed. A schema scan on a large file can be a slow process: in these cases, it may be more desirable to simply select feature types manually.
With three exceptions, the OSM relations are not interpreted. The interpreted relations are the ones that are tagged with a key of type
and values of either multipolygon
, route
, or restriction
. Both route
and restriction
are output as non-geometrical features, and their feature types are set to relation_route
and relation_restriction
, respectively. The multipolygon
relation is output as an area or multi-area geometry; this includes donuts, or an aggregate of polygons and donuts. The multipolygon
relation may be output as a line or a non-geometrical feature. In the case of bad geometrical information, the multipolygon
relation feature type will be set to relation_multipolygon
.
Geometry
The OSM reader supports points, lines, and area geometries. Points are constructed from OSM nodes, linear features from OSM ways, and area features are constructed from either appropriately tagged closed OSM ways, or from OSM multipolygon relations.
Coordinate Systems
The features output by the OSM reader are always in LL84.
FME Feature Attributes
All OSM tags are loaded from the OSM data primitives are loaded as FME feature attributes. Relation feature types will have their members mapped as an FME list attribute in the FME feature. The list attribute will have 3 components:
member{}.type
member{}.ref
member{}.role
Relation feature types will also have an attribute named as osm_relation_type
to describe the type of relation.
You can use this member list attribute to further process the relations within FME Workbench.
In OSM way features are constructed by reference to node IDs. These node IDs are mapped into the nd{}.ref
list attribute in FME way features.
Writer Overview
The OSM writer will write out features as nodes, ways, and relations into an OSM file. Lines and areas that have more than 2000 points will be split into multiple ways, each having at most 2000 nodes. Duplicated nodes are also handled to make sure no duplicate OSM nodes are written out. Conversion of coordinates into WGS84/LL84 is done automatically into the writer.
Feature types in OSM writer do not have any predefined schema. User attributes that are specified on the feature type will be used as tags in the OSM elements of the output file, if such attributes exist on the features or geometry traits of the geometry.
Example: A feature type named “amenity” has 3 tags that OSM writer will create if the features have such attributes:
OSM_2_DEF amenity \
amenity xml_char(17) \
building xml_char(4) \
source xml_char(19)
There are common attributes on each OSM element that the writer will write out if feature attributes or geometry traits exist: id, uid, timestamp, visible, changeset, and version
.
If an OSM node, point or relation does not have an id
attribute found on geometry or feature, then a negative value will be assigned to each element.
All geometries that contain points (including line, polygon, donut or any multi geometry) will have their coordinates written out as OSM nodes.
Tags on the OSM node will only be written out if there are user attributes defined on feature types and such attributes exist on the feature as attributes or point-level geometry as traits.
In the case where there are multiple sources of the same node (for example, from a point and a line), only the first node with positive ID is written out. If there are no nodes with positive ID, then the first node the writer encounters will be written out.
All linear geometries will have corresponding OSM way elements written out. The writer does not check for duplicated lines.
A feature is written out as an OSM relation if osm_relation_type
attribute exist, and the value of such attribute determines the type of relation.
Tags that are associated with the relation must be specified as attributes on the features. Tags for the members (OSM ways and nodes) must be specified as traits on each geometry part of feature.
OSM writer also writes out multipolygon relation from donut or multipolygon geometry, even if osm_relation_type
attribute does not exist on the feature.
The multipolygon relation that is written out follows the rules and examples described in http://wiki.openstreetmap.org/wiki/Relation:multipolygon
A feature with null or no geometry can be used to describe an OSM relation by specifying the following attributes:
osm_relation_type |
The type of OSM relation to be written out |
member{}.ref, member{}.role and member{}.type list |
Each attribute describes the reference id, role and type of members in relation. The length of list attributes must be equal; otherwise, no relation will be written out. |
A feature with collection geometry can be written out as any relation provided that osm_relation_type
is specified. All non-null geometry parts will be written out as ways and/or nodes and included as members in the relation. The attributes of <member>
element (role
and type
) must be specified as traits to the geometry parts. The ref attribute of <member>
is populated from the ID of the ways or nodes that have been written out.
© OpenStreetMap contributors