<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-size: 12pt; font-family: Consolas, Courier, monospace;">The following two select statements  return  FALSE:</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<p style="margin: 0px; font: 12px Menlo; margin: 0px"><span style="font-size: 12pt; font-family: Consolas, Courier, monospace;">SELECT ST_WITHIN(CAST(bounds as GEOMETRY) , ST_MakePoint(1, 1) ) FROM m_polygon;</span></p>
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<p style="margin: 0px; font: 12px Menlo; margin: 0px"><span style="font-family: Consolas, Courier, monospace; font-size: 12pt;">SELECT ST_WITHIN( ST_MakePoint(1, 1), CAST(bounds as GEOMETRY)</span><span style="font-family: Consolas, Courier, monospace; font-size: 12pt;"> 
</span><span style="font-family: Consolas, Courier, monospace; font-size: 12pt;">) FROM m_polygon;</span></p>
<p style="margin: 0px; font: 12px Menlo; min-height: 14px; margin: 0px; min-height: 14px">
<br>
</p>
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-size: 12pt; font-family: Consolas, Courier, monospace;">Why it is so? I think what the point (1,1) inside the given polygon:</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-size: 12pt; font-family: Consolas, Courier, monospace;"> </span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<p style="margin: 0px; font: 12px Menlo; margin: 0px"><span style="font-size: 12pt; font-family: Consolas, Courier, monospace;">SELECT bounds FROM m_polygon;</span></p>
<span style="font-size: 12pt; font-family: Consolas, Courier, monospace;">((0,0),(0,10),(10,0),(10,10),(0,0))</span><br>
</div>
<div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> on behalf of Michael Lubinsky <mlubinsky@hotmail.com><br>
<b>Sent:</b> Wednesday, August 7, 2019 6:08 PM<br>
<b>To:</b> PostGIS Users Discussion <postgis-users@lists.osgeo.org><br>
<b>Subject:</b> Re: [postgis-users] Issue with ST_WITHIN</font>
<div> </div>
</div>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt">I understand now what the core issue is what I am trying feed POLYGON type to ST_WITHIN which expects the GEOMETRY type.</span><br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="margin:0px; font-size:12pt; font-family:Calibri,Helvetica,sans-serif; background-color:rgb(255,255,255)">
Given what I cannot change the table column type from POLYGON to GEOMETRY<br>
is it possible to cast POLYGON to GEOMETRY inside SQL:</div>
<div style="margin:0px; font-size:12pt; font-family:Calibri,Helvetica,sans-serif; background-color:rgb(255,255,255)">
<br>
</div>
<div style="margin:0px; font-size:12pt; font-family:Calibri,Helvetica,sans-serif; background-color:rgb(255,255,255)">
<pre style="margin:0px 0px 1em; padding:12px 8px; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; width:auto; max-height:600px; overflow:auto; background-color:rgb(239,240,241); border-radius:3px; color:rgb(36,39,41); text-align:left"><code style="margin:0px; background-color:rgb(239,240,241)">SELECT ST_WITHIN(CAST(bounds as GEOMETRY) , CAST(bounds as GEOMETRY) ) FROM m_polygon;</code></pre>
Thanks!</div>
<br>
<br>
</div>
<div>
<div id="x_appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> on behalf of Darafei "KomÑpa" Praliaskouski <me@komzpa.net><br>
<b>Sent:</b> Monday, August 5, 2019 11:57 PM<br>
<b>To:</b> PostGIS Users Discussion <postgis-users@lists.osgeo.org><br>
<b>Subject:</b> Re: [postgis-users] Issue with ST_WITHIN</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi,
<div><br>
</div>
<div>The issue is indeed you are using Postgres polygons instead of PostGIS polygons. ST_MakePoint (note ST_ prefix) builds a postgis point.<br>
Non-working countertpart would be this:<br>
<font color="#000000" face="monospace">SELECT ST_WITHIN('(1,1)'::point, '(1,1)'::point ) ;            </font></div>
<span style="font-family:monospace"><br>
</span></div>
<br>
<div class="x_x_gmail_quote">
<div dir="ltr" class="x_x_gmail_attr">On Tue, Aug 6, 2019 at 7:37 AM Michael Lubinsky <<a href="mailto:mlubinsky@hotmail.com">mlubinsky@hotmail.com</a>> wrote:<br>
</div>
<blockquote class="x_x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<p style="margin-top: 0px; margin-bottom: 0px;margin:0px 0px 1em; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; clear:both; color:rgb(36,39,41); text-align:left; background-color:rgb(255,255,255)">
Environment: PostgreSQL 11.4 with PostGIS 2.5.2</p>
<pre style="margin:0px 0px 1em; padding:12px 8px; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; width:auto; max-height:600px; overflow:auto; background-color:rgb(239,240,241); border-radius:3px; color:rgb(36,39,41); text-align:left"><code style="margin:0px; background-color:rgb(239,240,241)">CREATE TABLE m_polygon (id SERIAL PRIMARY KEY, bounds POLYGON);
INSERT INTO m_polygon(bounds) VALUES( 
  '(0.0, 0.0),  (0.0, 10.0), (10.0, 0.0), (10.0, 10.0), (0,0)' 
);

SELECT ST_WITHIN(m_polygon.bounds , m_polygon.bounds ) FROM m_polygon;
</code></pre>
<p style="margin-top: 0px; margin-bottom: 0px;margin:0px 0px 1em; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; clear:both; color:rgb(36,39,41); text-align:left; background-color:rgb(255,255,255)">
I am getting the error message for SELECT statement above:</p>
<pre style="margin:0px 0px 1em; padding:12px 8px; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; width:auto; max-height:600px; overflow:auto; background-color:rgb(239,240,241); border-radius:3px; color:rgb(36,39,41); text-align:left"><code style="margin:0px; background-color:rgb(239,240,241)">ERROR:  function st_within(polygon, polygon) does not exist 
HINT:  No function matches the given name and argument types. You might 
need to add explicit type casts
</code></pre>
<p style="margin-top: 0px; margin-bottom: 0px;margin:0px 0px 1em; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; clear:both; color:rgb(36,39,41); text-align:left; background-color:rgb(255,255,255)">
I was thinking what the reason for the error is: the ST_WITHIN arguments types should be GEOMETRY, but I am passing the POLYGONs.</p>
<p style="margin-top: 0px; margin-bottom: 0px;margin:0px 0px 1em; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; clear:both; color:rgb(36,39,41); text-align:left; background-color:rgb(255,255,255)">
However the following works:</p>
<pre style="margin:0px 0px 1em; padding:12px 8px; font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif; font-size:13px; width:auto; max-height:600px; overflow:auto; background-color:rgb(239,240,241); border-radius:3px; color:rgb(36,39,41); text-align:left"><code style="margin:0px; background-color:rgb(239,240,241)">SELECT ST_WITHIN(ST_MakePoint(1,1), ST_MakePoint(1,1) ) ;</code></pre>
Thanks! </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Michael</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>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_x_gmail_signature">
<div dir="ltr">
<div>
<div>Darafei Praliaskouski</div>
<div>Support me: <a href="http://patreon.com/komzpa" target="_blank">http://patreon.com/komzpa</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>