needs more cowbell
Join Date: Feb 2008
Location: ÿ
Posts: 5,038
Thanks: 158
Thanked 269 Times in 212 Posts
|
I'm glad to see the interest in things computer, but perl is not the best choice for xml schema handling, or arguably much else. Here is a python example of reading gpx and making csv files out of them.
Python and XML -- by Mike Hostetler ,
The program is trivial in python (this is the whole thing, I just use php tags cuz it looks pretty, it is python), worked as-is for me:
PHP Code:
import cElementTree as ET import string
if __name__ == '__main__':
mainNS=string.Template("{http://www.topografix.com/GPX/1/0}$tag")
wptTag=mainNS.substitute(tag="wpt") nameTag=mainNS.substitute(tag="name")
et=ET.parse(open("everything.gpx"))
for wpt in et.findall("//"+wptTag): wptinfo=[] wptinfo.append(wpt.get("lat")) wptinfo.append(wpt.get("lon")) wptinfo.append(wpt.findtext(nameTag))
print ",".join(wptinfo)
and here was the output ( after I saved http://www.topografix.com/fells_loop.gpx to everything.gpx )
Code:
42.438878,-71.119277,5066
42.439227,-71.119689,5067
42.438917,-71.116146,5096
42.443904,-71.122044,5142
42.447298,-71.121447,5156
42.454873,-71.125094,5224
42.459079,-71.124988,5229
42.456979,-71.124474,5237
42.454401,-71.120990,5254
42.451442,-71.121746,5258
42.454404,-71.120660,5264
42.457761,-71.121045,526708
42.457089,-71.120313,526750
42.456592,-71.119676,527614
42.456252,-71.119356,527631
42.458148,-71.119135,5278
42.459377,-71.117693,5289
42.464183,-71.119828,5374FIRE
42.465650,-71.119399,5376
42.439018,-71.114456,6006
42.438594,-71.114803,6006BLUE
42.436757,-71.113223,6014MEADOW
42.441754,-71.113220,6029
42.436243,-71.109075,6053
42.439250,-71.107500,6066
42.439764,-71.107582,6067
42.434766,-71.105874,6071
42.433304,-71.106599,6073
42.437338,-71.104772,6084
42.442196,-71.110975,6130
42.442981,-71.111441,6131
42.444773,-71.108882,6153
42.443592,-71.106301,6171
42.447804,-71.106624,6176
42.448448,-71.106158,6177
42.453415,-71.106783,6272
42.453434,-71.107253,6272
42.458298,-71.106771,6278
42.451430,-71.105413,6280
42.453845,-71.105206,6283
42.459986,-71.106170,6289
42.457616,-71.105116,6297
42.467110,-71.113574,6328
42.464202,-71.109863,6354
42.466459,-71.110067,635722
42.466557,-71.109410,635783
42.463495,-71.107117,6373
42.401051,-71.110241,6634
42.432621,-71.106532,6979
42.431033,-71.107883,6997
42.465687,-71.107360,BEAR HILL
42.430950,-71.107628,BELLEVUE
42.438666,-71.114079,6016
42.456469,-71.124651,5236BRIDGE
42.465759,-71.119815,5376BRIDGE
42.442993,-71.105878,6181CROSS
42.435472,-71.109664,6042CROSS
42.458516,-71.103646,DARKHOLLPO
42.443109,-71.112675,6121DEAD
42.449866,-71.119298,5179DEAD
42.459629,-71.116524,5299DEAD
42.465485,-71.119148,5376DEAD
42.462776,-71.109986,6353DEAD
42.446793,-71.108784,6155DEAD
42.451204,-71.126602,GATE14
42.458499,-71.122078,GATE16
42.459376,-71.119238,GATE17
42.466353,-71.119240,GATE19
42.468655,-71.107697,GATE21
42.456718,-71.102973,GATE24
42.430847,-71.107690,GATE5
42.431240,-71.109236,GATE6
42.439502,-71.106556,6077LOGS
42.449765,-71.122320,5148NANEPA
42.457388,-71.119845,5267OBSTAC
42.434980,-71.109942,PANTHRCAVE
42.453256,-71.121211,5252PURPLE
42.457734,-71.117481,5287WATER
42.459278,-71.124574,5239ROAD
42.458782,-71.118991,5278ROAD
42.439993,-71.120925,5058ROAD
42.453415,-71.106782,SHEEPFOLD
42.455956,-71.107483,SOAPBOX
42.465913,-71.119328,5376STREAM
42.445359,-71.122845,5144SUMMIT
42.441727,-71.121676,5150TANK
__________________
WINDMILLS DO NOT WORK THAT WAY!!!
Last edited by dcb; 07-13-2009 at 01:23 AM..
|