Difference in QGIS multipart to single parts and geopandas.explode()

explodegeopandasmultipartqgissinglepart

I noticed that QGIS tool multipart to single parts produces different results than geopandas explode when used to MultiLineString geometries.

Having a multiple lines which are randomly split along their geometries can be dissolved to one using the dissolve tool that works the same in QGIS and GPD. Using GPD.explode() will produce geometrically the same result as before dissolving. QGIS will instead keep some lines continous without splitting them, if they are "logically" better than way (for example one long line that before was split to multiple smaller parts will be a one line after QGIS tool). But geopandas will split it again into multiple small parts.

I need to emulate the behaviour of QGIS tool in geopandas. Is that possible? What is the difference in those two tools?

Best Answer

There is an explode tool in QGIS, too. Explode means creating a separate line (feature) for each segment - thus each line consists of just two vertices: start- and endpoint.

Single parts, however, can consists of many vertices. Only limitation is that each feature consists of only one linestring, thus the line might not fork or not consist of two or more separate lines. Imagine it like a pen on a sheet of paper: what you draw in a single line, without removing the pen from the paper and not going back on a line you already drew.

A mulipart, however, can consist of as many independent lines as you wish, being topologically connected (like forking) or completely disjoint. Imagine it like a whole road- or river network integrated in one single feature.

Consider the following image:

  • There is one multipart line, symbolized in black: one single feature consisting of all the lines you see on the image (1 feature: no. 1 to 31)
  • If you convert this multipart to single parts, you get three parts: the red (no. 1 to 21), yellow (no. 22 to 26) and blue (no. 27 to 31) lines are each separate lines, thus 3 features in total.
  • If you explode these lines, you get 31 parts: the ones labeled from 1 to 31. So each segment (connection from one vertex to the next vertex) is a separate feature. If you have n vertices, you get n-1 features (parts).

enter image description here

Related Question