Talk:Brněnské cyklotrasy

From OpenStreetMap Wiki
Jump to navigation Jump to search
wget "http://www.overpass-api.de/api/interpreter?data=(rel[operator~BrnoNaKole];>;);out meta; " -O bnk.osm
java -Xmx700M -classpath /usr/share/java/saxonb.jar net.sf.saxon.Transform bnk.osm bicycle2wiki.xsl | awk -f relan.awk > bnk_wiki.txt

bicycle2wiki.xsl

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" indent="no"/>

<xsl:template match="/osm">
	<xsl:text>! colspan="6" align="center" | Cyklotrasy 1. třídy

|-
! číslo
! jméno
! relace
! network
! počet členů
! kompletní?

</xsl:text>

	<xsl:apply-templates select="relation[matches(tag[@k = 'ref']/@v, '^[0-9]{1}[^0-9]*$')]">
		<xsl:sort select="tag[@k='ref']/@v" />
	</xsl:apply-templates>
	<xsl:text>|-
! colspan="6" align="center" | Cyklotrasy 2. třídy

</xsl:text>

	<xsl:apply-templates select="relation[matches(tag[@k = 'ref']/@v, '^[0-9]{2}[^0-9]*$')]">
		<xsl:sort select="tag[@k='ref']/@v" />
	</xsl:apply-templates>
	<xsl:text>|-
! colspan="6" align="center" | Cyklotrasy 3. třídy

</xsl:text>
	<xsl:apply-templates select="relation[matches(tag[@k = 'ref']/@v, '^[0-9]{3}[^0-9]*$')]">
		<xsl:sort select="tag[@k='ref']/@v" />
	</xsl:apply-templates>
	<xsl:text>|-
! colspan="6" align="center" | Cyklotrasy 4. třídy

</xsl:text>
	<xsl:apply-templates select="relation[matches(tag[@k = 'ref']/@v, '^[0-9]{4}[^0-9]*$')]">
		<xsl:sort select="tag[@k='ref']/@v" />
	</xsl:apply-templates>

	<xsl:text>|-
! colspan="6" align="center" | Cyklotrasy bez ref

</xsl:text>
	<xsl:apply-templates select="relation[matches(tag[@k = 'ref']/@v, '^[^0-9]')]">
		<xsl:sort select="tag[@k='ref']/@v" />
	</xsl:apply-templates>
	<xsl:apply-templates select="relation[not(tag/@k = 'ref')]">
		<xsl:sort select="tag/@id" data-type="number"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="relation[tag/@v = 'bicycle']">
		<xsl:text>|-
</xsl:text>

		<xsl:text>|  </xsl:text>
		<xsl:value-of select="tag[@k = 'ref']/@v"/>
		<xsl:text>
</xsl:text>

		<xsl:text>| </xsl:text>
		<xsl:value-of select="tag[@k = 'name']/@v"/>
		<xsl:text>
</xsl:text>

		<xsl:text>| {{Relation|</xsl:text>
		<xsl:value-of select="@id"/>
		<xsl:text>}}
</xsl:text>

		<xsl:text>| </xsl:text>
		<xsl:value-of select="tag[@k = 'network']/@v"/>
		<xsl:text>
</xsl:text>

		<xsl:text>| </xsl:text>
		<xsl:value-of select="count(member)"/>
		<xsl:text>
</xsl:text>
		
		<xsl:text>| </xsl:text>
		<xsl:value-of select="tag[@k = 'complete']/@v"/>
		<xsl:text>
</xsl:text>

		<!--
		<xsl:text>| </xsl:text>
		<xsl:value-of select="tag[@k = 'description']/@v"/>
		<xsl:text>
</xsl:text>

		<xsl:text>| </xsl:text>
		<xsl:value-of select="tag[@k = 'source']/@v"/>
		<xsl:text>
</xsl:text>

		<xsl:text>| </xsl:text>
		<xsl:value-of select="tag[@k = 'note']/@v"/>
		<xsl:text>
</xsl:text>
		-->

		<xsl:text>
</xsl:text>
</xsl:template>

<xsl:template match="*">
</xsl:template>

</xsl:stylesheet>

relan.awk

#!/usr/bin/env awk -f
/\$Length\$/ { 
	system("wget 'http://betaplace.emaitie.de/webapps.relation-analyzer/analyze.jsp?relationId="$3"' -q -O temp.html") 

  	t = "cat temp.html | grep 'Relation length ca.:' | sed 's/.*<b>\\(.*\\) KM<\\/b>/\\1/'" 
  	s = "cat temp.html | grep 'Unconnected segments:' | sed 's/.*<b>\\(.*\\)<\\/b>/\\1/'" 

   a = "0"
   b = "1"

	t | getline a
	s | getline b
	close(t)
	close(s)
	print "| "a
	print "| "b
}
/^[^$]*$/