[Marble-commits] KDE/kdeedu/marble/src

Thibaut Gridel tgridel at free.fr
Sun Jul 18 23:52:43 CEST 2010


SVN commit 1151350 by tgridel:

FileLoader: provide a PNT file loader so that GeoPainter could render those

This does not deprecate or change in any way the current PNT file loading
from DGML files, still using VectorComposer

 M  +2 -3      QtMainWindow.cpp  
 M  +59 -0     lib/FileLoader.cpp  
 M  +1 -0      lib/FileLoader.h  


--- trunk/KDE/kdeedu/marble/src/QtMainWindow.cpp #1151349:1151350
@@ -650,7 +650,7 @@
 {
     QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open File"),
                             QString(), 
-                            tr("All Supported Files (*.gpx *.kml);;GPS Data (*.gpx);;Google Earth KML (*.kml)"));
+                            tr("All Supported Files (*.gpx *.kml *.pnt);;GPS Data (*.gpx);;Google Earth KML (*.kml);; Micro World Database II (*.pnt)"));
 
     foreach( const QString &fileName, fileNames ) {
         QString extension = fileName.section( '.', -1 );
@@ -658,8 +658,7 @@
         if ( extension.compare( "gpx", Qt::CaseInsensitive ) == 0 ) {
             m_controlView->marbleWidget()->openGpxFile( fileName );
         }
-        else if ( extension.compare( "kml", Qt::CaseInsensitive )
-                  == 0 ) 
+        else
         {
             m_controlView->marbleWidget()->addPlacemarkFile( fileName );
         }
--- trunk/KDE/kdeedu/marble/src/lib/FileLoader.cpp #1151349:1151350
@@ -26,6 +26,9 @@
 namespace Marble
 {
 
+// distance of 180deg in arcminutes
+const qreal INT2RAD = M_PI / 10800.0;
+
 FileLoader::FileLoader( QObject* parent, const QString& file )
     : QThread( parent ),
       m_filepath( file ),
@@ -117,6 +120,10 @@
             }
         }
         else {
+            if( suffix.compare( "pnt", Qt::CaseInsensitive ) == 0 ) {
+                loadPntFile( m_filepath );
+            }
+            else {
 	    mDebug() << "No recent Default Placemark Cache File available!";
             if ( QFile::exists( defaultSourceName ) ) {
                 // Read the KML file.
@@ -130,6 +137,7 @@
                 mDebug() << "No Default Placemark Source File for " << name;
             }
         }
+        }
     } else {
         // Read the KML Data
         importKmlFromData();
@@ -315,5 +323,56 @@
     }
 }
 
+bool FileLoader::loadPntFile( const QString &fileName )
+{
+    QFile  file( fileName );
+
+    file.open( QIODevice::ReadOnly );
+    QDataStream stream( &file );  // read the data serialized from the file
+    stream.setByteOrder( QDataStream::LittleEndian );
+
+    m_document = new GeoDataDocument();
+    m_document->setFileName( fileName );
+
+    short  header;
+    short  iLat;
+    short  iLon;
+
+    GeoDataPlacemark  *placemark = 0;
+    placemark = new GeoDataPlacemark;
+    m_document->append( placemark );
+    GeoDataMultiGeometry *geom = new GeoDataMultiGeometry;
+    placemark->setGeometry( geom );
+
+    while( !stream.atEnd() ){
+        stream >> header >> iLat >> iLon;
+        // Transforming Range of Coordinates to iLat [0,ARCMINUTE] , iLon [0,2 * ARCMINUTE]
+
+        if ( header > 5 ) {
+
+            // qDebug(QString("header: %1 iLat: %2 iLon: %3").arg(header).arg(iLat).arg(iLon).toLatin1());
+
+            // Find out whether the Polyline is a river or a closed polygon
+            if ( ( header >= 7000 && header < 8000 )
+                || ( header >= 9000 && header < 20000 ) ) {
+                GeoDataLineString *polyline = new GeoDataLineString;
+                geom->append( polyline );
+            }
+            else {
+                GeoDataLinearRing *polyline = new GeoDataLinearRing;
+                geom->append( polyline );
+            }
+        }
+        GeoDataLineString *polyline = static_cast<GeoDataLineString*>(geom->child(geom->size()-1));
+        polyline->append( GeoDataCoordinates( (qreal)(iLon) * INT2RAD, (qreal)(iLat) * INT2RAD,
+                                                  0.0, GeoDataCoordinates::Radian, 5 ) );
+    }
+
+    file.close();
+
+    emit newGeoDataDocumentAdded( m_document );
+
+}
+
 #include "FileLoader.moc"
 } // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/FileLoader.h #1151349:1151350
@@ -38,6 +38,7 @@
         bool loadFile(const QString &filename );
         void saveFile(const QString& filename );
         void savePlacemarks(QDataStream &out, const GeoDataContainer *container);
+        bool loadPntFile( const QString &fileName );
 
         QString m_filepath;
         QString m_contents;


More information about the Marble-commits mailing list