I am trying to get the speed limit of the surrounding locations of a specific coordinate.
OSM Query: www.overpass-api.de/api/xapi?*[maxspeed=*][bbox=5.6283473,50.5348043,5.6285261,50.534884]
Response:
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="Overpass API">
<note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
<meta osm_base="2015-06-09T07:04:02Z"/>
<node id="21265775" lat="50.5350159" lon="5.6293520"/>
<node id="21265776" lat="50.5346804" lon="5.6276238"/>
<node id="1312239857" lat="50.5347491" lon="5.6278274"/>
<node id="1312239864" lat="50.5348877" lon="5.6286790">
<tag k="highway" v="crossing"/>
<tag k="traffic_calming" v="table"/>
</node>
<node id="2025084669" lat="50.5353414" lon="5.6303289">
<tag k="highway" v="traffic_calming"/>
<tag k="traffic_calming" v="choker"/>
</node>
<node id="3362188585" lat="50.5345623" lon="5.6274183">
<tag k="highway" v="traffic_calming"/>
<tag k="traffic_calming" v="choker"/>
</node>
<way id="191950462">
<nd ref="2025084669"/>
<nd ref="21265775"/>
<nd ref="1312239864"/>
<nd ref="1312239857"/>
<nd ref="21265776"/>
<nd ref="3362188585"/>
<tag k="highway" v="secondary"/>
<tag k="maxspeed" v="30"/>
<tag k="name" v="Rue d'Esneux"/>
<tag k="source:maxspeed" v="school zone"/>
</way>
</osm>
This is in case of bounding box (bbox: I am guessing these are the corner coordinates or the API makes a box or polygon based on the provided coordinates). But the issue is, I have only one coordinate and another issue is, I see maxspeed = 30 in the response. But not sure what kind of code should I write to parse this response as the response format may change. I am using objective C platform to parse this response.
The format of the response is regular XML. For understanding it you should read about OSM's elements.
Your response contains one way and several nodes as well as their tags. But it could contain more than a single way when querying a different bounding box.
The way has a maxspeed tag in which you seem to be interested. The way geometry is defined by its nodes. The way referes six different nodes via <nd ref="<node ID>"/>. Each <node> has a unique ID and a coordinate specified via lat and lon. The way geometry is defined by the order in which it references its nodes, not the order in which the nodes appear in the response file! In your specific case, the way starts at the node with ID 2025084669 and ends at the node with ID 3362188585. Also keep in mind that a single way can refer the same node more than once (e.g. if it is a roundabout). And that a single node can be referenced by more than one way (e.g. if it is a junction).
Understanding these primitives might get easier for you if you create an OSM account and try one of the map editors.
Regarding JSON output: I suggest to get rid of the XAPI compatibility call and instead start using Overpass XML or Overpass QL which are much more powerful (see the language guide): raw data, query and data on overpass turbo. Note that the bounding box format here differes from the ordering in the XAPI syntax.
Related
I try to extract some text for creating a lemma in the back of a book and don't know how to grab the nodes:
Consider the following:
<anchor type='commentary' xml:id='A1'/>Romeo and Juliet<note type='commentary' xml:id='N1'>Some blabla</note> is a tragedy written by William Shakespeare
So with my XSLT i want to be able to access the text between anchor and note to write a lemma in the back of the book:
p. 1 Romeo and Juliet) Some blabla
The problem is that basically all other possible elements can occur between anchor and note so I can't just use text(). E.g. sometimes I have the element in between anchor and note:
<anchor type='commentary' xml:id='A1'/>Romeo <c rendition="ampersand"/> Juliet<note type='commentary' xml:id='N1'>Some blabla</note>
with the undesired result of 'Romeo Juliet' instead of 'Romeo & Juliet'
How can i copy the nodes between anchor and note to access it a second time?
Is there a possibility to delete all text lines using Ant in a text file that are after a specific keyword? - after the first occurrence of the keyword.
Example
Line1
Line2
Line3
Line4
Line5
.....
Line1000
I want to delete everything that is in that file that is after "Line3" keyword excluding that line.
Ant's replaceregexp task can handle this pretty easily:
<replaceregexp
file="input.txt"
match="(.*Line3).*"
replace="\1"
flags="s"
/>
Brief explanation: The regex pattern captures everything up to and including "Line3" in a group, then continues to match the rest of the input. The replacement consists of only the captured group, effectively deleting the part you don't want. The s flag is switched on so that newlines are matched with the . wildcard.
Here is a short version of my question.
When using a nested for-loop in a FLOWR expression returning the variable from the inner loop behaves as expected but returning the variable from the outer loop unexpectedly returns empty tags.
Here is a longer version of my question.
I have recently started learning XQuery. I've been using the XQilla command-line tool on Mac OS X 10.10.4 (Yosemite) to execute my XQuery scripts. In particular I've tried XQilla Version 2.3.0_2 which I installed with the MacPorts package manager and also XQilla version 2.3.2 which I manually installed from source.
While experimenting with various XPath and FLWOR expressions I came across an unexpected behavior which I've narrowed down to the simplified example which I am going to present here. The example consists of a single XML data file and two versions of a simple XQuery; the first query works as expected but the second query does not.
Here is my XML data file (test.xml):
<elements>
<element>
element data
</element>
</elements>
Here is my first XQuery script (test_1.xq):
for $e1 in doc("test.xml")//element
for $e2 in doc("test.xml")//element
return $e1
And here is my second XQuery script (test_2.xq):
for $e1 in doc("test.xml")//element
for $e2 in doc("test.xml")//element
return $e2
Both queries consist of the same redundant, nested for-loops, but the first query returns the variable from the outer (i.e. first) for-loop and the second query returns the variable from the inner (i.e. second) for-loop. I expected the two queries to have similar output in general, and identical output for this specific data file, however that appears not to be the case.
Here is a sample shell session:
$ xqilla test_1.xq
<element>
element data
</element>
$ xqilla test_2.xq
<element/>
So returning the variable from the outer loop only produces the empty tag; this was unexpected.
As a sanity-check I tried a third variation (test_3.xq):
for $e1 in doc("test.xml")//element
for $e2 in doc("test.xml")//element
where $e1=$e2
return $e2
And when I execute this third query I get:
$ xqilla test_3.xq
<element>
element data
</element>
I would have originally expected this query to work correctly, but in light of the unexpected behavior of test_2.xq I would think that test_3.xq would also fail. This only adds to my confusion.
Most probably a bug. An online XQuery tester http://www.xpathtester.com/xquery returns
<?xml version="1.0" encoding="UTF-8"?>
<element>
element data
</element>
as a result for both scripts (with the doc(...) part removed).
I am trying to concat multiple files (say 15 txt files) to a single file at the same time by separate ant calls.
Say there are 15 concat() run at the same time.
However, the output file was not expected.
The data in the output file is corrupted.
Does anyone have idea to solve this problem?
Example:
Input 1:
a=1
b=2
c=3
Input 2:
d=4
e=5
f=6
Output:
a=1
b=2
d=4
e
c=3=5
f=6
You can do this with the concat task, which take a resource collection such as `filesets' as nested elements, allowing you to concatenate all the files in a single task call. Example:
<concat destfile="${build.dir}/output.txt">
<fileset file="${src.dir}/input1.txt" />
<fileset file="${src.dir}/input2.txt" />
</concat>
Given this source document:
<things>
<thing><duck>Eider</duck></thing>
<thing><duck>Mallard</duck></thing>
<thing><duck>Muscovy</duck></thing>
</things>
I require the following output
Fat Eider, Fat Mallard, Fat Muscovy
which I can indeed get with this XSL transform:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of separator=", ">
<xsl:apply-templates select="//duck"/>
</xsl:value-of>
</xsl:template>
<xsl:template match="duck" as="xs:string">
<xsl:value-of select="concat('Fat ', .)"/>
</xsl:template>
</xsl:stylesheet>
However, I have three questions:
Question 1. (specific)
If I remove as="xs:string" from the duck template, I get the following output:
Fat EiderFat MallardFat Muscovy
Why? My understanding is that in XSLT 2.0 the result of xsl:apply-templates is always a sequence, and that xsl:value-of inserts its separator between the items in the sequence. So why does the sequence seem to "collapse" when the template has no as attribute? Bonus points for pointing me towards appropriate pages of Michael Kay's excellent "XSLT 2.0 and XPath 2.0, 4th Edition" book.
Question 2. (vague!)
As a novice user of XSLT, it seems to me that there are probably many ways to solve this problem. Can you put forward a good solution that takes a different approach? How do you choose between approaches?
Question 3.
Debugging. Can you recommend how to dump out intermediate results that would indicate the difference between the presence and the absence of the as attribute to the template?
See http://www.w3.org/TR/xslt20/#value-of which says
The string value of the new text node may be defined either by using
the select attribute, or by the sequence constructor (see 5.7 Sequence
Constructors) that forms the content of the xsl:value-of element.
These are mutually exclusive, and one of them must be present. The way
in which the value is constructed is specified in 5.7.2 Constructing
Simple Content.
So we need to look at http://www.w3.org/TR/xslt20/#constructing-simple-content and that says "2. Adjacent text nodes in the sequence are merged into a single text node.". So that is what is happening without the as="xs:string", the sequence constructor inside the xsl:value-of creates adjacent text nodes which are merged into a single text node. If you have as="xs:string" or did <xsl:sequence select="concat('Fat ', .)"/> the sequence constructor is of a sequence of primitive string values.