is it possible programmatically to rotate a svg of the feature without rotate all fea

المشرف العام

Administrator
طاقم الإدارة
I am working on a project that need to move and update the shape of the feature of the layer.

I am working in c++/ QT4.8.5 and qgis api c++ 2.8.2.In my Layer I have a lot of features, each feature has a specific svg file corresponding to the value of the attribute of the feature like the color, the length and the angle

In my program, at the begining all the feature has an initial position, with the same caracteristic color=black, length=small, angle=0When I start my simulator that generate random data and save them into the first feature, all of my feature rotate of the value of the angle of the first feature

I have 3 functionsthe first add a point to the layerthe second update the data of the layerand the last update the feature with color, size and rotation

here is an extract of my code ( too long to post it full )the 3 function

void MainWindow::addTracks() { QgsVectorLayer * lLayer = mMapLayer.value(TRACKS); QgsVectorDataProvider * lDataProvider = lLayer->dataProvider(); double lposX =(qrand()%(Xmax-Xmin)+Xmin); double lposY =(qrand()%(Ymin-Ymax)+Ymax); // init cap aleatoire double lCapqrand()%(360); // init vitesse aleatoire double lVitesse= qrand()%(30); // init classification int lClassif= qrand()%(5); QColor lColor; switch(lClassif) { case 1: lColor=QColor("green"); break; case 2: lColor=QColor("blue"); break; case 3: lColor=QColor("orange"); break; case 4: lColor=QColor("red"); default: lColor=QColor("black"); } if (lVitesse < 10) lClassif=lClassif+10; else if (lVitesse addFeatures(myFeatureList); lLayer->updateExtents(); // Increment de l'Id mId=mId+1; // Add the Vector Layer to the Layer Registry QgsMapLayerRegistry::instance()->addMapLayer(lLayer, TRUE); // Add the Layer to the Layer Set QgsMapCanvasLayer PointMapCanvasLayer = QgsMapCanvasLayer(lLayer, TRUE); mpS57->myListForPrint.insert(1,PointMapCanvasLayer); // set the canvas to the extent of our layer mpMapCanvas->setExtent(lLayer->extent()); // Set the Map Canvas Layer Set mpMapCanvas->setLayerSet(mpS57->myListForPrint); mpS57->UpdateTrack(lLayer); // zoom full canvas mpMapCanvas->zoomToFullExtent(); mpMapCanvas->refresh(); mpMapCanvas->updateMap(); mpMapCanvas->updateFullExtent(); } void MainWindow::moveTracks(int pTrackId) { QgsVectorLayer * lLayer = mMapLayer.value(TRACKS); lLayer->startEditing(); QgsVectorDataProvider * lDataProvider; lDataProvider = lLayer->dataProvider(); //calc new random X and Y double posX =(qrand()%(Xmax-Xmin)+Xmin); double posY =(qrand()%(Ymin-Ymax)+Ymax); // init vitesse aleatoire double lVitesse = qrand()%(30); // couleur QString lColor="black"; // init classification int lClassif= qrand()%(5); // init cap aleatoire double lCap= qrand()%(360); //create point QgsGeometry *myPoint; myPoint=QgsGeometry::fromPoint(QgsPoint(posX,posY)); myPoint->rotate(lCap,QgsPoint(posX,posY)); QgsGeometryMap MyGeometryMap; //get the feature of the specify Id QgsFeatureIterator myFeatIter; myFeatIter = lDataProvider->getFeatures(); QgsFeature myFeature; QgsFeatureId myFeatureId; // search the feature for the id while ( myFeatIter.nextFeature(myFeature)) { qDebug()changeAttributeValues(MyChangedAttributesMap); // save all change lLayer->commitChanges(); mpS57->createTrackIco(myFeature,myFeatureId,true); // update the track mpS57->UpdateTrack2(lLayer,myFeature);}void CMyQgsS57::UpdateTrack2(QgsVectorLayer* pLayer,QgsFeature pFeature){ QgsFeatureRendererV2 * lRenderer = pLayer->rendererV2(); QgsSymbolV2 * lNewSymbol = lRenderer->symbolForFeature(pFeature); QgsStringMap MyTrackDefault; QString MyFeatureId; MyFeatureId = QString::number(pFeature.attribute(0).toInt()); QString lTrackIcoDefault = "../data/Icones/iconeS52/track_"+MyFeatureId+ EXT_ICONE; // list of property for the boystyle QStringList MyTrackPropertyName; MyTrackPropertyName
 
أعلى