Thanks for your answer. Now I can use correctly QgsCategorizedSymbolRenderer and show markers. Now I've another question. I would like put near each marker a label. I can do it in QGIS Desktop 3.26 in section Labels for my vector layer. Can you suggest a way to do this using qgsi api c++ (Qt 5.15.2 in ubuntu 20.04) Regards, Simone
Il 13/01/2024 12:03, Adam Nielsen ha scritto:
I created a vector layer and I can show correctly a georeferenced pdf
image.
Then I added another transparent layer  (vector layer) and I tried to
add markers in lat,long points.
Using QgsSimpleMarkerSymbolLayer I can inserted correctly all markers of
the same shape and color. Then I tried to add markers with different
shapes and colors on the same layers; using QgsSimpleMarkerSymbolLayer I
show only one kind of marker. Browsing on internet I found an example to
use QgsCategorizedSymbolRenderer. I tried to implement it in my code but
no markers shown. Can you suggest a correct way to do this?
You should try to do this through the normal QGIS GUI, then once you
have it working in the GUI you will have a better understanding of what
your code needs to achieve.

I haven't tried to do it in code, but:

def_symbol->symbolLayers()[0]->setColor(Qt::red);
def_symbol->symbolLayers()[0]->setColor(Qt::blue);
Here you're just changing settings on the same symbol, so you'll only
end up with one symbol.

QgsCategorizedSymbolRenderer*categorizedRenderer=newQgsCategorizedSymbolRenderer("Category");
QgsRendererCategorybsprxCategory("A",def_symbol->clone(),"RX",true);
categorizedRenderer->addCategory(bsprxCategory);

QgsRendererCategorybsptxCategory("B",def_symbol->clone(),"TX",true);
categorizedRenderer->addCategory(bsptxCategory);
Here you're saying when your Category field is "A", use the same symbol
as when your Category field is "B".  You'll have to assign different
symbols if you want them to appear differently.

I guess you want to call def_symbol->clone() first, then change the
colour on the clone, before assigning it to Category A or B.

Cheers,
Adam.

--

--
Questa email è stata esaminata alla ricerca di virus dal software antivirus 
Avast.
www.avast.com
_______________________________________________
QGIS-User mailing list
QGIS-User@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to