[Scilab-users] Extracting numerical an text data from gmx files

Jens Simon Strom j.s.strom at hslmg.de
Tue May 23 15:35:00 CEST 2017


Hello Samuel,
Here comes a sucsessful result:

function [route,lat,lon,n]=gpx2scilab(gpxpath)
     //Extracting geographical coordinates and route point names from a gpx file
     //containing a route with routepoints as defined by the rte element
     //gpxpath: full path of the gpx file (string 1 x 1).
         //The first two lines of the file have to be
             //<?xml version="1.0"  encoding="UTF-8"  standalone="no"  ?>
             //<gpx ...>
          //The last line of the file has to be
             //</gpx>
      //route: All results compiled in a n x 4 string matrix
      //lat: Geographical latitude/°  (numerical row vector))
      //long: Geographical longitude/° (numerical row vector))
      //n: number of route points
      //gpx2scilab() requires Scilab Version 6.

     doc=xmlRead(gpxpath);
     Coo=getPreferencesValue("/gpx/rte/rtept", ["lat", "lon"],doc);//string matrix n x 2
      xp = xmlXPath(doc, "/gpx/rte/rtept/name");//XMLSet
      s = size(xp)
      Name=[]
      for i=1:s(2)
      	Name=[Name;xmlDump(xp(i))]
      end
      xmlDelete(doc)
      route=[Name Coo string(1:s(2))']
      lat=strtod(Coo(:,1))//double, °
      lon=strtod(Coo(:,2))//double, °
      n=length(lat)//number of route points
  endfunction

Thanks again for your help.

Regards, Jens
______________________________________________________________________________


Am 22.05.2017 08:19, schrieb Jens Simon Strom:
> Hello Samuel,
>
> I tried the script
> doc=xmlRead("G:/Daten/Navigation/gpxArchiv/testfile.gpx")
> recent =getPreferencesValue("/gpx/rte/body/rtept", ["lat","lon"],doc)
> xmlDelete(doc)
> The file is as below.
>
> The result is:
>  doc  =
> XML Document
> url: file:///G:/Daten/Navigation/gpxArchiv/testfile.gpx
> root: XML Element
>  !--error 10000
> getPreferencesValue: Invalid XPath request.
> at line      39 of function getPreferencesValue called by :
> recent = getPreferencesValue("/gpx/rte/rtept", ["lat","lon"],doc)
> at line      55 of exec file called by :
> exec('G:\Daten\Navigation\eTrex10_GPX_Generator.sce', -1)
>
> What am I doing wrong here?
> Regards, Jens
> -----------------------------------------------------------------------------
>
> Am 22.05.2017 01:31, schrieb Jens Simon Strom:
>> Great, I will try this soon.
>> Regards, Jens
>> --------------------------------------------------------------------------
>>
>> Am 22.05.2017 01:14, schrieb Samuel Gougeon:
>>> Hello,
>>>
>>> Le 22/05/2017 à 00:32, Jens Simon Strom a écrit :
>>>> Hi,
>>>> I want to extract lat, lon and <rte>-name from gmx files. See the 
>>>> following reduced example:
>>>> -----------------------------------------------------------------------------------------------------------------------------------------
>>>> <?xml version="1.0" encoding="UTF-8" standalone="no" ?><gpx 
>>>> xmlns="http://www.topografix.com/GPX/1/1" creator="MEDIA-TOURS" 
>>>> version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>>>> xsi:schemaLocation="http://www.topografix.com/GPX/1/1 
>>>> http://www.topografix.com/GPX/1/1/gpx.xsd">
>>>> <!--
>>>> line of comments
>>>> ...
>>>> line of comments
>>>>  -->
>>>> <rte>
>>>> <name>route_1</name>
>>>> <rtept lat="52.00424932154729" lon="8.875365257263184">
>>>> <name>1 Start</name>
>>>> </rtept>
>>>> <rtept lat="52.00319255643224" lon="8.878369331359863">
>>>> <name>11 station</name>
>>>> </rtept>
>>>> <rtept lat="52.00271700399025" lon="8.879871368408203">
>>>> <name>111 destination.</name>
>>>> </rtept>
>>>> </rte>
>>>> </gpx>
>>>> ------------------------------------------------------------------------------------------------------------------------------------
>>>> lat and lon  should be collected as numerical colum vectors, name 
>>>> as a colum of strings.
>>>>
>>>> Which commands would you recommend? Is reading by mgetl and 
>>>> retrieving by regexp recommendable?
>>>
>>> xmlXPath() is made for parsing xml documents and extracting selected 
>>> informations.
>>> getPreferencesValue() may also help. It is based on xmlXPath()
>>>
>>> HTH
>>> Samuel
>>>
>>>
>>>
>>> _______________________________________________
>>> users mailing list
>>> users at lists.scilab.org
>>> http://lists.scilab.org/mailman/listinfo/users
>>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170523/f2f04082/attachment.htm>


More information about the users mailing list