<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19412"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial>I think the problem is a bit more complicated. The self join 
is the good approach but you can't collect the boolean output of st_dwithin. I 
should have tried something like</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial>with myselect as (</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial>    select a.id, a.geom, st_collect(b.geom) 
as b_geom from mytable a, mytable b</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013>    <FONT 
color=#0000ff size=2 face=Arial>where st_dwithin(a.geom, b.geom, 
500)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013>    <FONT 
color=#0000ff size=2 face=Arial>and a.id != b.id</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013>    <FONT 
color=#0000ff size=2 face=Arial>group by a.id, a.geom</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013>    <FONT 
color=#0000ff size=2 face=Arial>)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial>select a.id, st_collect(geom, b_geom) from 
myselect</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=619053207-11102013><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV><SPAN class=619053207-11102013><FONT size=2 
face=Arial>Hugues.</FONT></SPAN></DIV><BR>
<DIV dir=ltr lang=fr class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> postgis-users-bounces@lists.osgeo.org 
[mailto:postgis-users-bounces@lists.osgeo.org] <B>On Behalf Of </B>Carsten 
Hogertz<BR><B>Sent:</B> Friday, October 11, 2013 9:30 AM<BR><B>To:</B> PostGIS 
Users Discussion<BR><B>Subject:</B> [postgis-users] 
ST_Collect<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr>Hello,
<DIV><BR></DIV>
<DIV>I've got a question about using ST_Collect.</DIV>
<DIV><BR></DIV>
<DIV>I have one table with hundrets of thousands of points. Within this table I 
want to collect the points that are within a 500 meter radius and calculate a 
convex hull around them.</DIV>
<DIV><BR></DIV>
<DIV>Since the ST_DWithin needs (geom, geom, distance) and I only have one table 
with points, do I first have to perform a self join to identify the points 
within 500 meters and then a ST_Collect to group these points? Or can I somehow 
do it without joining the one table with itself?</DIV>
<DIV><BR></DIV>
<DIV>And can I use the ST_DWithin inside the ST_Collect? Like 
ST_Collect(ST_DWithing(geom,geom,distance))?</DIV>
<DIV><BR></DIV>
<DIV>Thanks for your help!</DIV>
<DIV>--</DIV>
<DIV>Carsten</DIV></DIV></BODY></HTML>