Skip to content

BUG: errors in GEOSProject (line_locate_point) are not properly catched #215

@jorisvandenbossche

Description

@jorisvandenbossche

I discovered that GEOS for some cases also raises std::runtime_error (instead of using the "error" message handler mechanism, which we capture and raise as Python exceptions. Not sure why this mechanism is not used for those cases ..)

For example, in the GEOSProject function, if the second geometry is not a point a runtime error is raised: https://github.com/libgeos/geos/blob/27516e0bdb7526699c00fef328c61561ab7a4b47/capi/geos_ts_c.cpp#L3071

When running an example that should trigger that runtime error, with PyGEOS we don't see anything special in Python:

In [5]: import pygeos

In [6]: pygeos.line_locate_point(pygeos.linestrings([(0, 0), (2, 2)]), pygeos.linestrings([(1, 1), (1.5, 1.5)]))
Out[6]: -1.0

As comparison, Shapely is actually somehow "catching" this somewhat (int the logger, but also printing to stdout, not sure where this is done in the Shapely code):

In [3]: from shapely.geometry import LineString

In [4]: LineString([(0, 0), (2, 2)]).project(LineString([(1, 1), (1.5, 1.5)]))
third argument of GEOSProject_r must be Point*
Out[4]: -1.0

But so general question: do we need to do something specific with those runtime errors? I am also not sure how that works in C since the exceptions is a C++ thing (https://en.cppreference.com/w/cpp/error/runtime_error)

Metadata

Metadata

Assignees

No one assigned

    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