TransWikia.com

Convert cityGML to SHP?

Geographic Information Systems Asked on May 13, 2021

I want to convert cityGML files into shapefiles which show the 3D-objects from above in 2D. It would be also nice to keep the height of the objects in the attribute table or as z-value. I want to use either QGIS, SAGA or GDAL to solve the problem.

If I simply export the GML in QGIS to shapefiles, several polygons are corrupted (when I color them, only the outlines are showing, they are not filled). And I can only keep the height if it was in the GML file added as attribute. If I use ogr2ogr from GDAL, the same problem occurs.

I can repair the polygons with the "fix geometries" tool in QGIS, but I am not sure if this always works or if I would have to check all the polygons everytime to check nothing went wrong…

Here is my current code:

# set path to the gml
gml_path = r"H:QGISoriginal.gml"
intermediate_path = r"H:QGISexported.shp"
shp_path = r"H:QGISrepaired.shp"

# load gml
gml_input =  QgsVectorLayer(gml_path, "gml_input", "ogr")

# export as shp
QgsVectorFileWriter.writeAsVectorFormat(gml_input, fileName=intermediate_path, fileEncoding="utf-8", driverName="ESRI Shapefile")

# repair shp
processing.run("native:fixgeometries", {'INPUT':intermediate_path, 'OUTPUT':shp_path})

Are there better or more reliable ways to do this?

Edit: I also tried "cheating" my way around it by trying to clip the GML-objects with a polygon with a bigger extent. This, however, did not work.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP