[postgis-users] ST_SnapToGrid question

Nicolas Ribot nicolas.ribot at gmail.com
Sun Aug 14 05:15:41 PDT 2011


On 13 August 2011 19:30, James Tippett <james.tippett at gmail.com> wrote:
> Hello all,
>
> As a total n00b I have been trying to get my head around a number of postgis issues, and also troubleshoot some early stage failures I seem to be running across.
>
> I would be delighted if someone could tell me what I am doing wrong here:
>
>> SELECT name, ST_AsEWKT(the_geom), ST_AsEWKT(ST_SnapToGrid(the_geom, 360.0)) FROM "countries" WHERE "countries"."gid" = 1 LIMIT 1
>>> "Aruba";"MULTIPOLYGON(((-69.8991387600357 12.4520051131644,-69.8956764390721 12.4230146346486,-69.9421593899187 12.4385175643362,-70.0041452704528 12.5005034448703,-70.0661311509868 12.5469863957168,-70.0508607652446 12.5970866968238,-70.0351252916118 12.614114081264,-69.9731394110777 12.5676311304174,-69.9117994859472 12.4804788273572,-69.8991387600357 12.4520051131644)))";"GEOMETRYCOLLECTION EMPTY"
>
> I had thought to be doing something different here; I wanted to reduce the number of points to unique points on a 360*360 grid. "GEOMETRYCOLLECTION EMPTY" is unexpected.
>
> Can someone please point out where I have gone stupidly wrong?
>
> thanks,
>
> James

Hi James,

The second argument of st_snapToGrid is the size of one unit of the grid.
You are snapping input points to a grid with cell dimensions equal to
360 units (degree in your case). Thus leading to a invalid polygon,
with no points.
Even a 1 degree snapping seems to be too strong for your data:


select astext(st_snapToGRid(



'MULTIPOLYGON(((-69.8991387600357 12.4520051131644,-69.8956764390721
12.4230146346486,-69.9421593899187 12.4385175643362,-70.0041452704528
12.5005034448703,-70.0661311509868 12.5469863957168,-70.0508607652446
12.5970866968238,-70.0351252916118 12.614114081264,-69.9731394110777
12.5676311304174,-69.9117994859472
12.4804788273572,-69.8991387600357 12.4520051131644)))'::geometry,
1));
          astext
--------------------------
 GEOMETRYCOLLECTION EMPTY
(1 ligne)

What exactly do you want to do with your data ?
By reducing too much the coordinates precision, geometries are really
"rough" (see picture 1: input polygon snapped to a 0.1 degree grid).

You may want to try st_simplifyPreserveTopology if you want to remove
some points from the input dataset.

Nicolas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen shot 2011-08-14 at 2.05.24 PM.png
Type: image/png
Size: 34444 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110814/00407ce6/attachment.png>


More information about the postgis-users mailing list