2

I have a CSV file containing geodata in WKT in one column. The geometry type is GEOMETRYCOLLECTION. How do I import this to QGIS with one layer per geometry type (POINT and LINESTRING in this case)?

Here's a simplified feature example:

id,title,description,features,category,date
79042,Ausbau Wismar–Rostock,"Ich schlage einen zweigleisigen Ausbau und die Elektrifizierung Wismar–Rostock...","GEOMETRYCOLLECTION(POINT(11.474493907902323 53.89207715945744),LINESTRING(11.47502100706609 53.89112033371444,11.474763515000689 53.89162614941653))",Regionalverkehr,2023-03-24

I used Layer > Add Layer > Add Delimited Text Layer... in QGIS 3.22 and I can select either single geometry types or "Detect" for WKT. I would have expected a new window to select one or more geometry type layers to create from the source. But there is no such selection. An empty layer with no data is being created.

enter image description here

It works if I split the geometry into one column for points and one for lines.

id,title,description,point,line,category,date
79042,Ausbau Wismar–Rostock,"Ich schlage einen zweigleisigen Ausbau und die Elektrifizierung Wismar–Rostock...","POINT(11.474493907902323 53.89207715945744)","LINESTRING(11.47502100706609 53.89112033371444,11.474763515000689 53.89162614941653)",Regionalverkehr,2023-03-24

But my original data has almost 15k rows, so the manual solution does not work. Also, it has more than one point and one linestring per feature.

4
  • it's not the problem but that isn't in 3857 its 4326 (unless they speak German on Null Island)
    – Ian Turton
    May 24 at 11:10
  • So true. I updated the screenshot. The problem persists.
    – winnewoerp
    May 24 at 11:21
  • Does the CSV work if you split the geometry collection manually and insert point and linestring as two rows?
    – user30184
    May 24 at 11:21
  • Yes, it does. See new final paragraph of my question.
    – winnewoerp
    May 24 at 11:28

1 Answer 1

1

I converted your data into GeoJSON and tried to open that with QGIS but it cannot read the geometry nor the attributes correctly. I believe that QGIS cannot really handle geometry collections.

As a workaround I suggest to pre-process the data with ogr2ogr first by exploding the geometry collections.

Usage example:

ogr2ogr -f GeoJSON geomcol.json geomcoll.csv -explodecollections -oo geom_possible_names=features

QGIS can open the resulting GeoJSON file and it suggest to create separate layers for each geometry type.

1
  • Very good, thank you. ogr2ogr is a good solution as a workaround outside of QGIS. It worked even with my large dataset.
    – winnewoerp
    May 24 at 12:02

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.