#4314 closed defect (fixed)

ST_AsMVTGeom: IllegalArgumentException

Reported by: Algunenano Owned by: Algunenano
Priority: high Milestone: PostGIS 2.5.2
Component: postgis Version: 2.5.x
Keywords: Cc:

Description

# SELECT ST_AsMVTGeom(
    'SRID=3857;MULTIPOLYGON(((-8230700.44460474 4970098.60762691,-8230694.76395068 4970080.40480045,-8230692.98226063 4970074.69572152,-8230702.2389602 4970071.78449542,-8230709.99536139 4970096.63875167,-8230700.73864062 4970099.5499925,-8230700.44460474 4970098.60762691)))'::geometry,
    'SRID=3857;POLYGON((-8257645.03970416 5009377.08569731,-8257645.03970416 4970241.3272153,-8218509.28122215 4970241.3272153,-8218509.28122215 5009377.08569731,-8257645.03970416 5009377.08569731))'::geometry,
    2048,
    8,
    true
) as the_geom_webmercator;
ERROR:  lwgeom_clip_by_rect: GEOS Error: IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4

I think this was introduced in #4289 so it looks like one of the functions that modify the geometry (lwgeom_remove_repeated_points_in_place, lwgeom_simplify_in_place, lwgeom_affine and lwgeom_grid_in_place) might be producing an invalid ring (or I'm not checking it's output correctly). Note that in the case where the polygon disappeared because of it, MVTGeom should return NULL, not an exception.

Change History (6)

comment:1 Changed 12 months ago by Algunenano

I've extracted the geometry and clip box that was used to call clip_by_rect:

# SELECT ST_ClipByBox2D('POLYGON((1410 2055, 1410 2056, 1410 2057, 1410 2055))'::geometry, ST_MakeEnvelope(-8.000000, -8.000000, 2056.000000, 2056.000000));
ERROR:  lwgeom_clip_by_rect: GEOS Error: IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4
Time: 0.654 ms

The geometry has 4 points but after simplification they've fallen into a Line. I'm not sure yet who is removing one of the points.

Last edited 12 months ago by Algunenano (previous) (diff)

comment:2 Changed 12 months ago by Algunenano

According to the manual for ST_ClipByBox2D:

Topologically invalid input geometries do not result in exceptions being thrown.

On the other hand lwgeom_clip_by_rect might call GEOS_FAIL and GEOS_FREE_AND_FAIL, which calls lwerror throwing an exception.

I think the proper action here would be to call lwdebug or lwnotice instead and return NULL.

comment:4 Changed 12 months ago by Algunenano

Milestone: PostGIS 2.4.7PostGIS 2.5.2
Version: 2.4.x2.5.x

This only affects 2.5, which is when these macros were introduced to simplify the error handling.

comment:5 Changed 12 months ago by Raul Marin

In 17220:

ST_ClipByBox2D: Do not throw when the geometry is invalid

References #4314
Closes https://github.com/postgis/postgis/pull/369

comment:6 Changed 12 months ago by Raul Marin

Resolution: fixed
Status: assignedclosed

In 17221:

ST_ClipByBox2D: Do not throw when the geometry is invalid

Closes #4314

Note: See TracTickets for help on using tickets.