Postgresql 如何解决 GEOSIntersects 错误?
Postgresql how to work around GEOSIntersects error?
所以我有一个大型 select 查询,它有超过 1700 行,基本上从与多边形 table
select a.id
(select count(*) from pointtable2 b where st_contains(a.geom,b.geom ) )
(select sum(st_length(st_intersection(a.geometry, r.geometry))) from linetable3 b where st_intersects(a.geom,b.geom ) ),
(select a whole bunch of stuff from several other tables where multitude of conditions..)
from polygontable a
group by a.id, a.geom
特别是一个线层具有无效的几何图形,最初我通过在 where 条件上添加来处理
geometrytype(r.geom) <> 'MULTICURVE'::text AND st_isvalid(r.geom) is true
问题是,即使在这些情况下,我仍然收到以下错误
SQL Error [XX000]: ERROR: GEOSIntersects: IllegalArgumentException: RobustDeterminant encountered non-finite numbers
ERROR: GEOSIntersects: IllegalArgumentException: RobustDeterminant encountered non-finite numbers
ERROR: GEOSIntersects: IllegalArgumentException: RobustDeterminant encountered non-finite numbers
修复错误的几何结构将是长期解决方案,但迫切需要此报告视图,运行 我的查询忽略失败行的最佳方式是什么?或者我如何才能发现哪些 geometries/which 行代码失败了?
这个问题很可能已在最新的 PostGIS 版本中得到解决。请参阅下面的示例 using PostgreSQL 12 and PostGIS 3.0
:
WITH j(geom)AS (
VALUES ('MULTICURVE((0 0,5 5))'::GEOMETRY),
('POINT(0 0 42)'::GEOMETRY),
('POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))'::GEOMETRY), --invalid polygon
('POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))'::GEOMETRY)
)
SELECT
ST_AsText(geom),ST_IsValidReason(geom),
GeometryType(geom),
ST_Intersection(ST_MakeValid(geom),'POINT(0 0)'::GEOMETRY)
FROM j
WHERE
ST_Intersects(geom,'POINT(0 0)'::GEOMETRY) AND
GeometryType(geom) <> 'MULTICURVE'
AND ST_IsValid(geom);
st_astext | st_isvalidreason | geometrytype | st_intersection
------------------------------------------------------+------------------+--------------+------------------------------------------------------------
POINT Z (0 0 42) | Valid Geometry | POINT | 0101000080000000000000000000000000000000000000000000004540
POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)) | Valid Geometry | POLYGON | 010100000000000000000000000000000000000000
进一步阅读:
所以我有一个大型 select 查询,它有超过 1700 行,基本上从与多边形 table
select a.id
(select count(*) from pointtable2 b where st_contains(a.geom,b.geom ) )
(select sum(st_length(st_intersection(a.geometry, r.geometry))) from linetable3 b where st_intersects(a.geom,b.geom ) ),
(select a whole bunch of stuff from several other tables where multitude of conditions..)
from polygontable a
group by a.id, a.geom
特别是一个线层具有无效的几何图形,最初我通过在 where 条件上添加来处理
geometrytype(r.geom) <> 'MULTICURVE'::text AND st_isvalid(r.geom) is true
问题是,即使在这些情况下,我仍然收到以下错误
SQL Error [XX000]: ERROR: GEOSIntersects: IllegalArgumentException: RobustDeterminant encountered non-finite numbers
ERROR: GEOSIntersects: IllegalArgumentException: RobustDeterminant encountered non-finite numbers
ERROR: GEOSIntersects: IllegalArgumentException: RobustDeterminant encountered non-finite numbers
修复错误的几何结构将是长期解决方案,但迫切需要此报告视图,运行 我的查询忽略失败行的最佳方式是什么?或者我如何才能发现哪些 geometries/which 行代码失败了?
这个问题很可能已在最新的 PostGIS 版本中得到解决。请参阅下面的示例 using PostgreSQL 12 and PostGIS 3.0
:
WITH j(geom)AS (
VALUES ('MULTICURVE((0 0,5 5))'::GEOMETRY),
('POINT(0 0 42)'::GEOMETRY),
('POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))'::GEOMETRY), --invalid polygon
('POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))'::GEOMETRY)
)
SELECT
ST_AsText(geom),ST_IsValidReason(geom),
GeometryType(geom),
ST_Intersection(ST_MakeValid(geom),'POINT(0 0)'::GEOMETRY)
FROM j
WHERE
ST_Intersects(geom,'POINT(0 0)'::GEOMETRY) AND
GeometryType(geom) <> 'MULTICURVE'
AND ST_IsValid(geom);
st_astext | st_isvalidreason | geometrytype | st_intersection
------------------------------------------------------+------------------+--------------+------------------------------------------------------------
POINT Z (0 0 42) | Valid Geometry | POINT | 0101000080000000000000000000000000000000000000000000004540
POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)) | Valid Geometry | POLYGON | 010100000000000000000000000000000000000000
进一步阅读: