On Thu, 3 Sep 2020 at 00:06, C Hamilton <[email protected]> wrote:
>
> Nyall,
>
> Thanks. This almost gets the right answer. 
> QgsSymbolLayerUtils::estimateMaxSymbolBleed is returning 0 as its value.  I'm 
> not sure what the problem is with it. bounds() seems to work for small 
> symbols which is probably all I'll need, but if the symbol is very large with 
> a large border and join style set to miter, the bounding box it returns is a 
> little too small. My example used an excessively large icon and large border 
> which probably would not be used in any real project.

Hm - not sure what your issue with estimateMaxSymbolBleed is. Are you
using data defined properties at all?

Regarding the miter question -- that's something which none of the
symbol bounds checking functions currently available account for.

Nyall

>
> Calvin
>
> On Tue, Sep 1, 2020 at 6:39 PM Nyall Dawson <[email protected]> wrote:
>>
>> On Wed, 2 Sep 2020 at 03:39, C Hamilton <[email protected]> wrote:
>> >
>> > I am trying to calculate the size of a single symbol in pixels using:
>> >
>> > canvas = iface.mapCanvas()
>> > context = QgsRenderContext.fromMapSettings(canvas.mapSettings())
>> > layer = iface.activeLayer()
>> > rnd = layer.renderer()
>> > sym = rnd.symbol()
>> > scaled_size_in_pixels = context.convertToPainterUnits(
>> >     sym.size(),
>> >     sym.sizeUnit(),
>> >     sym.sizeMapUnitScale() )
>> >
>> > The last line can also be calculated by:
>> >
>> >   scaled_size_in_pixels = sym.size(context)
>> >
>> > I am finding that this is returning the size of the filled area of the 
>> > symbol, but it does not include the border. Is this a bug or do I need to 
>> > add something additional to include the border?
>>
>> You can use  QgsSymbolLayerUtils::estimateMaxSymbolBleed if you're
>> wanting to calculate the "maximum" bounding box of a rendered symbol.
>> That includes any stroke/offset/other settings which also affect the
>> rendered bounds.
>>
>> There's also QgsMarkerSymbol::bounds which returns an approximate
>> bounding box of a marker symbol, which also accounts for things like
>> the stroke and offset.
>>
>> Nyall
>>
>>
>> >
>> > Thanks,
>> >
>> > Calvin
>> >
>> > _______________________________________________
>> > QGIS-Developer mailing list
>> > [email protected]
>> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to