<div dir="ltr">Thanks alot. Now it is working!<div><br></div><div>--</div><div style>Carsten</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/10/11 Nicolas Ribot <span dir="ltr"><<a href="mailto:nicolas.ribot@gmail.com" target="_blank">nicolas.ribot@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">array_agg is collecting all the values during the group by a.poi_id, a.geom.<br>
As you link on desc_string, this will be always the same values.<br>
You can extract the first one using the [] array notation:<br>
<br>
select ..., descs[1] as desc, ....<br>
<span class="HOEnZb"><font color="#888888"><br>
Nicolas<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 11 October 2013 15:10, Carsten Hogertz <<a href="mailto:carsten.hogertz@gmail.com">carsten.hogertz@gmail.com</a>> wrote:<br>
> Hey that's perfect.<br>
> The only thing when I use the array_agg is that I normaly get this:<br>
><br>
> "{"Moth Theatre Company"}"<br>
><br>
> but in some cases I get this:<br>
><br>
> "{"Sacred Fools Theater Company","Sacred Fools Theater Company","Sacred<br>
> Fools Theater Company"}"<br>
><br>
> Any idea why this happens?<br>
> Thanks<br>
> Carsten<br>
><br>
><br>
> 2013/10/11 Nicolas Ribot <<a href="mailto:nicolas.ribot@gmail.com">nicolas.ribot@gmail.com</a>><br>
>><br>
>> Hi,<br>
>><br>
>> you could store initial information in a array of values of<br>
>> desc_string or other attribute, using array_agg function (or create a<br>
>> concatenated string using string_agg function):<br>
>><br>
>> ...<br>
>> SELECT a.poi_id,<br>
>>     a.geom,<br>
>>     array_agg(desc_string) as descs,<br>
>>     St_collect(b.geom) AS b_geom<br>
>><br>
>><br>
>> Nicolas<br>
>><br>
>><br>
>> On 11 October 2013 13:16, Carsten Hogertz <<a href="mailto:carsten.hogertz@gmail.com">carsten.hogertz@gmail.com</a>><br>
>> wrote:<br>
>> > Thanks Hugues,<br>
>> > you helped alot. I added some text to your SQL like the following:<br>
>> ><br>
>> > WITH myselect<br>
>> ><br>
>> >     AS (SELECT a.poi_id,<br>
>> ><br>
>> >     a.geom,<br>
>> ><br>
>> >     St_collect(b.geom) AS b_geom<br>
>> ><br>
>> > FROM<br>
>> ><br>
>> >     ciss_poi a, ciss_poi b<br>
>> ><br>
>> > WHERE<br>
>> ><br>
>> >     St_dwithin(a.geom, b.geom, ( 0.5 / 111.111 ))<br>
>> ><br>
>> >     AND a.poi_id != b.poi_id<br>
>> ><br>
>> >     AND a.desc_string = b.desc_string<br>
>> ><br>
>> > GROUP BY<br>
>> ><br>
>> >     a.poi_id, a.geom)<br>
>> ><br>
>> > SELECT ROW_NUMBER() over (order by geom) as id,<br>
>> ><br>
>> >     St_centroid(St_convexhull(St_collect(geom, b_geom))) as geom<br>
>> ><br>
>> > FROM<br>
>> ><br>
>> >     myselect m<br>
>> ><br>
>> ><br>
>> > With this statement I get the centroid of the grouped point's convex<br>
>> > hulls.<br>
>> > Obviously only the geography.<br>
>> ><br>
>> > What can I do to label the information of one of the "initial" points<br>
>> > that<br>
>> > formed the convex hull to the new centroid?<br>
>> ><br>
>> ><br>
>> > Best Regards and thank you very much<br>
>> ><br>
>> > --<br>
>> ><br>
>> > Carsten<br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > 2013/10/11 Hugues François <<a href="mailto:hugues.francois@irstea.fr">hugues.francois@irstea.fr</a>><br>
>> >><br>
>> >> I think the problem is a bit more complicated. The self join is the<br>
>> >> good<br>
>> >> approach but you can't collect the boolean output of st_dwithin. I<br>
>> >> should<br>
>> >> have tried something like<br>
>> >><br>
>> >> with myselect as (<br>
>> >>     select <a href="http://a.id" target="_blank">a.id</a>, a.geom, st_collect(b.geom) as b_geom from mytable a,<br>
>> >> mytable b<br>
>> >>     where st_dwithin(a.geom, b.geom, 500)<br>
>> >>     and <a href="http://a.id" target="_blank">a.id</a> != <a href="http://b.id" target="_blank">b.id</a><br>
>> >>     group by <a href="http://a.id" target="_blank">a.id</a>, a.geom<br>
>> >>     )<br>
>> >><br>
>> >> select <a href="http://a.id" target="_blank">a.id</a>, st_collect(geom, b_geom) from myselect<br>
>> >><br>
>> >> Hugues.<br>
>> >><br>
>> >> ________________________________<br>
>> >> From: <a href="mailto:postgis-users-bounces@lists.osgeo.org">postgis-users-bounces@lists.osgeo.org</a><br>
>> >> [mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org">postgis-users-bounces@lists.osgeo.org</a>] On Behalf Of Carsten<br>
>> >> Hogertz<br>
>> >> Sent: Friday, October 11, 2013 9:30 AM<br>
>> >> To: PostGIS Users Discussion<br>
>> >> Subject: [postgis-users] ST_Collect<br>
>> >><br>
>> >> Hello,<br>
>> >><br>
>> >> I've got a question about using ST_Collect.<br>
>> >><br>
>> >> I have one table with hundrets of thousands of points. Within this<br>
>> >> table I<br>
>> >> want to collect the points that are within a 500 meter radius and<br>
>> >> calculate<br>
>> >> a convex hull around them.<br>
>> >><br>
>> >> Since the ST_DWithin needs (geom, geom, distance) and I only have one<br>
>> >> table with points, do I first have to perform a self join to identify<br>
>> >> the<br>
>> >> points within 500 meters and then a ST_Collect to group these points?<br>
>> >> Or can<br>
>> >> I somehow do it without joining the one table with itself?<br>
>> >><br>
>> >> And can I use the ST_DWithin inside the ST_Collect? Like<br>
>> >> ST_Collect(ST_DWithing(geom,geom,distance))?<br>
>> >><br>
>> >> Thanks for your help!<br>
>> >> --<br>
>> >> Carsten<br>
>> >><br>
>> >> _______________________________________________<br>
>> >> postgis-users mailing list<br>
>> >> <a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
>> >> <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > postgis-users mailing list<br>
>> > <a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
>> > <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
>> _______________________________________________<br>
>> postgis-users mailing list<br>
>> <a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
>> <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br></div>