[postgis-users] fuzzy tolerance

Lars Aksel Opsahl Lars.Opsahl at nibio.no
Wed Sep 14 10:50:43 PDT 2016


Hi again


I did a simple test with ST_SnapToGrid(geo, 0.001) on a real dataset that based on farm property border in Norway and intersection of this dataset http://www.skogoglandskap.no/en/subjects/ar5_land_resource_map/subject_view .


The result was almost 100.000 invalid polygons of 2.6 millions polygons.

I have added SQL below so you can check the way I have used the postgis functions.


The server I tested on has this configuration

postgis_full_version | POSTGIS="2.2.2 r14797" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.6" LIBJSON="0.11" TOPOLOGY RASTER


First i convert the data to meter and check that it was valid then I did a st_snaptogrid and then I count who is valid who is not.


select count(*) as valid_rows from (

select ST_isValid(org_geo), ST_area(org_geo), ST_isValid(snap_geo), ST_area(snap_geo)

from (Select geo as org_geo , ST_SnapToGrid(geo, 0.001) as snap_geo from (

select ST_transform(geo,25835) as geo from gaard_ar5_7kl_16_12_2012_flate

) as t1

) as t2 where st_isvalid( org_geo) and st_isvalid( snap_geo)

) as t3;


valid_rows

------------

    2648499

(1 row)



select count(*) as invalid_rows from (

select ST_isValid(org_geo), ST_area(org_geo), ST_isValid(snap_geo), ST_area(snap_geo)

from ( Select geo as org_geo , ST_SnapToGrid(geo, 0.001) as snap_geo from (

select ST_transform(geo,25835) as geo from gaard_ar5_7kl_16_12_2012_flate

) as t1

) as t2 where st_isvalid( org_geo) and st_isvalid( snap_geo) = false

) as t3;


invalid_rows

--------------

        94308

(1 row)



select ST_isValid(org_geo), ST_area(org_geo), ST_isValid(snap_geo), ST_area(snap_geo), ST_isSimple(snap_geo)

from ( Select geo as org_geo , ST_SnapToGrid(geo, 0.001) as snap_geo from (

select ST_transform(geo,25835) as geo from gaard_ar5_7kl_16_12_2012_flate

) as t1

) as t2 where st_isvalid( org_geo) and st_isvalid( snap_geo) = false

limit 5;

NOTICE:  Self-intersection at or near point -712380.76390491705 6752484.312060223

NOTICE:  Self-intersection at or near point -712380.76390491705 6752484.312060223

NOTICE:  Self-intersection at or near point -693336.00845633878 6760997.9791273763

NOTICE:  Self-intersection at or near point -693336.00845633878 6760997.9791273763

NOTICE:  Self-intersection at or near point -685803.05900000001 6761659.9010000005

NOTICE:  Self-intersection at or near point -685803.05900000001 6761659.9010000005

NOTICE:  Self-intersection at or near point -686975.27643165435 6761818.4071217496

NOTICE:  Self-intersection at or near point -686975.27643165435 6761818.4071217496

NOTICE:  Self-intersection at or near point -685793.5384688942 6761692.5602394082

NOTICE:  Self-intersection at or near point -685793.5384688942 6761692.5602394082

 st_isvalid |     st_area      | st_isvalid |     st_area      | st_issimple

------------+------------------+------------+------------------+-------------

 t          | 12071.0927293049 | f          | 12071.0915145167 | t

 t          | 1249.63589967907 | f          | 1249.62388100091 | t

 t          |  2438.3765259538 | f          | 2438.41668248867 | t

 t          | 8.73835355134684 | f          | 8.72929450303413 | t

 t          |  8.1236959106824 | f          | 8.12728899896324 | t

(5 rows)



Lars



________________________________
Fra: postgis-users <postgis-users-bounces at lists.osgeo.org> på vegne av Willy-Bas Loos <willybas at gmail.com>
Sendt: 14. september 2016 12:52
Til: PostGIS Users Discussion
Emne: Re: [postgis-users] fuzzy tolerance

On Wed, Sep 14, 2016 at 11:27 AM, Stefan Keller <sfkeller at gmail.com<mailto:sfkeller at gmail.com>> wrote:
There is at least SnapToGrid:
# select ST_SnapToGrid((ST_DumpPoints(mypoly.geom)).geom, 0.1) from mypoly;

:Stefan

Hm, i considered that before, but now i can't say why i discarded the thought.
One thing is that the unit for snaptogrid is degrees for WGS84, so for world data that would pose a problem: you're not using a uniform grid to snap to.
But in other coordinate systems, and if the algorithm is fast enough, one could use this in a trigger and always store geometries snapped to a 10cm grid. That would be precise enough for our data.
It is easy to understand what is happening too, so that is an advantage.
BTW i tested and saw that it's not necessary to dump the points, you can snap the whole polygon.

Any words of warning about using a trigger and storing the data on a 10 cm grid like i suggest?

Cheers,


--
Willy-Bas Loos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20160914/9a683103/attachment.html>


More information about the postgis-users mailing list