workflow/tool to extract data from xml..?

Discuss or share your track-related work here

Moderator: kilo

workflow/tool to extract data from xml..?

Postby simon-2 » Wed Feb 11, 2015 2:52 pm

Hello,

does anyone know a good tool or has written anything to get segment data from xml to tabular (cvs for example)? i want to create a height profile for a track; therefore i want to perform some table calculations (lenght of each segment and some smoothing). Would be nice to get something like this:

Code: Select all
segment name;type;lg;arc;radius;end radius;...
Straight 1;str;12;;;;...
Straight 2;str;20;;;;...
Curve 1;lft;;30;80;60;...
Straight 3;str;40;;;;...
Curve 2;rgt;;90;50;;...


i once made this manually for another track, but it was shorter than the one i'm currently working on and the "critical part" was only a part of the track (nevertheless it was a boring task). Now i have much more track segments and I'm too lazy to typewrite everything...
best would be to automatically write the resulting colums back into the xml file, to the according track segment...

i tried some online xml to cvs converters, but they are all overstrained by track-xml files...
simon-2
 
Posts: 90
Joined: Thu Jan 29, 2015 3:01 pm

Re: workflow/tool to extract data from xml..?

Postby MiniJoe » Wed Feb 11, 2015 4:16 pm

I am working on something similar for my trackdesigner. Should not be too hard to add "export to csv" function. Do you need info for the sides/curbs/barriers ?
MiniJoe
 
Posts: 100
Joined: Fri Mar 16, 2012 1:32 am

Re: workflow/tool to extract data from xml..?

Postby simon-2 » Wed Feb 11, 2015 5:16 pm

you are working on a new trackdesigner :o ? very cool. this java trackeditor is a nice tool indeed, but it has some issues being really annoying, and as it is not continued, these will never be corrected...

i don't need other info than lenght (as for curves, this is only implicit, arc and start/end-radius are needed). But as unused columns can easily be deleted (or just remain unused), it might be wise to export z values, profil tangents (and/or grade) and banking as well, as they could also be useful... but i don't think, side/curb/barrier will be needed..?

But maybe you could also implement this height-stuff directly;
tangent creation (or smoothing):
set profil end tangent to the average of current and subsequent segment's grade (personally, i don't use grade, but it can be calculated from length and z values)

z end modification (for short segments only; so it might be better to do this for single segments than for a whole track):
set z end so that current and subsequent segment have the same grade

another idea is to fit a track to a given heightmap; i tried it myself and i think it should not be a big thing for experienced programmers, as nessecary functions are already available (GetElevation in elevation.cpp for heightmap processing and something inside track4.cpp to get x and y of segments) , but it's a difficulty for me to cope with such large object oriented projects, so i failed :oops:
simon-2
 
Posts: 90
Joined: Thu Jan 29, 2015 3:01 pm

Re: workflow/tool to extract data from xml..?

Postby simon-2 » Wed Feb 11, 2015 7:47 pm

did this:

Code: Select all
#!/usr/bin/python

from xml.dom.minidom import parse
import xml.dom.minidom

# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("Track.xml")
file = DOMTree.documentElement
sections = file.getElementsByTagName("section")
print "name; typeStr; lg; arc; rad; endRad;"
for section in sections:
   if section.getAttribute("name") == "Main Track":
      innersections = section.getElementsByTagName("section")
      for innersection in innersections:
        if innersection.getAttribute("name") == "Track Segments":
          trackSegments = innersection.getElementsByTagName("section")
          for segment in trackSegments:
            name = segment.getAttribute("name")
            typeStr = ""
            lg = ""
            arc = ""
            rad = ""
            endRad = ""           
            numAtts = segment.getElementsByTagName("attnum")
            strAtts = segment.getElementsByTagName("attstr")
            for att in numAtts:
                attName = att.getAttribute("name")
                if attName == "lg":
                    lg = att.getAttribute("val")
                elif attName == "arc":
                    arc = att.getAttribute("val")
                elif attName == "radius":
                    rad = att.getAttribute("val")
                elif attName == "end radius":
                    endRad = att.getAttribute("val")
            for att in strAtts:
                if att.getAttribute("name") == "type":
                    typeStr = att.getAttribute("val")
            print "%s; %s; %s; %s; %s; %s;" % (name, typeStr, lg, arc, rad, endRad)       


it is a bit silly, as getElementsByTagName works recursively, so it produces output like this:
Code: Select all
curve 75; lft; ; 63.0; 267.0; 50.0;
Left Side; ; ; ; ; ;
Left Border; ; ; ; ; ;
Left Barrier; ; ; ; ; ;
Right Side; ; ; ; ; ;
Right Border; ; ; ; ; ;
Right Barrier; ; ; ; ; ;
curve 76; rgt; ; 51.0; 124.0; 63.0;
Left Side; ; ; ; ; ;
Left Border; ; ; ; ; ;
Left Barrier; ; ; ; ; ;
Right Side; ; ; ; ; ;
...


but it's ok to do the task (additional lines are easy to replace with nothing in any text editor)
simon-2
 
Posts: 90
Joined: Thu Jan 29, 2015 3:01 pm

Re: workflow/tool to extract data from xml..?

Postby MiniJoe » Wed Feb 11, 2015 10:26 pm

Just don't call print if the name starts with "Left" or "Right".
Are you using an existing track xml or is this a brand new track?
One thing to look out for: measurements don't have to be in meters or degrees. I have not seen it in a track xml yet, but the code that reads the files supports radians and kilometers, etc. (I think even feet and miles). You are likely to see some elevation as absolute meters AND some as grade percentage in the same track.xml
MiniJoe
 
Posts: 100
Joined: Fri Mar 16, 2012 1:32 am

Re: workflow/tool to extract data from xml..?

Postby simon-2 » Thu Feb 12, 2015 12:35 am

it is derived from Nordschleife, but i completely reworked alignment to fit google's satellite image, so you could call it a brand new track...

one thing makes me really dizzy; when compiling the track with trackgen, it says 20944m length (this is ok; original is 20832 which is about half a percent). But if i calculate it with openoffice from the cvs, it says 22454m!?
For the straights, there is nothing to calculate, for curves i used (radius+endRadius)/2*arc (in radians, of course), as i thought speed dreams would do so as well (as in track4.cpp)!?
i checked if something with the python script could be wrong; e.g. takes values from one of the inner sections, but there are no attributes with the same name in sides/borders...
i did not check the whole file, but according to spot checks, the cvs has the same content as the xml.

there are no feet, yards, cm or whatever in the file, and the angles give 360° when cumulated (negative for left segments), although you are right, this could be an issue. But it is just a quick'n'dirty solution..
simon-2
 
Posts: 90
Joined: Thu Jan 29, 2015 3:01 pm

Re: workflow/tool to extract data from xml..?

Postby MiniJoe » Thu Feb 12, 2015 2:49 am

But if i calculate it with openoffice from the cvs, it says 22454m!?

That's quite a difference!
for curves i used (radius+endRadius)/2*arc (in radians, of course),

That should be right (or very close, depending on profil steps)

Maybe openoffice is doing something strange with the negative arcs? Going the long way round? ie: using 357 degrees instead of -3 degrees. Try ABS of degrees, then convert to radians.

Sorry if none of this helps, this is a strange one!
MiniJoe
 
Posts: 100
Joined: Fri Mar 16, 2012 1:32 am

Re: workflow/tool to extract data from xml..?

Postby simon-2 » Thu Feb 12, 2015 12:32 pm

nope, for length calculation, i used the arcs as positive, just for angle check i made them negative.
simon-2
 
Posts: 90
Joined: Thu Jan 29, 2015 3:01 pm


Return to SD Tracks

Who is online

Users browsing this forum: No registered users and 1 guest

cron