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

estrarre nome campo e relativo alias da un file qml #253

Open
pigreco opened this issue May 16, 2023 · 1 comment
Open

estrarre nome campo e relativo alias da un file qml #253

pigreco opened this issue May 16, 2023 · 1 comment

Comments

@pigreco
Copy link
Contributor

pigreco commented May 16, 2023

In questo file qml (è un file che permette di memorizzare lo stile dei layer in QGIS), nella sezione <aliases> ci sono memorizzati i nomi dei campi e i relativi alias di un layer vettoriale:

image

dove:

  • field è il nome dell'attributo
  • name è il relativo alias

il mio obiettivo è estrarre il field e name e creare una file csv come sotto

field name
DATA Data sopralluogo:
Comune Comune:
Localita Località:

io ho risolto manualmente usando NotePad++ con trova e sostituisci, mi piacerebbe farlo usando bash
schedadicampo.zip

@aborruso
Copy link
Member

Ciao @pigreco, per queste cose trovo comodo https://github.com/kislyuk/yq

Con yq faccio una query al tuo file XML, come se fosse un JSON.

<schedadicampo.qml xq . | fx

La struttura di base è questa:

image

Quindi devo esplorare la struttura del JSON sino ad arrivare agli alias:

<schedadicampo.qml xq -c '.qgis.aliases.alias[]'

In questo modo estraggo un JSONlines, ovvero un file in cui ogni riga è un oggetto json valido

image

E questo lo leggi nativamente con visidata

<schedadicampo.qml xq -c '.qgis.aliases.alias[]' | vd -f jsonl

image

E con Miller

<schedadicampo.qml xq -c '.qgis.aliases.alias[]' | mlr --j2c cat >output.csv

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

No branches or pull requests

2 participants