[Qgis-user] Fail to show markers in a vector layer

Adam Nielsen a.nielsen at shikadi.net
Sat Jan 13 03:03:48 PST 2024


> 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.


More information about the QGIS-User mailing list