User:Kuratkoo/Skript Veřejná hromadná doprava v ČR

From OpenStreetMap Wiki
Jump to: navigation, search

Generovaní stránky Veřejná_hromadná_doprava_v_ČR

Pustíme skript ids.sh:

 sh ids.sh

Použité skripty:

ids.sh

  #!/bin/sh
  wget -q http://download.geofabrik.de/osm/europe/czech_republic.osm.bz2
  bunzip2 czech_republic.osm.bz2
  osmosis -q --read-xml czech_republic.osm --tag-filter accept-relations route=tram,bus,train,subway,trolleybus --tag-filter reject-ways --tag-filter reject-nodes --write-xml ids.osm
  xsltproc xsl.xsl ids.osm | awk -f relan.awk > output.txt
  

xsl.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!-- Global template -->
	<xsl:template match="/osm">
		<xsl:text>== Linky v ČR ==
</xsl:text>
		<xsl:apply-templates select="relation[(tag/@v = 'tram' or tag/@v = 'train' or tag/@v = 'bus' or tag/@v = 'trolleybus' or tag/@v = 'subway') and tag[@k = 'network']]" mode="all">
			<xsl:sort select="tag[@k='network']/@v" data-type="text" order="ascending"/>
		</xsl:apply-templates>
		<xsl:text>
=== Ostatní ===
</xsl:text>
		<xsl:apply-templates select="relation[not(tag[@k = 'network']/@v)]" mode="network">
			<xsl:with-param name="network" />
			<xsl:sort select="tag[@k='operator']/@v" data-type="text" order="ascending"/>
		</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="relation" mode="all">
		<xsl:if test="current()[not(tag[@k = 'network']/@v = preceding-sibling::relation/tag[@k = 'network']/@v)]/tag[@k = 'network']/@v">
			<xsl:text>
=== </xsl:text><xsl:value-of select="tag[@k = 'network']/@v" /><xsl:text> ===
</xsl:text>
			<xsl:variable name='network' select="tag[@k = 'network']/@v" />

			<xsl:apply-templates select="../relation[tag[@k = 'network']/@v = $network]" mode="network">
				<xsl:with-param name="network"><xsl:value-of select="tag[@k = 'network']/@v" /></xsl:with-param>
				<xsl:sort select="tag[@k='operator']/@v" data-type="text" order="ascending"/>
			</xsl:apply-templates>

		</xsl:if>
	</xsl:template>

	<xsl:template match="relation" mode="network">
		<xsl:param name="network" />
		<xsl:if test="current()[not(tag[@k = 'operator']/@v = preceding-sibling::relation/tag[@k = 'operator']/@v)]/tag[@k = 'operator']/@v">
			<xsl:text>==== </xsl:text><xsl:value-of select="tag[@k = 'operator']/@v" /><xsl:text> ====
</xsl:text>
			<xsl:variable name='operator' select="tag[@k = 'operator']/@v" />
			<xsl:apply-templates select="../relation[tag[@k = 'operator']/@v = $operator]" mode="operator">
				<xsl:with-param name="network"><xsl:value-of select="$network" /></xsl:with-param>
				<xsl:with-param name="operator"><xsl:value-of select="$operator" /></xsl:with-param>
				<xsl:sort select="tag[@k='route']/@v" data-type="text" order="ascending"/>
			</xsl:apply-templates>
		</xsl:if>
	</xsl:template>

	<xsl:template match="relation" mode="operator">
		<xsl:param name="network" />
		<xsl:param name="operator" />
		<xsl:if test="current()[not(tag[@k = 'route']/@v = preceding-sibling::relation[tag[@k = 'operator']/@v = $operator]/tag[@k = 'route']/@v)]">
			<xsl:choose>
				<xsl:when test="tag[@k = 'route']/@v = 'bus'">
					<xsl:text>===== Autobusy =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'train'">
					<xsl:text>===== Vlaky =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'tram'">
					<xsl:text>===== Tramvaje =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'trolleybus'">
					<xsl:text>===== Trolejbusy =====
</xsl:text>
				</xsl:when>
				<xsl:when test="tag[@k = 'route']/@v = 'subway'">
					<xsl:text>===== Metro =====
</xsl:text>
				</xsl:when>
			</xsl:choose>

			<xsl:text>{| class="wikitable sortable" style="width: auto; text-align: center; font-size: smaller; table-layout: fixed;"
|-
! Linka
! Relace
! Síť
! Dopravce
! Verze
! Délka [km]
! Segmentů
! Kompletní
</xsl:text>
			<xsl:variable name='route' select="tag[@k = 'route']/@v" />
			<xsl:apply-templates select="../relation[tag[@k = 'operator']/@v = $operator and tag[@k = 'route']/@v = $route]" mode='route'>
				<xsl:with-param name='operator'><xsl:value-of select="$operator" /></xsl:with-param>
				<xsl:with-param name='route'><xsl:value-of select="tag[@k = 'route']/@v" /></xsl:with-param>
				<xsl:sort select="tag[@k='ref']/@v" data-type="number" order="ascending"/>
			</xsl:apply-templates>
			<xsl:text>|}
</xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template match='relation' mode='route'>
<xsl:text>|-
| </xsl:text><xsl:value-of select="tag[@k = 'ref']/@v" /><xsl:text>
| {{Relation|</xsl:text><xsl:value-of select="@id" /><xsl:text>}}
| </xsl:text><xsl:value-of select="tag[@k = 'network']/@v" /><xsl:text>
| </xsl:text><xsl:value-of select="tag[@k = 'operator']/@v" /><xsl:text>
| </xsl:text><xsl:value-of select="@version" /><xsl:text>
| $Length$ </xsl:text><xsl:value-of select="@id" /><xsl:text>
| $Segments$ </xsl:text><xsl:value-of select="@id" /><xsl:text>
| </xsl:text>
	<xsl:choose>
		<xsl:when test="tag[@k = 'complete']/@v= 'yes'">ano</xsl:when>
		<xsl:when test="tag[@k = 'complete']/@v = 'no'">ne</xsl:when>
	</xsl:choose><xsl:text>
</xsl:text>
	</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
}
/^[^$]*$/