This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Creating live GPS trace from lat/long datapoints

Tags: None
(comma "," separated)
carlsondavid
Registered Member
Posts
6
Karma
0
I am trying to create a live trace by plotting incoming lat/long GPS datapoints in marble. I have managed to achieve the functionality I am looking for, but the program randomly crashes with an access violation. After looking around it seems to me like some kind of conflict in the redrawing of the map or ui. I included my current implementation below and was hoping someone might have a better implementation method that avoids this issue. I was unable to add geodataplacemarks to the geodatadocument without removing it from the active widget, then readding it, so I am assuming there is a better way to do this.

Code: Select all
GeoDataPlacemark *dataPoint = new GeoDataPlacemark();
dataPoint->setCoordinate(tLong, tLat, tAlt, GeoDataCoordinates::Degree);
int geoDocumentSize = document->size();

  if (geoDocumentSize < 100) {
    mapWidget->model()->treeModel()->removeDocument(document);
    ui->document->append(dataPoint);
    mapWidget->model()->treeModel()->addDocument(document);
}
  else if (geoDocumentSize >= 100) {
    mapWidget->model()->treeModel()->removeDocument(document);
    ui->document->removeFirst();
    ui->document->append(dataPoint);
    mapWidget->model()->treeModel()->addDocument(document);
}


My next thought is to create a set number of geodataplacemarks in my geodatadocument with coordinates initially set outside the viewing area, then using updateFeature() from the treemodel to properly update each placemark as new points come in. This still feels convoluted though and I am hoping there is a simpler way of doing this that I just don't know about.
carlsondavid
Registered Member
Posts
6
Karma
0
Am I wasting my time posting on this board? It seems like there aren't any replies to any of the recent topics. Is there a better place to ask questions like these?
carlsondavid
Registered Member
Posts
6
Karma
0
Since it seems there aren't many contributors to this forum, I did find a solution to my problem.

It turns out there is a higher level functionality built into marble to create these gps point traces, and it's called GeoDataLineString. It stores a set of GeoDataCoordinates and is applied as geometry to a GeoDataPlacemark object.

Its usage is as follows:

Code: Select all
//Create a gps datapoint (mine pulls data each iteration of the program when new data comes in from the sensor)
GeoDataCoordinates dataPoint(Long, Lat, Alt, GeoDataCoordinates::Degree);   

//Create linestring and add datapoint to it
route = new GeoDataLineString;     
route->append(dataPoint);

//Create placemark and use linestring to assign its geometry (will error out if only one datapoint exists, need at least 2 to draw a line)
routePlacemark = new GeoDataPlacemark;   
routePlacemark->setGeometry(route);

//Add line styling if you desire
GeoDataLineStyle routeLine(QColor(Qt::red));
routeLine.setWidth(4);
QSharedPointer<GeoDataStyle> style(new GeoDataStyle);
style->setLineStyle(routeLine)
routePlacemark->setStyle(style);

//Add your placemark to a geodatadocument and add document to your marble widget
document = new GeoDataDocument;
document->append(routePlacemark);
mapWidget->model()->treeModel()->addDocument(document);


Making the route update is as easy as creating a new data point, appending it to the linestring, then updating the feature in the treemodel.
Code: Select all
GeoDataCoordinates dataPoint(Long, Lat, Alt, GeoDataCoordinates::Degree);    //New datapoint
route->append(dataPoint);
mapWidget->model()->treeModel()->updateFeature(routePlacemark);


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]