Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   como crear un archivo gpx con delphi 7 (https://www.clubdelphi.com/foros/showthread.php?t=72615)

Luis Cuenca 02-03-2011 00:21:42

como crear un archivo gpx con delphi 7
 
Hola a todos, necesito crear un archivo gpx con delphi, estoy usando el componente txmldocument, y tengo el siguiente codigo, pero cuando lo trato de abrir con un programa para archivos gpx me dice que mi archivo no es gpx.

Ojala que me puedan ayudar, llevo varios dias y no encuentro la forma:

Código Delphi [-]
begin
// empty the document
XMLDoc.Active := False;
XMLDoc.XML.Text := '';
XMLDoc.Active := True;
// root
iXml := XmlDoc.DOMDocument;
xmlNode := iXml.appendChild (iXml.createElement ('xml'));
iAttribute := iXml.createAttribute ('version');
iAttribute.nodeValue := '1.0';
xmlNode.attributes.setNamedItem (iAttribute);
//GPX
gpxNode := xmlNode.appendChild(iXml.createElement ('gpx'));
iAttribute := iXml.createAttribute ('xmlns');
iAttribute.nodeValue := 'http.....';
gpxNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('version');
iAttribute.nodeValue := '1.1';
gpxNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('creator');
iAttribute.nodeValue := 'http.....';
gpxNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('xmlns:xsi');
iAttribute.nodeValue := 'http.....';
gpxNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('xsi:schemaLocation');
iAttribute.nodeValue := 'http.....';
gpxNode.attributes.setNamedItem (iAttribute);
mNode := xmlNode.appendChild(iXml.createElement ('metadata'));
 
bNode := mNode.appendChild(iXml.createElement ('bounds'));
 
iAttribute := iXml.createAttribute ('minlat');
iAttribute.nodeValue := '19.38975200';
bNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('minlon');
iAttribute.nodeValue := '-99.17971000';
bNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('maxlat');
iAttribute.nodeValue := '19.39671900';
bNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('maxlon');
iAttribute.nodeValue := '-99.17543500';
bNode.attributes.setNamedItem (iAttribute);
 
trksegNode := xmlNode.appendChild(iXml.createElement ('wpt'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trksegNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trksegNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trksegNode.attributes.setNamedItem (iAttribute);
trksegNode := xmlNode.appendChild(iXml.createElement ('wpt'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.38975200';
trksegNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17543500';
trksegNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'SUPERAMA';
trksegNode.attributes.setNamedItem (iAttribute);
trksegNode := xmlNode.appendChild(iXml.createElement ('wpt'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39119400';
trksegNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17971000';
trksegNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'CUMULUS1';
trksegNode.attributes.setNamedItem (iAttribute);
 
trkptNode := xmlNode.appendChild (iXml.createElement ('rte'));
trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trkNode.attributes.setNamedItem (iAttribute);
trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.38975200';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17543500';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'SUPERAMA';
trkNode.attributes.setNamedItem (iAttribute);
trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39119400';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17971000';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'CUMULUS1';
trkNode.attributes.setNamedItem (iAttribute);
trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));
iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trkNode.attributes.setNamedItem (iAttribute);
iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trkNode.attributes.setNamedItem (iAttribute);
// show XML in memo
Memo1.Lines.Text := FormatXMLData (XMLDoc.XML.Text);
XMLDoc.SaveToFile('C:\Users\j\Desktop\borrar\codigo2.gpx');
 
end;

Neftali [Germán.Estévez] 02-03-2011 09:59:48

Hola Luis.
Un archivo GPX no es más que un XML con determinada estructura.

En mi caso, lo que he hecho es importar un fichero GPX hasta un Dataset, pero el paso contrario es igual de sencillo.
Para ello he utilizado el XML Mapper de Delphi.
Puedes revisar el proceso competo y descargar el código en esta entrada:
Cargar fichero GPX (XML) y acceder a los datos

Creo que no debe ser muy complejo, a partir de eso, generar el paso contrario.


La franja horaria es GMT +2. Ahora son las 18:37:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi