Using Postgres 9.2
I have a strange issue. To simplify it:
I have some data with line points. The query in question is using st_intersects to determine if the line points overlap with a polygon. Both the line and the polygon are stored in a 3d representation, with the z-axis being 0. This is for geospatial data.
In this case, I have a line point where the start and end are the same value. Two records have seemingly the same value, the X,Y,Z components on the start and end points are the same. Comparing the two points using =~, they are equal. Using =, they are equal. Using st_equals, the result is false, but comparing the components that make up the lines, the values all seem to be equal, including comparing the binary representation by visual inspection.
When I do st_intersects(my_line, some_polygon), one record returns true, the other false, even though the value of the line for both records appear identical. I didn't create the original values, so I do not know how they were originally created. There is a vehicle associated with each record, and for whatever reason, one of the vehicles has this problem for several of its records.
If I change the function from st_intersects to the presumably more expensive st_3dintersects, they both return true as expected, and the problem goes away. The polygon being compared against is quite large, and this affects several records with different points, so its unlikely we're hitting some fringe rounding error of any kind. Using st_force2d doesn't work either.
Any ideas why I might be seeing the behavior that I'm seeing?
Here's the EWKT of the line, with the coordinates changed:
SRID=4326;LINESTRING(-85.6600021 30.7976979 0,-85.6600021 30.7976979 0)
Both records have this exact same value for ST_AsEWKT, and yet one of them returns false for st_intersects(my_line, the_poly) and the other returns true for st_intersects(my_line, the_poly). Even if I hard code the EWKT value I still see this discrepency:
ST_Intersects(
ST_GeomFromEWKT('SRID=4326;LINESTRING(-85.6600021 30.7976979 0,-85.6600021 30.7976979 0)')),
x.geom
)
It seems like it is always affecting the very first record in the result set and no other records. If I change everything else in my query, this always returns false for the first record and true for all the subsequent records.
Edit: More investigation, it appears that the linestring is not valid with both the start and end being the same value. Casting st_makevalid fixes it by making it a point. Apparently the invalid linestring is evaluated inconsistently.
ST_AsEWKT()
for both of the things you're sending toST_Equals
.