2

I am confused about the geometry types in QGIS. I thought a linestring is just one line and a multilinestring consists of two or more linestrings in one layer. But then I created a vector layer with one line and in the properties I read Line (multilinestring). How is this possible, this should be just a linestring right? And I can't import this layer into my geodatabase, which don't accepts multilinestrings. What did I miss?enter image description here

6
  • 2
    If you create a Layer as a Shapefile, QGIS will make it a MultiLinestring when you chose Linestring (shapefiles have Polylines, not Lines). If you create the layer as a Geopackage or Spatialite layer, you'll be able to explicitely select single part lines LinesString. Additional note: a Multilinestring is multiple Lines in one single geometry object (multiple lines with the same feature attributes in your layer). This does not prevent a LineString layer at all to have multiple Line geometries, as separate features.
    – Kasper
    Jan 19, 2023 at 9:32
  • So there is no chance to import my shapefile layer into my geodatabase without converting to a geopackage or change the geometry type in the db? Jan 19, 2023 at 9:37
  • Are you exporting to PostgreSQL ? If so there is an option in the export tool, you can tick: "create single-part geometries inestead of multipart"
    – Kasper
    Jan 19, 2023 at 9:43
  • Yes its postgres, but I try to import with the ogr2ogr command in the osgeo shell Jan 19, 2023 at 9:52
  • Try -nlt LINESTRING, see ogr2ogr documentation: nlt option
    – Kasper
    Jan 19, 2023 at 10:03

2 Answers 2

4

A MultiLineString consists of 1 or more LineStrings. The reason that QGis (and other programs like PostGIS) "promote" single LineStrings to MultiLineStrings is that while formats like Shapefile can handle mixed geometry types most formats and programs expect to have the same type through out a dataset. So while a MultiLineString and a LineString are different a MultiLineString with one line in it is a valid MultiLineString.

2
  • Maybe I am misreading or misunderstanding your comment about "formats like Shapefile can handle mixed geometry types" because the ESRI Shapefile Technical Description - shapefile.pdf posted by Esri clearly states, "All the non-Null shapes in a shapefile are required to be of the same shape type." I believe the promotion of LineString to MultiLineString has less to do with mixed geometry types and more to do with some geometry models not supporting singular geometry types.
    – bixb0012
    Jan 22, 2023 at 23:55
  • Shapefiles don't consider (e.g) Polygons and MultiPolygons to be different types more sensible programs do.
    – Ian Turton
    Jan 23, 2023 at 8:25
2

A MultiLineString can contain multiple geometries per feature while a LineString can contain only a single geometry per feature.

If you are certain that all your features have only one geometry, you can use the "Multipart to singleparts" tool in QGIS to convert the file with MultiLineString geometries to one with LineString geometries.

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.