[postgis-users] problem with points in polygon edge

Greg Troxel gdt at lexort.com
Tue Mar 15 16:08:14 PDT 2022


Gustavo Martinez <gmpuljak at yahoo.com.ar> writes:

> attached you can see an example of the situation. I am interested in
> all the points. The arrow indicates one point that lays on the edge of
> polygon 1 and polygon 2.

Ah, now I understand that you are trying to use polygons that have
overlapping edges and that you further want each point to be assigned to
exactly one polygon.

> If I use st_within(), that point is not counted in either polygon, but
> if I use st_intersects() it is counted in both polygons. For that
> reason, I wrote the function.
> The data comes from a VMS device, that reports the GPS position, along
> speed and vessel ID with a fixed frequency.
> Hope it is more clear now.

The question is then what you are really trying to do.   If you are
trying to count all the points in the union of some polygons, you can
union the polygons and then count.  If you want to know how many points
are in each polygon, with a definition of "in" that says

  a point is in a polygon if it is really in it, or if it is on the
  boundary and the point is not in some other polygon sharing the
  boundary, however it is arbitrary which polygon the piont is
  considered to be in
   with the stipulation that polygons do not really overlap, but just
   touch at outer edges.

You might consider a function that assigns points to polygons, perhaps
taking the first member of selecting all polygons such that
ST_Intersects(point, polygon) and assigning that in a table of points
and assigned polygons, and then using that for your statistics.

I guess you could also think about a function like ST_HalfOpenIntersect but
that somehow treats each edge as either a closed or open interval
depending on angle, so that points on shared edges would end up matching
one and not the other.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20220315/59c45c5e/attachment.sig>


More information about the postgis-users mailing list