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

Simone Melis simone.melis at leonardo-si.it
Tue Jan 16 09:48:15 PST 2024


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20240116/9fe55484/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FirmaPosta_MelisSimone.jpg
Type: image/jpeg
Size: 19509 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20240116/9fe55484/attachment-0001.jpg>


More information about the QGIS-User mailing list