Skip to content

Calling Distance on an empty geometry returns 0 #12978

@jontwo

Description

@jontwo

What is the bug?

An empty geometry has a Distance to another geometry of 0; it would be better to raise an error, as this calculation is essentially undefined. For example, Python would would raise a TypeError if a user entered something like 1 > None .

Steps to reproduce the issue

Using the Python bindings:

line1=ogr.CreateGeometryFromWkt("LINESTRING EMPTY")
line2=ogr.CreateGeometryFromWkt("LINESTRING (0 0,5 5)")
line1.Distance(line2)

>>> 0.0

Versions and provenance

Reproduced on Windows 11, GDAL 3.9.0 (OSGeo4W) and Ubuntu 22.04, GDAL 3.8.5 (built from source).

Additional context

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions