2

table of attribute

I have a KML file open in QGIS and I want to convert it to JSON or shapefile, but many attributes are merged in one as you see in the picture in the description field as HTML code, how to extract these attributes from this HTML code?

2
  • You need an ETL that can flatten the xml format then you can extract the data into more useable attributes.
    – Mapperz
    Dec 2, 2022 at 17:38
  • Can you make the kml file available?
    – GBG
    Dec 2, 2022 at 19:57

1 Answer 1

3
  • Add your KML as a layer to QGIS

enter image description here

  • Export to GeoJSON or GeoPackage

enter image description here

  • Go to planemad/qgis-extract-html-attributes and save the extract_html_attributes.py script.
    • Note the requirement to install the BeautifulSoup4 python package.
  • Open the Plugins -> Python Console
  • Click Show Editor and open the extract_html_attributes.py script you saved previously in the editor
  • Select the GeoJSON layer in the table of contents
  • Run the script

enter image description here

enter image description here

5
  • I tried this on but it gives me invalid syntax
    – AYOUB
    Dec 4, 2022 at 14:08
  • Save the extract_html_attributes.py script and open it rather than copy/paste maybe? It works fine for me.
    – user2856
    Dec 4, 2022 at 20:33
  • it works for me bro, thanks a lot for your support
    – AYOUB
    Dec 5, 2022 at 8:57
  • I get some KeyErrors from some of the KMLs, Did you come across this problem?
    – AYOUB
    Dec 5, 2022 at 11:11
  • No, but ask a new Q. with the exact error text (inc. line number) and a KML that causes it.
    – user2856
    Dec 5, 2022 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.