|
25 | 25 | )
|
26 | 26 | from PyQt4.QtCore import QDate, QTime, QDateTime, QVariant, QDir
|
27 | 27 | import os
|
| 28 | +import platform |
28 | 29 | from qgis.testing import (
|
29 | 30 | start_app,
|
30 | 31 | unittest
|
@@ -171,10 +172,14 @@ def testDateTimeWriteTabfile(self):
|
171 | 172 | assert isinstance(f.attributes()[datetime_idx], QDateTime)
|
172 | 173 | self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2014, 3, 5), QTime(13, 45, 22)))
|
173 | 174 |
|
174 |
| - # Fails on Travis Linux build for some reason |
175 |
| - @unittest.expectedFailure |
176 | 175 | def testWriteShapefileWithZ(self):
|
177 | 176 | """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 |
178 | 183 | ml = QgsVectorLayer(
|
179 | 184 | ('Point?crs=epsg:4326&field=id:int'),
|
180 | 185 | 'test',
|
@@ -215,6 +220,28 @@ def testWriteShapefileWithZ(self):
|
215 | 220 | expWkt = 'PointZ (1 2 3)'
|
216 | 221 | assert compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
|
217 | 222 |
|
| 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 | + |
218 | 245 | def testWriteShapefileWithMultiConversion(self):
|
219 | 246 | """Check writing geometries to an ESRI shapefile with conversion to multi."""
|
220 | 247 | ml = QgsVectorLayer(
|
|
0 commit comments