Me L.

asked • 08/06/19

Issue with PostGIS ST_WITHIN

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) ) ;


1 Expert Answer

By:

Quang T. answered • 08/07/19

Tutor
4.9 (21)

GIS professional and Engineer with 5+ years of experience

Me L.

I tried, it does not help. The core issue is what ST_WITHIN arguments type should be GEOMETRY. I need to convert POLYGON type into GEOMETRY. The closest function which I found is ST_GeomFromText() http://www.postgis.net/docs/ST_GeomFromText.html but I cannot figure out how to apply it to the POLYGON type which I have in my table.
Report

08/08/19

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.