[Marble-devel] Review Request: Added support for writing the ExtendedData of Documents and Folders to kml files.

Thibaut Gridel tgridel at free.fr
Sat Sep 10 14:53:54 UTC 2011


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/102538/#review6381
-----------------------------------------------------------

Ship it!


Looks good!
Do you have a kde account, or should we commit for you?

- Thibaut


On Sept. 6, 2011, 12:59 p.m., Javier Becerra Elcinto wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/102538/
> -----------------------------------------------------------
> 
> (Updated Sept. 6, 2011, 12:59 p.m.)
> 
> 
> Review request for Marble.
> 
> 
> Summary
> -------
> 
> According to KML 2.2 specification all features (which includes Documents and Folders) can have ExtendedData, but KmlDocumentTagWriter.cpp and KmlFolderTagWriter.cpp did not handle it. 
> The patch adds support for writing the ExtendedData of Documents and Folders to kml files using a GeoWriter object.
> 
> 
> Diffs
> -----
> 
>   src/lib/geodata/writers/kml/KmlDocumentTagWriter.cpp aab4c3e 
>   src/lib/geodata/writers/kml/KmlFolderTagWriter.cpp 561a294 
> 
> Diff: http://git.reviewboard.kde.org/r/102538/diff
> 
> 
> Testing
> -------
> 
> Checked generation of kml file (mydocument.kml) with ExtendedData in <Document> and <Folder>. File "main.cpp" and generated "mydocument.kml" attached below.
> 
> /////////
> Main.cpp
> /////////
> 
> //Marble
> #include "GeoDataDocument.h"
> #include "GeoDataFolder.h"
> #include "GeoDataPlacemark.h"
> #include "GeoDataExtendedData.h"
> #include "GeoDataData.h"
> #include "GeoWriter.h"
> #include "GeoDataStyle.h"
> #include "GeoDataPoint.h"
> 
> //Qt
> #include <QtGui/QApplication>
> #include <QDebug>
> #include <QTextCodec>
> #include <QFile>
> #include <QDir>
> 
> 
> void writeKML(Marble::GeoDataDocument *doc)
> {
>     Marble::GeoWriter writer;
>     writer.setDocumentType("http://earth.google.com/kml/2.2" );
> 
>     QFile file( doc->fileName());
>     if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
>     {
>         qDebug() << "Can not open file" << file.fileName();
> 
>     }
>     else
>     {
>         if ( !writer.write( &file, doc ) ) {
>             qDebug() << "Can not write to " << file.fileName();
>         }
>         qDebug()<<QString("File %1 written OK").arg(file.fileName());
>         file.close();
>     }
> }
> 
> 
> int main(int argc, char** argv)
> {
>     QApplication app(argc,argv);
> 
> 
>     QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
>     QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
> 
>     //Creating a GeoDataDocument from scratch:
> 
>     Marble::GeoDataDocument *mydoc=new Marble::GeoDataDocument();
>     mydoc->setFileName("mydocument.kml"); //Will identify the document internally, must be unique
>     mydoc->setName("My_GeoDataDocument"); //Name for visualisation in MarbleWidget
> 
>     //Extended data for the document
>     Marble::GeoDataExtendedData *ed_d=new Marble::GeoDataExtendedData;
>     Marble::GeoDataData *dd_d=new Marble::GeoDataData;
>     QString v_d("Value (GeoDataDocument)");
>     dd_d->setDisplayName("Display name (GeoDataDocument)");
>     dd_d->setName("Name (GeoDataDocument)");
>     dd_d->setValue(v_d);
> 
>     ed_d->addValue(*dd_d);
>     mydoc->setExtendedData(*ed_d);
> 
>     Marble::GeoDataFolder *myfolder=new Marble::GeoDataFolder;
>     myfolder->setName("My first folder"); //(setName from base class GeoDataFeature, inherited from GeoDataContainer)
> 
>     Marble::GeoDataPlacemark *myplacemark=new Marble::GeoDataPlacemark;
>     myplacemark->setName("A placemark in a folder");
>     myplacemark->setCoordinate( -2.45, 42.465278,0,Marble::GeoDataPoint::Degree);
> 
> 
>     //We create three GeoDataExtendedData, one attached to the Placemark, one to the Folder and
>     //one to the document
> 
>     Marble::GeoDataExtendedData *ed_p=new Marble::GeoDataExtendedData;
>     Marble::GeoDataData *dd_p=new Marble::GeoDataData;
>     QString v_p("Value (GeoDataPlacemark)");
>     dd_p->setDisplayName("Display name (GeoDataPlacemark)");
>     dd_p->setName("Name (GeoDataPlacemark)");
>     dd_p->setValue(v_p);
>     ed_p->addValue(*dd_p);
>     myplacemark->setExtendedData(*ed_p);
> 
>     myfolder->append(myplacemark);
> 
>     Marble::GeoDataExtendedData *ed_f=new Marble::GeoDataExtendedData;
>     Marble::GeoDataData *dd_f=new Marble::GeoDataData;
>     QString v_f("Value (GeoDataFolder)");
>     dd_f->setDisplayName("Display name (GeoDataFolder)");
>     dd_f->setName("Name (GeoDataFolder)");
>     dd_f->setValue(v_f);
>     ed_f->addValue(*dd_f);
>     myfolder->setExtendedData(*ed_f);
> 
>     mydoc->append(myfolder);
> 
>     //Check that the GeoData* structures contain the extendeddata elements:
>     qDebug()<<"ExtendedData in GeoDataDocument:"<<mydoc->extendedData().size();
>     qDebug()<<"ExtendedData in GeoDataFolder:"<<myfolder->extendedData().size();
>     qDebug()<<"ExtendedData in GeoDataPlacemark:"<<myplacemark->extendedData().size();
> 
>     ///Write the file to disk
>     writeKML(mydoc);
> 
>     while(app.hasPendingEvents())
>         app.processEvents();
> 
>     return 0;
> }
> 
> 
> /////////
> Generated file mydocument.kml
> /////////
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.2">
>     <Document>
>         <name>My_GeoDataDocument</name>
>         <Folder>
>             <name>My first folder</name>
>             <ExtendedData>
>                 <Data name="Name (GeoDataFolder)" displayName="Display name (GeoDataFolder)">
>                     <value>Value (GeoDataFolder)</value>
>                 </Data>
>             </ExtendedData>
>             <Placemark>
>                 <name>A placemark in a folder</name>
>                 <ExtendedData>
>                     <Data name="Name (GeoDataPlacemark)" displayName="Display name (GeoDataPlacemark)">
>                         <value>Value (GeoDataPlacemark)</value>
>                     </Data>
>                 </ExtendedData>
>                 <Point>
>                     <coordinates>-2.4500000000,42.4652780000</coordinates>
>                 </Point>
>             </Placemark>
>         </Folder>
>         <ExtendedData>
>             <Data name="Name (GeoDataDocument)" displayName="Display name (GeoDataDocument)">
>                 <value>Value (GeoDataDocument)</value>
>             </Data>
>         </ExtendedData>
>     </Document>
> </kml>
> 
> 
> Thanks,
> 
> Javier
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/marble-devel/attachments/20110910/067031aa/attachment.html>


More information about the Marble-devel mailing list