Skip to content


Followup fb7c683, 4e4743
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 26, 2016
1 parent fb7c683 commit ae347bf
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/src/python/
Expand Up @@ -25,6 +25,7 @@
from PyQt4.QtCore import QDate, QTime, QDateTime, QVariant, QDir
import os
import platform
from qgis.testing import (
Expand Down Expand Up @@ -171,10 +172,14 @@ def testDateTimeWriteTabfile(self):
assert isinstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2014, 3, 5), QTime(13, 45, 22)))

# Fails on Travis Linux build for some reason
def testWriteShapefileWithZ(self):
"""Check writing geometries with Z dimension to an ESRI shapefile."""

if os.environ.get('TRAVIS') and 'linux' in platform.system().lower():
# This test fails on Travis Linux build for unknown reason (probably GDAL version related)

#start by saving a memory layer and forcing z
ml = QgsVectorLayer(
Expand Down Expand Up @@ -215,6 +220,28 @@ def testWriteShapefileWithZ(self):
expWkt = 'PointZ (1 2 3)'
assert compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

#also try saving out the shapefile version again, as an extra test
#this tests that saving a layer with z WITHOUT explicitly telling the writer to keep z values,
#will stay retain the z values
dest_file_name = os.path.join(str(QDir.tempPath()), 'point_{}_copy.shp'.format(QgsWKBTypes.displayString(t)))
crs = QgsCoordinateReferenceSystem()
crs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
write_result = QgsVectorFileWriter.writeAsVectorFormat(
'ESRI Shapefile')
self.assertEqual(write_result, QgsVectorFileWriter.NoError)

# Open result and check
created_layer_from_shp = QgsVectorLayer(u'{}|layerid=0'.format(dest_file_name), u'test', u'ogr')
f = created_layer_from_shp.getFeatures(QgsFeatureRequest()).next()
g = f.geometry()
wkt = g.exportToWkt()
assert compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

def testWriteShapefileWithMultiConversion(self):
"""Check writing geometries to an ESRI shapefile with conversion to multi."""
ml = QgsVectorLayer(
Expand Down

0 comments on commit ae347bf

Please sign in to comment.