<div dir="ltr"><div dir="ltr"><div>Your geometry is invalid, as the vertex (10, 0)</div><div>occurs before (10, 10).</div><div><br></div><div>    select st_isvalid('((0,0),(0,10),(10,0),(10,10),(0,0))'::polygon::geometry);</div><div>    --returns false<br></div></div><div><br></div><div>Your polygon looks like this :<br></div><div>  _<br></div><div>|\  /<br></div><div>|/_\</div><div><br></div><div>(Sorry for the bad ascii art)<br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 8 août 2019 à 03:30, Michael Lubinsky <<a href="mailto:mlubinsky@hotmail.com">mlubinsky@hotmail.com</a>> a écrit :<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 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="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="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="font:12px Menlo;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="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="gmail-m_2015754300147824201appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_2015754300147824201divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> postgis-users <<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>> on behalf of Michael Lubinsky <<a href="mailto:mlubinsky@hotmail.com" target="_blank">mlubinsky@hotmail.com</a>><br>
<b>Sent:</b> Wednesday, August 7, 2019 6:08 PM<br>
<b>To:</b> PostGIS Users Discussion <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>><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="gmail-m_2015754300147824201x_appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_2015754300147824201x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> postgis-users <<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>> on behalf of Darafei "Komяpa" Praliaskouski <<a href="mailto:me@komzpa.net" target="_blank">me@komzpa.net</a>><br>
<b>Sent:</b> Monday, August 5, 2019 11:57 PM<br>
<b>To:</b> PostGIS Users Discussion <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>><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 face="monospace" color="#000000">SELECT ST_WITHIN('(1,1)'::point, '(1,1)'::point ) ;            </font></div>
<span style="font-family:monospace"><br>
</span></div>
<br>
<div class="gmail-m_2015754300147824201x_x_gmail_quote">
<div dir="ltr" class="gmail-m_2015754300147824201x_x_gmail_attr">On Tue, Aug 6, 2019 at 7:37 AM Michael Lubinsky <<a href="mailto:mlubinsky@hotmail.com" target="_blank">mlubinsky@hotmail.com</a>> wrote:<br>
</div>
<blockquote class="gmail-m_2015754300147824201x_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: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: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: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: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="gmail-m_2015754300147824201x_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>
</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></div>