# [postgis-users] Combines polygons within a specified distanceto each other into new polygons.

Peter Freimuth pfreimuth at arcor.de
Sun Sep 6 03:50:14 PDT 2009

```Paragon Corporation schrieb:
> Peter,
>
> Try
>
>
> SELECT a.gid, ST_ConvexHull(ST_Collect(b.the_geom)) As the_geom
> INTO polygon_convexhull
>  FROM polygon1 As a INNER JOIN polygon1 As b ON
>  ST_DWithin(a.the_geom, b.the_geom, 1000)
>  GROUP BY a.gid
>  HAVING a.gid = MIN(b.gid);
>
>
> This should create a new table called polygon_convexhull consisting of the
> convex hulls.
>
> Leo
>
> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net
> [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Peter
> Freimuth
> Sent: Saturday, September 05, 2009 8:56 PM
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] Combines polygons within a specified distanceto
> each other into new polygons.
>
> Paragon Corporation schrieb:
>
>> Peter,
>> For the harder case where the reference is arbitrary and you are
>> trying to calculate many convex hulls.  This will be much slower --
>> depending on size of your table. First thought that comes to mind is a
>>
> self join.
>
>> The HAVING clause is to try to minimize on a geometry being collected
>> in more than one convex hull set.  Its not guaranteed though and also
>> depending on your pattern, it may miss some.
>>
>> SELECT a.gid, ST_ConvexHull(ST_Collect(the_geom)) As convhull FROM
>> table_of_polygons As a INNER JOIN table_of_polygons As b ON
>> ST_DWithin(a.the_geom, b.the_geom, some_max_dist) GROUP BY a.gid
>> HAVING a.gid = MIN(b.gid);
>>
>> Hope that helps,
>> Regina
>>
>> -----Original Message-----
>> From: postgis-users-bounces at postgis.refractions.net
>> [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
>> Paragon Corporation
>> Sent: Saturday, September 05, 2009 11:07 AM
>> To: 'PostGIS Users Discussion'
>> Subject: Re: [postgis-users] Combines polygons within a specified
>> distanceto each other into new polygons.
>>
>> Peter,
>> You would use a combination of ST_DWithin, ST_Collect, and ST_ConvexHull.
>> When you say within a max distance -- you mean of a reference geometry
>> or from each other?  From each other can be kind of expensive.
>>
>> So something of the form
>>
>> SELECT ST_ConvexHull(ST_Collect(the_geom))
>> FROM table_of_polygons
>> WHERE ST_DWithin(ST_GeomFromText(.....), the_geom, max_dist)
>>
>> http://postgis.refractions.net/documentation/manual-svn/ST_ConvexHull.
>> html
>>
>> http://postgis.refractions.net/documentation/manual-svn/ST_Collect.htm
>> l
>>
>> http://postgis.refractions.net/documentation/manual-svn/ST_GeomFromTex
>> t.html
>>
>> http://postgis.refractions.net/documentation/manual-svn/ST_DWithin.htm
>> l
>>
>> Leo
>>
>>
>>
>> -----Original Message-----
>> From: postgis-users-bounces at postgis.refractions.net
>> [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
>> Peter Freimuth
>> Sent: Saturday, September 05, 2009 9:26 AM
>> To: PostGIS Users Discussion
>> Subject: [postgis-users] Combines polygons within a specified distance
>> to each other into new polygons.
>>
>> Hi PostGIS User,
>> i am searching for a postgis based solution to create a convexhull on
>> groups of polygons which are grouped via a max distance value.
>>
>>
>>
>> Any idea or a solution is welcome!
>>
>> Kind regards,
>> Peter
>>
>>
>>
>>
>>
> Thanks Regina for your hint,
> find attached the polygons which i try to aggregate and a screenshot of how
> it should look like at the end (brown are the results of the aggregation
> that i would like to produce and pink are the original polygons).
> The solution you proposed  did'nt produce the results that i want. Maybe i
> make a mistake.
> Anyway, thanks for your help!!
>
> Kind regards,
> Peter
>
>
>
Thanks Leo,
this one worked. and is exactly what i searched for.
Thanks for your support,
Peter

--
Peter Freimuth  Muskauer Str. 11   10997 Berlin
Location:http://www.berlinonline.de/citymap/map.asp?start.x=5&plz=10997&str=Muskauer+Str.+11&grid=dedatlas10
========================================================================================================
Tel:+49(0)30-69816610  Mobil:+49(0)175-8434074  Firma:+49(0)3381-8904327
========================================================================================================
mailto:pfreimuth at arcor.de
skype:pfreimuth
msn:peter_freimuth at hotmail.com

```

More information about the postgis-users mailing list