Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Diagram] technical research #48

Open
Kanahiro opened this issue Jul 6, 2023 · 6 comments
Open

[Diagram] technical research #48

Kanahiro opened this issue Jul 6, 2023 · 6 comments

Comments

@Kanahiro
Copy link
Member

Kanahiro commented Jul 6, 2023

image

@bordoray
Copy link
Collaborator

bordoray commented Jul 7, 2023

image

Memo

# get attributes renderer
lyr[0].diagramRenderer().diagramSettings()[0].categoryAttributes
>>> [' "code" /100', 'rand(0,100)', 'rand(0,100)']

#get legends
lyr[0].diagramRenderer().diagramSettings()[0].categoryLabels
>>> ['one', 'two', 'three']

#get colors
lyr[0].diagramRenderer().diagramSettings()[0].categoryColors
>>> [<PyQt5.QtGui.QColor object at 0x000001F7E7F96EB0>, <PyQt5.QtGui.QColor object at 0x000001F7C9EC6C10>, <PyQt5.QtGui.QColor object at 0x000001F7C9EC6CF0>]

#get size
lyr[0].diagramRenderer().diagramSettings()[0].size
>>> PyQt5.QtCore.QSizeF(15.0, 15.0)

@bordoray
Copy link
Collaborator

bordoray commented Jul 7, 2023

To detect diagram

lyr[0].diagramsEnabled()
True
nodiag[0].diagramsEnabled()
False

@bordoray
Copy link
Collaborator

bordoray commented Jul 10, 2023

Tentative process idea:

  • Use clipped shapefile.
  • Get centroids coordinates or used label process
  • get values of each centroid feature
  • Export as diagram_{n}.json separated json (as for labels_{n}.json)

Issue : may work only for centroid placed diagram
image

@bordoray
Copy link
Collaborator

bordoray commented Jul 10, 2023

Tentative JSON diagram_{n}.json

{
    "layer": "population",
    "type": "pie_chart",
    "size": "15.0",
    "legends" : ['legend1','legend2','legend3'],
    "colors" : ['#232323','#999999','#aaaaaa'],
    "attributes": [
        {
            "x": 420744.52217771474,
            "y": 4034541.0965687246,
            "legend1": 151,
            "legend2": 250,
            "legend3": 55,
        },
        {
            "x": 420744.52217771474,
            "y": 4034541.0965687246,
            "legend1": 251,
            "legend2": 180,
            "legend3": 65,
        },
    ...
]

@bordoray
Copy link
Collaborator

To detect diagram type

lyr[0].diagramRenderer().diagram()
<qgis._core.QgsPieDiagram object at 0x000002625B1D9DC0>
lyr[0].diagramRenderer().diagram()
<qgis._core.QgsHistogramDiagram object at 0x000002625B1D9C10>
lyr[0].diagramRenderer().diagram()
<qgis._core.QgsStackedBarDiagram object at 0x000002625B1D9DC0>
lyr[0].diagramRenderer().diagram()
<qgis._core.QgsTextDiagram object at 0x000002625B1D9C10>

@Kanahiro
Copy link
Member Author

It is technically difficult to support Diagrams because:

  • there is no API to extract positions of diagrams rendered on map canvas.
    • this is similar to Labels but a processing for extracting label-postion is supported relatively newer QGIS, IMO Diagrams need API like it.

So, set a priority for this very lower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants