Is it possible to change the geometry without startEditing the layer

المشرف العام

Administrator
طاقم الإدارة
I am working in c++/QT 4.5 with the qgis 2.8.2 api.I had to change the geometry of features in a layer each second.Each second new data comes from the Ethernet connection, the application get the data and call a function with parameters.

It look like a real time tracker.It works only if i put lLayer->startEditing and lLayer->commitChanges but it was too slow.

Here is my code (just an extract. Complete code is too long for the post.)

QgsVectorLayer * lLayer = mMapLayer.value(TRACKS);lLayer->startEditing();QgsVectorDataProvider * lDataProvider;lDataProvider = lLayer->dataProvider();//calc new random X and YPosX =(qrand()%(Xmax-Xmin)+Xmin);PosY =(qrand()%(Ymin-Ymax)+Ymax);//create pointQgsGeometry *MyPoint;MyPoint=QgsGeometry::fromPoint(QgsPoint(PosX,PosY));QgsGeometryMap MyGeometryMap;//get the feature of the specify IdQgsFeatureIterator MyFeatIter;MyFeatIter = lDataProvider->getFeatures();QgsFeature MyFeature;QgsFeatureId MyFeatureId;while ( MyFeatIter.nextFeature(MyFeature)) { if (pTrackId == MyFeature.attribute("TrackId")) { MyFeatureId=MyFeature.id(); MyFeature.setGeometry(*MyPoint); MyFeature.setAttribute(Longitude,PosY); MyFeature.setAttribute(Latitude,PosX); }}MyGeometryMap.insert(MyFeatureId,*MyPoint);bool lResult;lResult=lDataProvider->changeGeometryValues(MyGeometryMap);lLayer->commitChanges();With the starEditing and commitChanges, it works, but very slow.Without the startEditing and commitChanges, the coordinate seems to be modified, but on the layer the feature don't move anyway.



أكثر...
 
أعلى