<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hello postgis-community,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">I’m searching for a solution to create aggregated geometries from a table with different single geometries. The input data looks like that:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">id foreign_key geom<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">1 100 point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">2 200 point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">3 200 point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">4 300 point<o:p></o:p></span></p>
<p class="MsoNormal">5 300 point<o:p></o:p></p>
<p class="MsoNormal">6 300 point<o:p></o:p></p>
<p class="MsoNormal">7 400 point<o:p></o:p></p>
<p class="MsoNormal">8 400 line<o:p></o:p></p>
<p class="MsoNormal">9 500 point<o:p></o:p></p>
<p class="MsoNormal">10 500 polygon<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">Now, I want to group this data by the “foreign_key”. The result table have to be this structure:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">foreign_key geom <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">100 point * result of one point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">200 line * result of two points<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">300 polygon * result of three points<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">400 polygon * result of one line and one point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">500 polygon * result of one polygon and one point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">600 (…) * other combinations<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The target is the smallest geometry that contains all single geometries. For example, three points creates a triangle-polygon.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">My last try looks like this:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">SELECT e. foreign_key,<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"> ST_Multi(ST_makeline(e.geom)) as geom<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"> FROM gis_schema.single_objects e<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">GROUP BY e. foreign_key<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(* Of course, polygons are not considered yet ;-)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="mso-fareast-language:DE">Have anybody an idea? Thank’s a lot!<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="mso-fareast-language:DE"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="mso-fareast-language:DE">Best regards,<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="mso-fareast-language:DE">Christopher<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>