<div dir="ltr"><div>Hi,</div><div><br></div><div>Something like accumulating ids of obstacles for each polygon, ordered by height, and taking the first element of the array:<br></div><div><br></div><div>select <a href="http://p.id">p.id</a>, (array_agg(<a href="http://o.id">o.id</a> order by height_m))[1] as heighest_id<br></div><div>from polyobstacles p join obstacles o on st_contains(p.geom, o.geom);</div><div><br></div><div>Nicolas<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 9 Mar 2020 at 10:21, <<a href="mailto:paul.malm@lfv.se">paul.malm@lfv.se</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="SV">
<div class="gmail-m_8865961900053524214WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I have 2 tables:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">obstacles (point layer) with a column height_m (INTEGER) and a
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">polyobstacles (polygon layer)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">the point layer has obstacles all over the map and the polygon layer has some polygons containing some of the obstacle points.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Now I would like to select the highest obstacle in each polygon. If there is several points with the same highest height a random obstacle of those highest shall be selected.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Is there someone that can get me on the track for such a query, I’m losing myself in subqueries?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Kind regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Paul<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt" lang="EN-US">   
</span><span style="font-size:9pt"><img id="gmail-m_8865961900053524214Bild_x0020_1" src="cid:170bea203984ce8e91" alt="2_LFV_engelsk_96" width="132" height="107"><u></u><u></u></span></p>
<table style="border-collapse:collapse" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="height:36.85pt">
<td style="width:315pt;padding:0cm 0cm 0cm 2.25pt;height:36.85pt" width="420" valign="top">
<p class="MsoNormal" style="margin-top:2pt;line-height:10pt">
<span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-top:2pt;line-height:10pt">
<b><span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US">   Paul Malm</span></b><span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US"><br>
<br>
   Operations AIM</span><span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US"><u></u><u></u></span></p>
</td>
</tr>
<tr style="height:24.1pt">
<td style="width:315pt;padding:0cm 0cm 0cm 2.25pt;height:24.1pt" width="420" valign="top">
<p class="MsoNormal" style="line-height:9pt"><span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US">   Direct  +46 (0)8 797 70 23  Mobile: +46 (0)708 601115<br>
   <a href="mailto:paul.malm@lfv.se" target="_blank">paul.malm@lfv.se</a>  <br>
<br>
<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:9pt"><span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US">   </span><span style="font-size:9pt;color:rgb(51,51,51)">Mail & Visit: Löjtnantsgatan
 25, 115 50 Stockholm, Sweden</span><span style="font-size:9pt;color:rgb(51,51,51)"><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td style="width:315pt;padding:0cm 0cm 0cm 2.25pt" width="420" valign="top">
<p class="MsoNormal" style="margin-top:2pt;line-height:9pt">
<span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US">   Unit phone: +46 (0)8 797 70 20 
<br>
   </span><span style="font-size:9pt;color:rgb(51,51,51)"><a href="http://www.lfv.se/" target="_blank"><span lang="EN-US">www.lfv.se</span></a></span><span style="font-size:9pt;color:rgb(51,51,51)" lang="EN-US"><u></u><u></u></span></p>
</td>
</tr>
<tr style="height:3.7pt">
<td style="width:315pt;padding:0cm 0cm 0cm 2.25pt;height:3.7pt" width="420" valign="top">
<p class="MsoNormal" style="margin-top:6pt;line-height:9pt">
<span style="font-size:9pt;color:rgb(0,204,0)" lang="EN-US">   Please consider the enviroment before printing this e-mail message.</span><span style="font-size:9pt;color:rgb(0,204,0)" lang="EN-US"><u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:9pt" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
</div>
</div>

_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a></blockquote></div>