Skip to content

Commit

Permalink
test_qgsvectorlayerprofilegenerator: Add a test for purely vertical l…
Browse files Browse the repository at this point in the history
…ines

See the previous commit
  • Loading branch information
ptitjano committed Oct 3, 2024
1 parent 5868089 commit 2e5df52
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/src/python/test_qgsvectorlayerprofilegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,44 @@ def testPolyhedralSurfaceGenerationFeature(self):
error_message = f'Expected: {expected}\nGot: {result}\n'
self.assertTrue(compareWkt(expected, result, 0.1), error_message)

def testVerticalLineGenerationFeatureTolerance(self):
"""
Test that a purely vertical line is correctly handled by the generator
"""
vl = QgsVectorLayer("LineStringZ?crs=epsg:27700", "line", "memory")
self.assertTrue(vl.isValid())
self.assertEqual(vl.crs().authid(), 'EPSG:27700')
vl.elevationProperties().setClamping(Qgis.AltitudeClamping.Absolute)
vl.elevationProperties().setExtrusionEnabled(False)

vl_feature = QgsFeature()
vl_feature.setGeometry(QgsGeometry.fromWkt('LineStringZ(321777 129912 1, 321777 129912 -22))'))
self.assertTrue(vl.dataProvider().addFeature(vl_feature))

# Do an intersection
curve = QgsLineString()
curve.fromWkt(
'LineString (-346120 6631840, -346550 6632030, -346440 6632140, -347830 6632930)')
req = QgsProfileRequest(curve)

req.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
req.setTolerance(10)
generator = vl.createProfileGenerator(req)
self.assertTrue(generator.generateProfile())

# Check the result
results = generator.takeResults().asGeometries()
self.assertEqual(len(results), 1)

result = results[0]
self.assertEqual(result.wkbType(), Qgis.WkbType.LineStringZ)
if Qgis.geosVersionMajor() == 3 and Qgis.geosVersionMinor() == 12:
expected_wkt = "LineStringZ (-347055.8 6632478.8 1, -347055.8 6632478.8 -22)"
else:
expected_wkt = "LineStringZ (-347054.8 6632479.6 1, -347054.8 6632479.6 -22)"
self.assertTrue(compareWkt(expected_wkt, result.asWkt(), 0.1),
f'Expected: {expected_wkt}\nGot: {result.asWkt()}\n')

def test_vertical_transformation_4978_to_4985(self):
"""
Test vertical transformations are correctly handled during profile generation
Expand Down

0 comments on commit 2e5df52

Please sign in to comment.