[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] How to eliminate small gaps produced by ST_union?
From:       Alexandre Neto <senhor.neto () gmail ! com>
Date:       2012-10-26 13:55:20
Message-ID: CA+H0G_Gksyyzpe7xeCnRsrg-BnZ9qaGR9+ncswyna8u1XhUVcA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


That seamed to have worked.

Here is my implementation of Sandro guidelines:

SELECT ST_Union(v.the_geom)
FROM
(SELECT ST_MakeValid(St_Snap(t.the_geom,
        (SELECT ST_SnapToGrid(st_collect(f.the_geom), 0.001) as the_geom
         FROM (SELECT (ST_DumpPoints(g.the_geom)).geom as the_geom
               FROM table1 as g) as f),
        0.001)) as the_geom
FROM
    table1 as t) as v;

It's obviously a slow process as it implies 2 sequential reads in the
table, it takes 11ms with a very simple table containing only 2 polygons,
as it implies 2 sequential reads in the table.

With a bigger table ( 701 polygons, 113147 vertices), it takes 762575 ms...

Since the problem occurs when I do the input of new polygons, I will try to
use this procedures only for the new polygons and the adjacent ones.

Thank you for your help.

Alexandre Neto

On Fri, Oct 26, 2012 at 10:20 AM, Sandro Santilli <strk@keybit.net> wrote:

> On Fri, Oct 26, 2012 at 10:05:29AM +0100, Alexandre Neto wrote:
> > Thank you for all the answers.
> >
> > I did not try the topology, as I need to study its implementation a
> little
> > better.
> >
> > I did not found the st_cleanpolygon function and using (St_Buffer, 0) did
> > not worked:
> >
> > The dilate\erode visually corrects the problem, but of course introduce a
> > small rounding in the angle introducing a small overlaping with other
> > adjacent polygons...
> >
> > I guess that the tolerance with the GEOS PrecisionModel would be nice, I
> > think that is the method used by ArcGIS products to "insure" geometry
> > "topology" after aggregation operations.
> >
> > Any more ideas?
>
> You may try collecting all vertices of input into a MULTIPOINT, then
> ST_SnapToGrid that MULTIPOINT, then ST_Snap each of the input geometries
> to the resulting MULTIPOINT, with your desired tolerance.
> Finally pass the result trough ST_MakeValid to drop collapsed polygons.
>
> Should work fine.  Let us know.
>
> --strk;
>
>  http://www.cartodb.com - Map, analyze and build applications with your
> data
>
>                                        ~~ http://strk.keybit.net
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>

[Attachment #5 (text/html)]

That seamed to have worked.<div><br></div><div>Here is my implementation of Sandro \
guidelines:</div><div><br></div><div><div>SELECT \
ST_Union(v.the_geom)</div><div>FROM</div><div>(SELECT \
ST_MakeValid(St_Snap(t.the_geom, </div> <div>        (SELECT \
ST_SnapToGrid(st_collect(f.the_geom), 0.001) as the_geom</div><div>         FROM \
(SELECT (ST_DumpPoints(g.the_geom)).geom as the_geom</div><div>               FROM \
table1 as g) as f),</div><div>        0.001)) as the_geom</div> <div>FROM</div><div>  \
table1 as t) as v;</div><div><br></div><div>It&#39;s obviously a slow process as it \
implies 2 sequential reads in the table, it takes 11ms with a very simple table \
containing only 2 polygons, as it implies 2 sequential reads in the table.</div> \
<div><br></div><div>With a bigger table ( 701 polygons, 113147 vertices), it takes \
762575 ms...</div><div><br></div><div>Since the problem occurs when I do the input of \
new polygons, I will try to use this procedures only for the new polygons and the \
adjacent ones.</div> <div><br></div><div>Thank you for your \
help.</div><div><br></div><div>Alexandre Neto</div><br><div class="gmail_quote">On \
Fri, Oct 26, 2012 at 10:20 AM, Sandro Santilli <span dir="ltr">&lt;<a \
href="mailto:strk@keybit.net" target="_blank">strk@keybit.net</a>&gt;</span> \
wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div class="im">On Fri, Oct 26, 2012 at 10:05:29AM \
+0100, Alexandre Neto wrote:<br> &gt; Thank you for all the answers.<br>
&gt;<br>
&gt; I did not try the topology, as I need to study its implementation a little<br>
&gt; better.<br>
&gt;<br>
&gt; I did not found the st_cleanpolygon function and using (St_Buffer, 0) did<br>
&gt; not worked:<br>
&gt;<br>
&gt; The dilate\erode visually corrects the problem, but of course introduce a<br>
&gt; small rounding in the angle introducing a small overlaping with other<br>
&gt; adjacent polygons...<br>
&gt;<br>
&gt; I guess that the tolerance with the GEOS PrecisionModel would be nice, I<br>
&gt; think that is the method used by ArcGIS products to &quot;insure&quot; \
geometry<br> &gt; &quot;topology&quot; after aggregation operations.<br>
&gt;<br>
&gt; Any more ideas?<br>
<br>
</div>You may try collecting all vertices of input into a MULTIPOINT, then<br>
ST_SnapToGrid that MULTIPOINT, then ST_Snap each of the input geometries<br>
to the resulting MULTIPOINT, with your desired tolerance.<br>
Finally pass the result trough ST_MakeValid to drop collapsed polygons.<br>
<br>
Should work fine.  Let us know.<br>
<br>
--strk;<br>
<div class="HOEnZb"><div class="h5"><br>
 <a href="http://www.cartodb.com" target="_blank">http://www.cartodb.com</a> - Map, \
analyze and build applications with your data<br> <br>
                                       ~~ <a href="http://strk.keybit.net" \
target="_blank">http://strk.keybit.net</a><br> <br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
 <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" \
target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br> \
</div></div></blockquote></div><br></div>



_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic