Skip to content

QgsLineString.extend() produce nan if vertices are stacked #62473

@jfbourdon

Description

@jfbourdon

What is the bug or the crash?

The method extend() from QgsLineString will produce nan coordinates if the extremity that need to be extended has stack vertices. The resulting geometry is thus invalid. A line with stacked vertices at its ends isn't something that we should normally have but as it doesn't render the geometry invalid, I expect a method like extend() to give a valid output, only affecting the first and/or last vertices. For exemple, a buffer operation will accept such a geometry without any issue.

Steps to reproduce the issue

linestring = QgsLineString([4,4,5,5],[0,0,0,0])
linestring.extend(1,1)
linestring
# Result:   QgsLineString: LineString (nan nan, 4 0, 5 0, nan nan)
# Expected: QgsLineString: LineString (3 0, 4 0, 5 0, 6 0)

Obviously, the same thing happens if I extend a QgsGeometry containing a linestring:

geom = QgsGeometry.fromWkt('LineString (4 0, 4 0, 5 0, 5 0)')
geom.extendLine(1,1)
# Result:   QgsGeometry: LineString (nan nan, 4 0, 5 0, nan nan)
# Expected: QgsGeometry: LineString (3 0, 4 0, 5 0, 6 0)

Versions

QGIS 3.44.0
GDAL 3.8.5
GEOS 3.12.2 (CAPI 1.18.2)

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugEither a bug report, or a bug fix. Let's hope for the latter!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions