I have a grid line table to use as the blade for splitting my polygon table in PostGIS with a ST_Split method. It works fine but now I want to find which parts of polygons are located within my grid.I thought about using ST_Centroid to find the centroid of split parts and then applying ST_Within. My question is: can I apply these two steps in one SQL query or should I compute centroid first and then use ST_whitin? Or is there anything else to do this? Maybe something like this:
SELECT
gridpoly.*
FROM
(SELECT
st_centroid(gridpoly.geom)
FROM gridpoly) as center
JOIN
( SELECT geom FROM gridline As cells WHERE col=1 AND row=2 ) as line
ON ST_Within(center.geom,line.geom)
The gridpoly table is the result of the split function which contains polygons. But in this code I don't have any column as 'center'.