
PostGIS Geometry Quality: Invalid Geometries, Mixed SRIDs, and Complexity
Why Your PostGIS Spatial Queries Return Wrong Results (and How to Fix It) PostGIS spatial functions assume their input geometries are valid. When they're not, things go wrong quietly. ST_Intersection returns NULL instead of a result. ST_Area reports negative values. Spatial joins silently drop matching rows. You don't get an error -- you get incomplete or wrong results that look plausible. This article covers the three geometry quality problems that cause these failures and how to fix each one. Problem 1: Invalid Geometries A geometry is "invalid" under the OGC Simple Features specification when it has structural defects: self-intersecting polygon rings, duplicate consecutive points, or unclosed rings. These defects cause spatial operations to behave unpredictably. The insidious part is that different PostGIS functions fail differently on invalid input. ST_Contains might return FALSE for a point that's clearly inside a polygon. ST_Union might throw a TopologyException . ST_Buffer might
Continue reading on Dev.to Tutorial
Opens in a new tab

![[MM’s] Boot Notes — The Day Zero Blueprint — Test Smarter on Day One](/_next/image?url=https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1368%2F1*AvVpFzkFJBm-xns4niPLAA.png&w=1200&q=75)

