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
OSM v0.6 from 2009 is the latest version and some tools like Osmosis, libosmium and JOSM strictly enforce this specification. Some of the OSM files we use for tests do not comply with this spec. I think they should be converted so they can be used with recent tools.
I had a closer look at this and to my surprise the 'v0.5/6' API definition is not very strict at all. First of all I could not find a definite resource about the exact specification of v0.6. Osmosis, osmium-tool and JOSM all claim to 'require' v0.6, but what exactly does this even mean? The wiki has this page: https://wiki.openstreetmap.org/wiki/API_v0.6/DTD, but it says 'N.B.: This schema is incomplete!'.
So I tried opening test-osm.xml with the different tools and the result was:
osmosis complaint about missing 'version' attributes. After adding version="1" to all nodes and ways it complaint about missing timestamps. But when I used the enableDateParsing=no option it accepted the file. I was also able to use the --migrate option with osmosis 0.35.1 in combination with --read-xml-0.5 which is supposed to migrate to v0.6 and apparently simply adds the current timestamp, user="" and version="1".
JOSM also complaint about the missing version attribute, but after adding this it accepted the file
osmium accepted the file without any problem, even without adding the version attribute
Strangely, the version attribute required by JOSM and osmosis is listed as 'implied'(=optional) in above linked DTD, so this does not seem very helpful.
Conclusion: Simply adding some "version" attribute to all nodes,ways,relations makes our files compatible with the latest versions of osmosis, osmium and JOSM and I do not think there is a reason to do anything beyond this for now.
We should also sort our XML files. I ran into a few problems when trying to convert unsorted XMLs into pbfs as this yielded unsorted pbfs which are not supported by a few tools.
Objects are sorted by type, ID, and version. IDs are sorted negative IDs first, the positive IDs, both ordered by their absolute values. So the sort order for types and IDs is:
node -1, node -2, …, node 1, node 2, …, way -1, way -2, …, way 1, way 2, …, relation -1, relation -2, …, relation 1, relation 2, …
Is this the format osmium expects or the output format of osmium's sort command? And what are we trying to achieve here? In case we want to remove xml support we need a pre-processing step that converts xml to pbf right? How do you think should this be done? Osmosis might be easier to integrate because its Java. Osmium would require an extra installation step. If we decide to use Osmium of course we can sort the 2 or 3 unsorted test files.
But honestly I am not entirely sold on the idea that we even need to remove the XML support yet. Can you explain why exactly this would be beneficial?
Most tools nowadays require pbfs to be sorted like e.g osm2pgsql 1.4.0. This would require an extra step if we keep our XML files unsorted and want to convert them on-the-fly to pbfs.
But honestly I am not entirely sold on the idea that we even need to remove the XML support yet. Can you explain why exactly this would be beneficial?
Better maintainability and simpler code would be the biggest arguments for this. And the fact that pbfs are the de facto standard format for OSM data (at least for any larger datasets)
OSMReader already requires that nodes come before ways and like I said sure we can sort the few files that do not follow the other rule (ids ordered by their absolute values and negative ids before positive ids) if this is really required.
Better maintainability and simpler code would be the biggest arguments for this.
Ok I am just wondering if its more maintainable if we need the pre-processing step instead of what we are doing right now. Where can we simplify our current code if we remove xml support?
I'd strongly favor Osmosis as it would be very easy to integrate into our unittests. My first idea was to replace all XML paths with calls to a converter utility:
FastXmlReader requires the OSM files to contain timestamps (and some more attributes) that we currently do not have in these files. But using XmlReader they are not required. XmlReader is also the one that is used from the command line tool with the --read-xml option.
OSMReaderTest loads the OSM files via the classpath currently while GraphHopperTest loads them via the file system. This must be addressed.
I tried this here: 883ae3c and its working for osm.xml files in both OSMReaderTest and GraphHopperTest. The converter is still missing support for the .osm.gz files, but that shouldn't be too hard because the osmosis CLI tool can handle these as well. Another problem was that the conversion seems to add/change some of the timestamps. Maybe we are just missing some option to suppress this, not sure.
However, I am still wondering if this approach is really improving things. Sure we get rid of some XML handling in our reader, but at the same time we are adding the code that does the same via the osmosis dependencies. Not sure I think either way is fine for me.
Activity
easbar commentedon Jan 5, 2021
I had a closer look at this and to my surprise the 'v0.5/6' API definition is not very strict at all. First of all I could not find a definite resource about the exact specification of v0.6. Osmosis, osmium-tool and JOSM all claim to 'require' v0.6, but what exactly does this even mean? The wiki has this page: https://wiki.openstreetmap.org/wiki/API_v0.6/DTD, but it says 'N.B.: This schema is incomplete!'.
So I tried opening test-osm.xml with the different tools and the result was:
version="1"to all nodes and ways it complaint about missing timestamps. But when I used theenableDateParsing=nooption it accepted the file. I was also able to use the--migrateoption with osmosis 0.35.1 in combination with--read-xml-0.5which is supposed to migrate to v0.6 and apparently simply adds the current timestamp,user=""andversion="1".Strangely, the version attribute required by JOSM and osmosis is listed as 'implied'(=optional) in above linked DTD, so this does not seem very helpful.
Conclusion: Simply adding some "version" attribute to all nodes,ways,relations makes our files compatible with the latest versions of osmosis, osmium and JOSM and I do not think there is a reason to do anything beyond this for now.
otbutz commentedon Jan 5, 2021
We should also sort our XML files. I ran into a few problems when trying to convert unsorted XMLs into pbfs as this yielded unsorted pbfs which are not supported by a few tools.
easbar commentedon Jan 5, 2021
Sort such that nodes come before ways and ways before relations? Which ones are not sorted like this already?
otbutz commentedon Jan 5, 2021
From the Osmium manual:
I think it was limited to only 2 or 3 test files
easbar commentedon Jan 5, 2021
Is this the format osmium expects or the output format of osmium's sort command? And what are we trying to achieve here? In case we want to remove xml support we need a pre-processing step that converts xml to pbf right? How do you think should this be done? Osmosis might be easier to integrate because its Java. Osmium would require an extra installation step. If we decide to use Osmium of course we can sort the 2 or 3 unsorted test files.
But honestly I am not entirely sold on the idea that we even need to remove the XML support yet. Can you explain why exactly this would be beneficial?
otbutz commentedon Jan 5, 2021
Most tools nowadays require pbfs to be sorted like e.g osm2pgsql 1.4.0. This would require an extra step if we keep our XML files unsorted and want to convert them on-the-fly to pbfs.
Better maintainability and simpler code would be the biggest arguments for this. And the fact that pbfs are the de facto standard format for OSM data (at least for any larger datasets)
easbar commentedon Jan 5, 2021
OSMReader already requires that nodes come before ways and like I said sure we can sort the few files that do not follow the other rule (ids ordered by their absolute values and negative ids before positive ids) if this is really required.
Ok I am just wondering if its more maintainable if we need the pre-processing step instead of what we are doing right now. Where can we simplify our current code if we remove xml support?
otbutz commentedon Jan 5, 2021
The OSMInputFile currently needs to deal with both formats and could be trimmed down significantly if we drop XML support:
master vs my branch
easbar commentedon Jan 5, 2021
Ok and would you use Osmosis or Osmium for the conversion? Osmosis seems easier to use as we could simply pull it in via maven with test scope?
otbutz commentedon Jan 5, 2021
I'd strongly favor Osmosis as it would be very easy to integrate into our unittests. My first idea was to replace all XML paths with calls to a converter utility:
If we generate the resulting pbfs files within
targetand avoid recreating them(timestamp check?) we should be fine.easbar commentedon Jan 5, 2021
Yes that seems like a good approach. Did you try this yet? I can try if you haven't already.
otbutz commentedon Jan 5, 2021
The class i used for my tests:
otbutz commentedon Jan 5, 2021
We could add a check based on
Files.getLastModifiedTime()to avoid converting the files on each test run but i'm not sure if it's worth the hassle.easbar commentedon Jan 5, 2021
Ok thanks!
Not worth the hassle if you ask me. Unless the conversion is really slow, but I do not think so.
easbar commentedon Jan 5, 2021
Two more things:
FastXmlReaderrequires the OSM files to contain timestamps (and some more attributes) that we currently do not have in these files. But usingXmlReaderthey are not required.XmlReaderis also the one that is used from the command line tool with the--read-xmloption.OSMReaderTestloads the OSM files via the classpath currently whileGraphHopperTestloads them via the file system. This must be addressed.I tried this here: 883ae3c and its working for osm.xml files in both OSMReaderTest and GraphHopperTest. The converter is still missing support for the .osm.gz files, but that shouldn't be too hard because the osmosis CLI tool can handle these as well. Another problem was that the conversion seems to add/change some of the timestamps. Maybe we are just missing some option to suppress this, not sure.
However, I am still wondering if this approach is really improving things. Sure we get rid of some XML handling in our reader, but at the same time we are adding the code that does the same via the osmosis dependencies. Not sure I think either way is fine for me.