Skip to main content
deleted 114 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.

To resolve~

How would one implement a text-size based on MapUnits?

    field = str(csvGridFieldNames[index])
    csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
    textSize = 7
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fieldName = field
    valLabel.placement= QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

This question appears related, but having some trouble understanding the doc's...

"...lables 'Data Defined' section in pyqgis"

...and FWIW:

A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green: lable settings

Updates following underdark's advice:

Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...

    valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')

LAST UPDATE [SOLVED] This forums pool of wisdom is awesome. Final thanks to underdark for setting things off right in short. Cheers, (final working code below):

    textSize = (abs(scale[0]-scale[1]))/4
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fontSizeInMapUnits = True
    valLabel.fieldName = field
    valLabel.placement = QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.

To resolve~

How would one implement a text-size based on MapUnits?

    field = str(csvGridFieldNames[index])
    csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
    textSize = 7
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fieldName = field
    valLabel.placement= QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

This question appears related, but having some trouble understanding the doc's...

"...lables 'Data Defined' section in pyqgis"

...and FWIW:

A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green: lable settings

Updates following underdark's advice:

Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...

    valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')

LAST UPDATE [SOLVED] This forums pool of wisdom is awesome. Final thanks to underdark for setting things off right in short. Cheers, (final working code below):

    textSize = (abs(scale[0]-scale[1]))/4
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fontSizeInMapUnits = True
    valLabel.fieldName = field
    valLabel.placement = QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.

To resolve~

How would one implement a text-size based on MapUnits?

    field = str(csvGridFieldNames[index])
    csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
    textSize = 7
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fieldName = field
    valLabel.placement= QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

This question appears related, but having some trouble understanding the doc's...

"...lables 'Data Defined' section in pyqgis"

...and FWIW:

A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green: lable settings

Updates following underdark's advice:

Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...

    valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')

LAST UPDATE [SOLVED] (final working code below):

    textSize = (abs(scale[0]-scale[1]))/4
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fontSizeInMapUnits = True
    valLabel.fieldName = field
    valLabel.placement = QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.

To resolve~

How would one implement a text-size based on MapUnits?

    field = str(csvGridFieldNames[index])
    csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
    textSize = 7
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fieldName = field
    valLabel.placement= QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

This question appears related, but having some trouble understanding the doc's...

"...lables 'Data Defined' section in pyqgis""...lables 'Data Defined' section in pyqgis"

...and FWIW:

A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green: lable settings

Updates following underdark's advice:

Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...

    valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')

LAST UPDATE [SOLVED] This forums pool of wisdom is awesome. Final thanks to underdark for setting things off right in short. Cheers, (final working code below):

    textSize = (abs(scale[0]-scale[1]))/4
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fontSizeInMapUnits = True
    valLabel.fieldName = field
    valLabel.placement = QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.

To resolve~

How would one implement a text-size based on MapUnits?

    field = str(csvGridFieldNames[index])
    csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
    textSize = 7
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fieldName = field
    valLabel.placement= QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

This question appears related, but having some trouble understanding the doc's...

"...lables 'Data Defined' section in pyqgis"

...and FWIW:

A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green: lable settings

Updates following underdark's advice:

Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...

    valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')

LAST UPDATE [SOLVED] This forums pool of wisdom is awesome. Final thanks to underdark for setting things off right in short. Cheers, (final working code below):

    textSize = (abs(scale[0]-scale[1]))/4
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fontSizeInMapUnits = True
    valLabel.fieldName = field
    valLabel.placement = QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.

To resolve~

How would one implement a text-size based on MapUnits?

    field = str(csvGridFieldNames[index])
    csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
    textSize = 7
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fieldName = field
    valLabel.placement= QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()

This question appears related, but having some trouble understanding the doc's...

"...lables 'Data Defined' section in pyqgis"

...and FWIW:

A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green: lable settings

Updates following underdark's advice:

Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...

    valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')

LAST UPDATE [SOLVED] This forums pool of wisdom is awesome. Final thanks to underdark for setting things off right in short. Cheers, (final working code below):

    textSize = (abs(scale[0]-scale[1]))/4
    valLabel = QgsPalLayerSettings()
    valLabel.readFromLayer(csvGrid)
    valLabel.enabled = True
    valLabel.fontSizeInMapUnits = True
    valLabel.fieldName = field
    valLabel.placement = QgsPalLayerSettings.OverPoint
    valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
    valLabel.writeToLayer(csvGrid)
    iface.legendInterface().refreshLayerSymbology(csvGrid)
    iface.mapCanvas().refresh()
by accepting an answer the system automatically marks the thread as solved
Link
underdark
  • 84.5k
  • 22
  • 233
  • 415

(SOLVED) Connecting vector label size with map-units?

Solved!
Source Link
Katalpa
  • 871
  • 10
  • 20
Loading
solution attemps added
Source Link
Katalpa
  • 871
  • 10
  • 20
Loading
deleted 37 characters in body, and added sister reference
Source Link
Katalpa
  • 871
  • 10
  • 20
Loading
added 110 characters in body
Source Link
Katalpa
  • 871
  • 10
  • 20
Loading
added relivent information
Source Link
Katalpa
  • 871
  • 10
  • 20
Loading
Source Link
Katalpa
  • 871
  • 10
  • 20
Loading