[postgis-users] Issue with ST_WITHIN

Michael Lubinsky mlubinsky at hotmail.com
Wed Aug 7 18:08:59 PDT 2019


I understand now what the core issue is what I am trying feed POLYGON type to ST_WITHIN which expects the GEOMETRY type.
Given what I cannot change the table column type from POLYGON to GEOMETRY
is it possible to cast POLYGON to GEOMETRY inside SQL:


SELECT ST_WITHIN(CAST(bounds as GEOMETRY) , CAST(bounds as GEOMETRY) ) FROM m_polygon;

Thanks!



________________________________
From: postgis-users <postgis-users-bounces at lists.osgeo.org> on behalf of Darafei "Komяpa" Praliaskouski <me at komzpa.net>
Sent: Monday, August 5, 2019 11:57 PM
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
Subject: Re: [postgis-users] Issue with ST_WITHIN

Hi,

The issue is indeed you are using Postgres polygons instead of PostGIS polygons. ST_MakePoint (note ST_ prefix) builds a postgis point.
Non-working countertpart would be this:
SELECT ST_WITHIN('(1,1)'::point, '(1,1)'::point ) ;


On Tue, Aug 6, 2019 at 7:37 AM Michael Lubinsky <mlubinsky at hotmail.com<mailto:mlubinsky at hotmail.com>> wrote:

Environment: PostgreSQL 11.4 with PostGIS 2.5.2

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;


I am getting the error message for SELECT statement above:

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


I was thinking what the reason for the error is: the ST_WITHIN arguments types should be GEOMETRY, but I am passing the POLYGONs.

However the following works:

SELECT ST_WITHIN(ST_MakePoint(1,1), ST_MakePoint(1,1) ) ;

Thanks!
Michael
_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org<mailto:postgis-users at lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/postgis-users


--
Darafei Praliaskouski
Support me: http://patreon.com/komzpa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20190808/5403afa9/attachment.html>


More information about the postgis-users mailing list