[OSM-dev] Segment-free OSM database and API

Ludwig Max Brinckmann ludwigbrinckmann at gmail.com
Sat Jan 6 14:40:11 GMT 2007


For those looking for a quick and dirty fix to the problem, I have hacked an
XSL file that will convert a OSM.xml file to another OSM.xml file where ways
with non-contiguous segments are broken up into a way per segment.

It can be used to pre-process an OSM xml file to remove jumbled ways without
affecting processing steps that come after as the xml structure does not
change and all attributes are retained.

I have used the windows sabcmd XSLT processor for it, e.g.

sabcmd.exe fixosm.xsl inputosm.xml outputosm.xml

Other XSLT processors should work similarly.

I agree that the issue should be fixed in the db itself, but setting up
another db will create huge maintenance problems in the future: what happens
if people start committing changes to the both dbs, old and fixed? How will
you sync the data? A cleaner way would be to set up a 'view' that would only
show contiguous segments.

Ludwig



The file fixosm.xsl

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>

<xsl:template match="text()"/>

<xsl:template match="osm"><osm><xsl:apply-templates
select="way|segment|node"/></osm></xsl:template>

<xsl:key name="node" match="/osm/node" use="@id"/>
<xsl:key name="segment" match="/osm/segment" use="@id"/>

<xsl:template match="segment|node">
<xsl:copy-of select="."/>
</xsl:template>

<xsl:template name="splitway">
<xsl:param name="way"/>
<xsl:for-each select="seg">
<way id="{../@id}">
<seg id="{@id}"/>
<xsl:for-each select="../tag">
<xsl:copy-of select="."/>
</xsl:for-each>
</way>
</xsl:for-each>
</xsl:template>

<xsl:template match="way">
<xsl:variable name="splitifnotempty">
<xsl:for-each select="seg">
<xsl:if test="position() != last()">
<xsl:variable name="thissegment" select="key('segment', at id)"/>
<xsl:variable name="next" select="position()+1"/>
<xsl:variable name="nextsegment" select="key('segment',../seg[$next]/@id)"/>
<xsl:variable name="tolon" select="key('node',$thissegment/@to)/@lon"/>
<xsl:variable name="tolat" select="key('node',$thissegment/@to)/@lat"/>
<xsl:variable name="fromlon" select="key('node',$nextsegment/@from)/@lon"/>
<xsl:variable name="fromlat" select="key('node',$nextsegment/@from)/@lat"/>
<!-- breaking ways with more than 28 segments for cgpsmapper routing -->
<xsl:if test="$tolon != $fromlon or $tolat != $fromlat or $next > 28 ">
<!--xsl:if test="$tolon != $fromlon or $tolat != $fromlat"-->
<xsl:value-of select="../@id"/>fail
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$splitifnotempty=''">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="splitway">
<xsl:with-param name="way" select="."/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20070106/35e66a55/attachment.html>


More information about the dev mailing list