[Qgis-user] multipart to singlepart Z fix for 2.18

Andreas Plesch andreasplesch at netscape.net
Wed Jul 12 14:55:54 PDT 2017


Looking at the source, 2.99 seems to fix the issue that the multipart to
singlepart vector geometry tool does not preserve Z values for 3d
geometries. 2.18.10 seems to still have this issue, at least 2.18.3 has it.

It turns out that it is straightforward to backport the 2.99 fix to 2.18,
so I thought it may be useful to share the fix:

After backing up the installed

qgis/python/plugins/processing/algs/qgis/MultipartToSingleparts.py

file, edit this file at the bottom (with notepad++ or emacs) and change the
function extractAsSingle to (this much shorter) definition:

def extractAsSingle(self, geom):
       print('multipart2single: use .asGeometryCollection')
       multiGeom = QgsGeometry()
       geometries = []
       if geom.isMultipart():
           multiGeom = geom.asGeometryCollection()
           for g in multiGeom:
               geometries.append(g)
       else:
           geometries.append(geom)
       return geometries

.asGeometryCollection() preserves Z, while the original .as or .from
methods do not.

Also rename the corresponing MultipartToSinglePart.pyc and .pyo files to
something else.

Restart qgis and try it out. This is only tested on linux and with
MultiPointZ but may work with other types as well.

Good luck,

Andreas

PS: I did not submit this as a PR to the github repo since the issue seems
already fixed and the strict requirements for a PR.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20170712/6ae257b8/attachment.html>


More information about the Qgis-user mailing list