[postgis-users] problem with points in polygon edge

Gustavo Martinez gmpuljak at yahoo.com.ar
Mon Mar 14 06:52:13 PDT 2022


Hi all,

I am working with fishing vessels positions. I have millions of points, 
and when doing some analysis I need to do some intersections with polygons.

All the database is on EPSG 4326 (Lat Long)

I've noticed some problems when the points are on the edges of the 
polygons. When I use ST_Within I lose the points on the edges, while 
when using ST_Intersects those points get counted twice.

To fix that I wrote a function:

CREATE OR REPLACE FUNCTION "monitoreo"."dentro" (punto geometry, rect 
geometry)  RETURNS boolean
   VOLATILE
AS $body$
begin
IF (st_within(punto, rect) OR
(
     st_x(punto)=st_xmax(rect) AND st_y(punto) BETWEEN st_ymin(rect) AND 
st_ymax(rect)
)
OR
(
     st_y(punto)=st_ymax(rect) AND st_x(punto) BETWEEN st_xmin(rect) AND 
st_xmax(rect)
)
) THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
end
$body$ LANGUAGE plpgsql


I have two questions:

1- that function works but it is slow. Do you have suggestions to 
optimize it?

2- the function works for rectangles, do you have an example of how to 
handle irregular polygons?

Many thanks in advance.


-- 

*Gustavo Martínez Puljak*

*
*Linkedin:www.linkedin.com/in/gustavomartinezpuljak 
<https://www.linkedin.com/in/gustavomartinezpuljak>

*
*/Que la tierra se vaya haciendo camino ante tus pasos,//
//que el viento sople siempre a tus espaldas,//
//que el sol brille cálido sobre tu cara,//
//que la lluvia caiga suavemente sobre tus campos y,//
//hasta tanto volvamos a encontrarnos,//
//que Dios te lleve en la palma de su mano./


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20220314/92daa280/attachment.html>


More information about the postgis-users mailing list