1

I am working in c++/python/QT 4.5 with the api qgis 2.8.2

My application receive data from a communication port that indicate the change of position of an object diplayed on the map and represented by a svg ( an arrow ) the data received contains new position x and y and the rotation in degree

I want to rotate the symbol with the value received, if value equal 0 there is no rotation, if the value is 30 then rotate the symbol of 30 deg clockwise

I don't know how to do that, may be some of you had already work on that kind of point and share their procedure

1

In qgis api 2.8.2, i found a simple way to do that but it correspond to my application perhaps this inspire you to find another way

in fact for each point or track i create a vectorlayer and i change the value of the vectorlayer angle

QStringList MyTargetPropertyName;
MyTargetPropertyName << "fill" << "name" << "outline" << "outline-width" << "size" << "angle";
QStringList MyTargetPropertyValue1;
MyTargetPropertyValue1 << "#f3e54d" << lTargetIcoType1 << "#000000" << "6.8" << "6" << lAngle;

for (int i = 0; i < MyTargetPropertyName.size(); i++)
    MyTargetStyle1.insert(MyTargetPropertyName.at(i),MyTargetPropertyValue1.at(i));
MySymbolLayer1 = QgsSvgMarkerSymbolLayerV2::create(MyTargetStyle1);
QList<QgsSymbolLayerV2*> MyLayerList;
MyLayerList << MySymbolLayer1;
QgsSymbolV2* newsymbol = QgsSymbolV2::defaultSymbol(
            pLayer->geometryType());
newsymbol->deleteSymbolLayer(0);
newsymbol->insertSymbolLayer(0, MyLayerList[0]);

this is just an extract but the essential of the code is here.

1

I am looking for a code snippet which does the question above described, as I need to rotate each symbol the value provided azimuth field at the attribute table.

At the QGIS python Cookbook there is a reference, which mentions the way to print the angle().

for i in xrange(symbol.symbolLayerCount()):
    lyr = symbol.symbolLayer(i)
    print "%d: %s" % (i, lyr.layerType())

This could be done to obtain the angle: lyr.angle(), but this does not rotate the symbol.

In that same chapter, you can find this section Creating Custom Symbol Layer Types which describes a process that Im sure could be used for this purpose. When I execute QgsSymbolLayerV2Registry.instance().addSymbolLayerType(FooSymbolLayerMetadata()), however I get this error: Traceback (most recent call last): File "", line 1, in File "C:/Users/EGARFEL/Desktop/Optimi Documents/atmMobilis/qgisScript.py", line 76, in QgsSymbolLayerV2Registry.instance().addSymbolLayerType(FooSymbolLayerMetadata())

 File "C:/Users/EGARFEL/Desktop/Optimi Documents/atmMobilis/qgisScript.py", line 58, in __init__
    QgsSymbolLayerV2AbstractMetadata.__init__(self, "FooMarker", QgsSymbolV2.Marker)
TypeError: arguments did not match any overloaded call:
  QgsSymbolLayerV2AbstractMetadata(QString, QString, QgsSymbolV2.SymbolType): argument 2 has unexpected type 'SymbolType'
  QgsSymbolLayerV2AbstractMetadata(QgsSymbolLayerV2AbstractMetadata): argument 1 has unexpected type 'str'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.