5

I have +1000 CityGML data with building height that I want to convert to a raster mask for deep learning. So far, I have converted the GML data into GeoJSON with its respective ID as linestring. Now I want to convert the polylines to polygons (QGIS: “lines to polygons”) but it is not correctly working:

enter image description here

I am well aware that similar questions exist on StackOverflow but none of the proposed solutions has worked for me. I tried the following:

  1. Polygonize > works but no attributes are saved which I essentially need for the raster mask

  2. Assign projection

  3. Buffer lines with 0 m

  4. Merge selected lines

  5. Dissolved > the result is much better but it is still not working for all lines enter image description here

  6. Extract vertices > points to the path

  7. Identification of gaps as shown here (Transforming lines to polygons not working in QGIS?) > gaps found

  8. Select lines > join multiple lines plugin

  9. Fix geometry (no errors found) > lines to polygons

  10. Dissolve > fix geometry > lines to polygons (same result as 5)

I applied the workflow to a single file but need some sort of automation e.g. in Python since I have so many files. The files also contain geometries with “NULL” entries, which would need to be filtered out. The heights are stored in a separate csv file. I’m new to Python.

My test data (EPSG 25832) can be downloaded here.

1
  • 1
    Sure! I added it to my post.
    – user210818
    Jun 5 at 12:49

1 Answer 1

4
  1. Drop M/Z values
  2. Polygonize
  3. Join attributes by location to join the line attributes to the polygons

enter image description here

2
  • Thanks for the input! I tried it but I still face the problem of 1) where the polygons miss the gml_id attributes which I need in order to identify the height information in the csv table. Also, I'm not sure on how to automatize this step.
    – user210818
    Jun 5 at 17:21
  • Join the attributes by location. You can execute the model in batch mode for all files. After you've pressed "Run model" there is a "Run as batch process" option
    – BERA
    Jun 5 at 18:01

Your Answer

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

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