1

I am trying to use the SVGmarker symbol for displaying the point vector layer. I was able to change the default symbol for the point vector layer. but I am not getting an idea of using the SVGmarker symbol in place of the default symbol. I am using QGIS3 C++ APIs.Even any lead in python will be beneficial. for example :

path for SVGmarker symbol:"C:\OSGeo4W64\apps\qgis-ltr-dev\svg\food\food_bar.svg"

code snipped for changing vector layer symbol:

    layer->startEditing();
    qDebug()<< "is editable " << layer->isEditable();
    QgsFeatureRenderer * layerRenderer= layer->renderer();
    QgsSingleSymbolRenderer *mSingleRenderer = QgsSingleSymbolRenderer::convertFromRenderer(layerRenderer);
    QgsMarkerSymbol* symbol = new  QgsMarkerSymbol();
    QgsStringMap mp;
    mp[QString("fill")]= QString("red");
    mp[QString("name")]= QString("food_bar.svg");
    mp[QString("size")]= QString("6");
    mp[QString("outline")]=QString("black");
    mp[QString("outline-width")]=QString("6.8");
    auto svgsymbol = QgsSvgMarkerSymbolLayer::create(mp);
    auto newsym=     symbol->createSimple(mp);
    mSingleRenderer->setSymbol(newsym);
    layer->setRenderer(mSingleRenderer);
    layer->triggerRepaint();
    layer->commitChanges();
    qDebug()<< "is editable after commiting  " << layer->isEditable();

In the above code, I am not able to provide a path of food_bar.svg icon. color and size are getting changed. but the icon is not coming.

1 Answer 1

1

I solved my problem. Here is the code snipped

        layer->startEditing();
        qDebug()<< "is editable " << layer->isEditable();
        QgsFeatureRenderer * layerRenderer= layer->renderer();
        QgsSingleSymbolRenderer *mSingleRenderer = QgsSingleSymbolRenderer::convertFromRenderer(layerRenderer);
        QgsMarkerSymbol* symbol = new  QgsMarkerSymbol();
        QgsStringMap mp;
       // mp[QString("fill")]= QString("red");
        mp[QString("name")]= QString("food_pub.svg");
        mp[QString("size")]= QString("6");
      //  mp[QString("outline")]=QString("black");
     //   mp[QString("outline-width")]=QString("6.8");

        QgsSvgMarkerSymbolLayer svglayer("C:\\OSGeo4W64\\apps\\qgis-ltr-dev\\svg\\food\\food_pub.svg");
        QgsSymbolLayer* svgsymbol=svglayer.create(mp);
       auto newsym=     symbol->createSimple(mp);
       newsym->changeSymbolLayer(0,svgsymbol);
       mSingleRenderer->setSymbol(newsym);
        layer->setRenderer(mSingleRenderer);
        layer->triggerRepaint();
        layer->commitChanges();
        qDebug()<< "is editable after commiting  " << layer->isEditable();

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.