1

I have data from open street maps in the format:

</way>
<way id="148531879">
    <nd ref="1616241466"/>
    <nd ref="1616241469"/>
    <nd ref="1616241471"/>
    <nd ref="1616241472"/>
    <nd ref="1616241475"/>
    <nd ref="1616241479"/>
    <nd ref="276928691"/>
    <tag k="highway" v="secondary"/>
    <tag k="lit" v="no"/>
    <tag k="oneway" v="yes"/>
    <tag k="ref" v="L 292"/>
</way>
<way id="10870759">
    <nd ref="96594201"/>
    <nd ref="96594205"/>
    <nd ref="96594209"/>
    <nd ref="96594224"/>
    <tag k="highway" v="residential"/>
    <tag k="maxspeed" v="50"/>
    <tag k="name" v="Rockwellstraße"/>
    <tag k="oneway" v="yes"/>
    <tag k="postal_code" v="38518"/>
</way>
<way id="10522831">
    <nd ref="90664716"/>
    <nd ref="940615687"/>
    <nd ref="2222543788"/>
    <nd ref="940619729"/>
    <nd ref="90664692"/>
    <nd ref="939024170"/>
    <nd ref="298997463"/>
    <tag k="highway" v="residential"/>
    <tag k="name" v="Am Allerkanal"/>
    <tag k="postal_code" v="38518"/>
    <tag k="tracktype" v="grade2"/>
</way>

A single file contains 1000s of similar way ids. I want to store these way ids in a list/tuple, but the problem is that the content in a way id is not fixed.

For example the number of 'nd ref' enteries can be different. I was thinking of storing the way id data into a tuple, and also include a list in each tuple containing nd ref data. Then finally storing all the tuples in a single list. Please suggest whether it is feasible, and will I be able to access all the enteries through looping?

1 Answer 1

2

Assuming the way id's have only 2 kind of tags, in this case and , if you want to organize the output in a datastructure, storing the way ids and their content in a list, you could do something like:

For every way id, you could define a tuple of the form

 t = (way_id,[list of nd ref tags],[list of tag k values])

So you will have a tuple for each way id and you could append this tuples into a list as you go. The idea of using a tuple is better because the data is organized better and you can refer to the content of tuples very easily:

t[0] -> gives you the way-id
t[1] -> gives you the list of nd-ref values for that id and so on.

Tuples are immutable data structures, in the sense that once you have defined a tuple(let's say its named 't'). You can not change the contents of the tuple like:

t[0] = 34983948 /*Invalid*/

However tuples can contain mutable elements like lists. The official python documentation on lists and tuples might also come in handy.

Sign up to request clarification or add additional context in comments.

1 Comment

thnx vivek, I will try this approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.