Skip to content

Commit ae347bf

Browse files
committedFeb 26, 2016
Followup fb7c683, 4e4743
1 parent fb7c683 commit ae347bf

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed
 

‎tests/src/python/test_qgsvectorfilewriter.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from PyQt4.QtCore import QDate, QTime, QDateTime, QVariant, QDir
2727
import os
28+
import platform
2829
from qgis.testing import (
2930
start_app,
3031
unittest
@@ -171,10 +172,14 @@ def testDateTimeWriteTabfile(self):
171172
assert isinstance(f.attributes()[datetime_idx], QDateTime)
172173
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2014, 3, 5), QTime(13, 45, 22)))
173174

174-
# Fails on Travis Linux build for some reason
175-
@unittest.expectedFailure
176175
def testWriteShapefileWithZ(self):
177176
"""Check writing geometries with Z dimension to an ESRI shapefile."""
177+
178+
if os.environ.get('TRAVIS') and 'linux' in platform.system().lower():
179+
# This test fails on Travis Linux build for unknown reason (probably GDAL version related)
180+
return
181+
182+
#start by saving a memory layer and forcing z
178183
ml = QgsVectorLayer(
179184
('Point?crs=epsg:4326&field=id:int'),
180185
'test',
@@ -215,6 +220,28 @@ def testWriteShapefileWithZ(self):
215220
expWkt = 'PointZ (1 2 3)'
216221
assert compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
217222

223+
#also try saving out the shapefile version again, as an extra test
224+
#this tests that saving a layer with z WITHOUT explicitly telling the writer to keep z values,
225+
#will stay retain the z values
226+
dest_file_name = os.path.join(str(QDir.tempPath()), 'point_{}_copy.shp'.format(QgsWKBTypes.displayString(t)))
227+
print(dest_file_name)
228+
crs = QgsCoordinateReferenceSystem()
229+
crs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
230+
write_result = QgsVectorFileWriter.writeAsVectorFormat(
231+
created_layer,
232+
dest_file_name,
233+
'utf-8',
234+
crs,
235+
'ESRI Shapefile')
236+
self.assertEqual(write_result, QgsVectorFileWriter.NoError)
237+
238+
# Open result and check
239+
created_layer_from_shp = QgsVectorLayer(u'{}|layerid=0'.format(dest_file_name), u'test', u'ogr')
240+
f = created_layer_from_shp.getFeatures(QgsFeatureRequest()).next()
241+
g = f.geometry()
242+
wkt = g.exportToWkt()
243+
assert compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
244+
218245
def testWriteShapefileWithMultiConversion(self):
219246
"""Check writing geometries to an ESRI shapefile with conversion to multi."""
220247
ml = QgsVectorLayer(

0 commit comments

Comments
 (0)
Please sign in to comment.