On Fri, 21 Jul 2017 11:44:27 -0700 (PDT), David Anderson wrote:
> I am working out a process to convert a set of irregular features
> into
> a set of regular features. The irregular features are a layer of
> vegetation cover.
> There are the multi colored areas.
>
> I run the SquareGrid function against the vegetation layer. I use
> the default 0,0 for the origin.
> It correctly generates 7 squares that cover the vegetation poygons in
> the area shown below.
>
> I only want 1 regular/square polygon.
>
> My current approach is to group by the geometry field, then select
> the
> one with the square that has the maximum area of a vegetation
> polygon.
> The problem is that the groupby returns 3 square polygons for this
> area.
> Using the ST_EQUALS function the 3 polygons are not equal.
> Yet the areas are the same out to 10 decimal places, the centroids
> return the same X and Y values. So I am wondering why the squares
> are not equal.
>
Hi David,
I not sure to correctly understand what are you doing so to
replicate a testcase.
the attached figure and WKT samples aren't enough: a detailed
specification of all SQL statements you're using will surely be
more useful.
> I am also wondering why 4 of the squares are equal to at least one of
> the three squares returned. It seems like they should all be equal
> or not should be equal.
>
> It might be floating point problem. Here is the WKT of two the
> almost equal polygons:
> POLYGON((530154.569 5256880.132,530296.
8159999999
> 5256880.132,530296.8159999999 5257022.379, 530154.569
> 5257022.379, 530154.569 5256880.132))
> POLYGON((530154.569 5256880.132,530296.
8159999999
> 5256880.132,530296.8159999999 5257022.379000001,530154.569
> 5257022.379000001,530154.569 5256880.132))
>
> They differ only by 0.000000001 for two points. Which appears to be
> enough to be not equal.
>
> Perhaps they could be some rounding in the SquareGrid function?
>
I strongly doubt that SquareGrid could be specifically prone to
rounding errors, but for sure all SQL functions involving some
GEOS operation are, most notably on 32 bit x86 platforms, as it
recently emerged in a discussion with GEOS developers.
a little known technical fact is that all modern x86 CPUs
(starting since year 2000, Pentium III generation) include
in their HW _TWO_ different floating point processors:
- the old 387, supporting 80 bit internal registers
- the new SSE, supporting 64 bit internal registers
(and the SSE fp processor is someway faster than the 387)
all C/C++ compilers (gcc, msvc and so on) always use by default
the 387 fp processor when compiling 32 bit code (mainly to
preserve historical compatibility), whilst they automatically
switch to SSE for 64 bit code.
the problem with 387 is in that its odd 80 bit internal
registers doesn't fit standard DOUBLE program variables
that always are 64 bit.
so every time that a 387 fp result is transferred from
CPU to memory a conversion from 80 to 64 bit happens, and
this can easily cause weird truncation/rounding effects.
the next version of GEOS will probably fix this issue
(SSE should be always switched on, also when compiling
32 bit code).
bye Sandro