3

I have a little problem with the rendering of SVG for layer symbol. I want to creeate a categorized symbol to show different style of buoy I have for that two icons the first is an half circle filled, and the second is a triangle filled, both are yellow, no rotate, same size. So I define the property of the symbol as descibe in the qgis cookbook page 149 here is my Code in C++ to do that

QgsStringMap MyBoyStyle,MyBoyStyle2;
QString lBoyIcoType1 = "../data/Icones/iconeS52/" + pNameCouche+QString("_")+"RVER1"+ EXT_ICONE;//attention au path icone "../data/Icones/iconeS52/" au lieu de PATH_ICONE
QString lBoyIcoType2 = "../data/Icones/iconeS52/" + pNameCouche+QString("_")+"RVER2"+ EXT_ICONE;//attention au path icone "../data/Icones/iconeS52/" au lieu de PATH_ICONE

// list of property for the boystyle
QStringList MyBoyPropertyName;
MyBoyPropertyName << "fill" << "name" << "outline" << "outline-width" << "size";
// list of corresponding value 1
QStringList MyBoyPropertyValue;
MyBoyPropertyValue << "#f3e54d" << lBoyIcoType1 << "#000000" << "6.8" << "6";
QStringList MyBoyPropertyValue2;
MyBoyPropertyValue2 << "#f3e54d" << lBoyIcoType2 << "#000000" << "6.8" << "6";

// create the map 1 et 2
for (int i =0; i < MyBoyPropertyName.size(); i++){
    //1ere bouee
    MyBoyStyle.insert(MyBoyPropertyName.at(i),MyBoyPropertyValue.at(i));
    //2eme bouee
    MyBoyStyle2.insert(MyBoyPropertyName.at(i),MyBoyPropertyValue2.at(i));
}
// creation du svg marker layer
QgsSymbolLayerV2* MySymbolLayer1;
MySymbolLayer1 = QgsSvgMarkerSymbolLayerV2::create(MyBoyStyle);
QgsSymbolLayerV2* MySymbolLayer2;
MySymbolLayer2 = QgsSvgMarkerSymbolLayerV2::create(MyBoyStyle2);

QList <QgsSymbolLayerV2*> MyLayerList;
MyLayerList << MySymbolLayer1 << MySymbolLayer2;

then I create the categories :

QList<QgsRendererCategoryV2> Categories;
QStringList lListValue; lListValue << "1" << "2";
QStringList lListIcone; lListIcone << pNameCouche+QString("_")+"RVER1" << pNameCouche+QString("_")+"RVER2";

for(int i = 0 ; i < lListValue.size() ; i++){
    QgsSymbolV2* newsymbol = QgsSymbolV2::defaultSymbol(pLayer->geometryType() );
    newsymbol->appendSymbolLayer(MyLayerList[i]);
    //newsymbol->setColor(QColor("#f3e54d"));
    QgsRendererCategoryV2 MyCategorie = QgsRendererCategoryV2(QVariant( lListValue.at(i) ),newsymbol,PATH_ICONE+lListIcone.at(i)+EXT_ICONE);
    Categories.append(MyCategorie);
}
// for the rendering
lrenderer = new QgsCategorizedSymbolRendererV2("RVER",Categories);
pLayer->setRendererV2(lrenderer);

when I launch the application, the file s57 was loaded and the buoy are display good but for the second icon or symbol I have a superposition of shape i have the default symbollayer which is a circle in background of my symbollayer which is a triangle filled in yellow.

Any Idea ?

1 Answer 1

3

Here is the solution,I finally understand why In fact a defaultSymbol is been created when I instanciate newsymbol , so instead of do an appendSymbolLayer I had to delete the default symbolLayer first and insert the new one to replace it The code is now :

for(int i = 0 ; i < lListValue.size() ; i++) {
    QgsSymbolV2* newsymbol =    QgsSymbolV2::defaultSymbol(pLayer->geometryType() );
    //newsymbol->appendSymbolLayer(MyLayerList[i]); // old method
    newsymbol->deleteSymbolLayer(0);
    newsymbol->insertSymbolLayer(0,MyLayerList[i]);
    QgsRendererCategoryV2 MyCategorie = QgsRendererCategoryV2(QVariant( lListValue.at(i) ),newsymbol,PATH_ICONE+lListIcone.at(i)+EXT_ICONE);
    Categories.append(MyCategorie);
}

the rendering is compliant with what I expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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