[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] Help with SQL
From:       <paul.malm () lfv ! se>
Date:       2020-03-10 10:04:23
Message-ID: fb69935db0204d0b93ce7758c7bb0ce2 () lfv ! se
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]

[Attachment #4 (text/plain)]

Thanks Felix!

Från: postgis-users [mailto:postgis-users-bounces@lists.osgeo.org] För Felix Kunde
Skickat: den 9 mars 2020 10:33
Till: postgis-users@lists.osgeo.org
Kopia: postgis-users@lists.osgeo.org
Ämne: Re: [postgis-users] Help with SQL

Hi Paul,

no need for subqueries here. Do a spatial join between polygon and points and start \
you query with DISTINCT ON (poly.id) poly.id, o.height etc.

DISTINCT ON (poly.id) will get you one row from the JOIN result per polygon. Which \
one it picks you can control with the final ORDER BY clause - in your case the height \
values of points. The first column in the ORDER BY must be the "group" of your \
DISTINCT ON and then the height value.

cheers
Felix


Gesendet: Montag, 09. März 2020 um 10:21 Uhr
Von: paul.malm@lfv.se
An: postgis-users@lists.osgeo.org
Betreff: [postgis-users] Help with SQL
Hi,
I have 2 tables:
obstacles (point layer) with a column height_m (INTEGER) and a
polyobstacles (polygon layer)
the point layer has obstacles all over the map and the polygon layer has some \
polygons containing some of the obstacle points. 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. Is there someone that \
can get me on the track for such a query, I'm losing myself in subqueries? Kind \
regards, Paul


    [2_LFV_engelsk_96]

   Paul Malm

   Operations AIM

   Direct  +46 (0)8 797 70 23  Mobile: +46 (0)708 601115
   paul.malm@lfv.se

   Mail & Visit: Löjtnantsgatan 25, 115 50 Stockholm, Sweden

   Unit phone: +46 (0)8 797 70 20
   www.lfv.se<http://www.lfv.se/>

   Please consider the enviroment before printing this e-mail message.



_______________________________________________ postgis-users mailing list \
postgis-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/postgis-users


[Attachment #5 (text/html)]

<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=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
	{font-family:Verdana;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
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-postmall17
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 70.85pt 70.85pt 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="SV" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Thanks \
Felix!<o:p></o:p></span></p> <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">Från:</span></b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> \
postgis-users [mailto:postgis-users-bounces@lists.osgeo.org] <b>För </b>Felix \
Kunde<br> <b>Skickat:</b> den 9 mars 2020 10:33<br>
<b>Till:</b> postgis-users@lists.osgeo.org<br>
<b>Kopia:</b> postgis-users@lists.osgeo.org<br>
<b>Ämne:</b> Re: [postgis-users] Help with SQL<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Hi \
Paul,<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">no \
need for subqueries here. Do a spatial join between polygon and points and start you \
query with DISTINCT ON (poly.id) poly.id, o.height etc.<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">DISTINCT \
ON (poly.id) will get you one row from the JOIN result&nbsp;per polygon. Which one it \
picks you can control with the final ORDER BY clause - in your case the height values \
of points.<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">The \
first column in the ORDER BY must be the &quot;group&quot; of your DISTINCT ON and \
then the height value.<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">cheers<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Felix<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp; \
<o:p></o:p></span></p> <div>
<p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp; \
<o:p></o:p></span></p> <div style="border:none;border-left:solid #C3D9E5 \
1.5pt;padding:0cm 0cm 0cm \
8.0pt;margin-left:7.5pt;margin-top:7.5pt;margin-right:3.75pt;margin-bottom:3.75pt;word-wrap: \
break-word;-webkit-nbsp-mode: space;-webkit-line-break: after-white-space" \
name="quote"> <div style="margin-bottom:7.5pt">
<p class="MsoNormal"><b><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Gesendet:</span></b><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp;Montag, \
09. März 2020 um 10:21 Uhr<br> <b>Von:</b>&nbsp;paul.malm@lfv.se<br>
<b>An:</b>&nbsp;postgis-users@lists.osgeo.org<br>
<b>Betreff:</b>&nbsp;[postgis-users] Help with SQL<o:p></o:p></span></p>
</div>
<div name="quoted-content">
<div>
<div>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hi,<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I have 2 \
tables:<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">obstacles (point layer) \
with a column height_m (INTEGER) and a <o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">polyobstacles (polygon \
layer)<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">the point layer has \
obstacles all over the map and the polygon layer has some polygons containing some of \
the obstacle points.<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p> \
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Is \
there someone that can get me on the track for such a query, I'm losing myself in \
subqueries?<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Kind \
regards,<o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Paul<o:p></o:p></p> <p \
class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt">&nbsp;</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt">&nbsp;&nbsp;&nbsp; <img width="132" height="107" \
id="Bild_x0020_1" src="cid:image001.jpg@01D5F6CB.A7C5F4E0" \
alt="2_LFV_engelsk_96"></span><o:p></o:p></p> <table class="MsoNormalTable" \
border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse"> <tbody>
<tr style="height:36.85pt">
<td width="420" valign="top" style="width:315.0pt;padding:0cm 0cm 0cm \
2.25pt;height:36.85pt"> <p class="MsoNormal" \
style="margin-top:2.0pt;mso-margin-bottom-alt:auto;line-height:10.0pt"> <span \
style="font-size:9.0pt;color:#333333">&nbsp;</span><o:p></o:p></p> <p \
class="MsoNormal" style="margin-top:2.0pt;mso-margin-bottom-alt:auto;line-height:10.0pt">
 <b><span style="font-size:9.0pt;color:#333333">&nbsp;&nbsp; Paul Malm</span></b><br>
<br>
<span style="font-size:9.0pt;color:#333333">&nbsp;&nbsp; Operations \
AIM</span><o:p></o:p></p> </td>
</tr>
<tr style="height:24.1pt">
<td width="420" valign="top" style="width:315.0pt;padding:0cm 0cm 0cm \
2.25pt;height:24.1pt"> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:9.0pt"> <span \
style="font-size:9.0pt;color:#333333">&nbsp;&nbsp; Direct&nbsp; &#43;46 (0)8&nbsp;797 \
70 23&nbsp; Mobile: &#43;46 (0)708 601115<br> &nbsp;&nbsp; paul.malm@lfv.se&nbsp; \
</span><br> &nbsp;<o:p></o:p></p>
<p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:9.0pt"> <span \
style="font-size:9.0pt;color:#333333">&nbsp;&nbsp;&nbsp;Mail &amp; Visit: \
Löjtnantsgatan 25, 115 50 Stockholm, Sweden</span><o:p></o:p></p> </td>
</tr>
<tr>
<td width="420" valign="top" style="width:315.0pt;padding:0cm 0cm 0cm 2.25pt">
<p class="MsoNormal" \
style="margin-top:2.0pt;mso-margin-bottom-alt:auto;line-height:9.0pt"> <span \
style="font-size:9.0pt;color:#333333">&nbsp;&nbsp; Unit phone: &#43;46 (0)8&nbsp;797 \
70 20&nbsp;<br> &nbsp;&nbsp;&nbsp;<a href="http://www.lfv.se/" \
target="_blank">www.lfv.se</a></span><o:p></o:p></p> </td>
</tr>
<tr style="height:3.7pt">
<td width="420" valign="top" style="width:315.0pt;padding:0cm 0cm 0cm \
2.25pt;height:3.7pt"> <p class="MsoNormal" \
style="margin-top:6.0pt;mso-margin-bottom-alt:auto;mso-line-height-alt:3.7pt"> <span \
style="font-size:9.0pt;color:#00CC00">&nbsp;&nbsp; Please consider the enviroment \
before printing this e-mail message.</span><o:p></o:p></p> </td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt">&nbsp;</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p> \
</div> <p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">_______________________________________________ \
postgis-users mailing list postgis-users@lists.osgeo.org <a \
href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank"> \
https://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></span></p> \
</div> </div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>


["image001.jpg" (image/jpeg)]
[Attachment #7 (unknown)]

_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic