<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi Greg,<br>
    </p>
    <div class="moz-cite-prefix">El 15/3/22 a las 20:08, Greg Troxel
      escribió:<br>
    </div>
    <blockquote type="cite" cite="mid:rmifsnistk1.fsf@s1.lexort.com">
      <pre class="moz-quote-pre" wrap="">
Gustavo Martinez <a class="moz-txt-link-rfc2396E" href="mailto:gmpuljak@yahoo.com.ar"><gmpuljak@yahoo.com.ar></a> writes:

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">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.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
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.

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">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.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
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.</pre>
    </blockquote>
    <p>I have two data sources: vessel positions (VMS) and logbooks with
      fish landings for each trip. I developed an algorithm that links
      the catches with some points that show "fishing behaviour". From
      this database (point  based), we get data at different spatial and
      temporal aggregations (polygons). I need to consider all the
      points, either on the boundaries or not. That's why I wrote the
      function, that has a fixed criteria for the selection. The
      question is, can it be optimized? It is quite slow.</p>
    <p>On the other hand, it works for rectangular (lat-long) polygons,
      but I don't know how to obtain this for irregular polygons
      (exclusive economic zones, marine protected areas, etc.)<br>
    </p>
    <blockquote type="cite" cite="mid:rmifsnistk1.fsf@s1.lexort.com">
      <pre class="moz-quote-pre" wrap="">

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.
</pre>
    </blockquote>
    <div class="moz-signature">-- <br>
      <p><font face="monospace"><font style="font-size: 14pt" size="4"><b>Gustavo
              Martínez Puljak</b></font></font></p>
      <p style="margin-bottom: 0cm"><font style="font-size: 14pt"
          size="4"><b><br>
          </b></font><font style="font-size: 10pt" size="2">cel:
          +549 11 64089000</font><br>
        <font face="monospace"><font style="font-size: 10pt" size="2">Linkedin:<a
              href="https://www.linkedin.com/in/gustavomartinezpuljak">www.linkedin.com/in/gustavomartinezpuljak</a></font></font></p>
      <p><b><br>
        </b><font face="monospace"><font style="font-size: 10pt"
            size="2"><i>Que
              la tierra se vaya haciendo camino ante tus pasos,</i></font></font><font
          style="font-size: 10pt" size="2"><i><br>
          </i></font><font face="monospace"><font style="font-size:
            10pt" size="2"><i>que
              el viento sople siempre a tus espaldas,</i></font></font><font
          style="font-size: 10pt" size="2"><i><br>
          </i></font><font face="monospace"><font style="font-size:
            10pt" size="2"><i>que
              el sol brille cálido sobre tu cara,</i></font></font><font
          style="font-size: 10pt" size="2"><i><br>
          </i></font><font face="monospace"><font style="font-size:
            10pt" size="2"><i>que
              la lluvia caiga suavemente sobre tus campos y,</i></font></font><font
          style="font-size: 10pt" size="2"><i><br>
          </i></font><font face="monospace"><font style="font-size:
            10pt" size="2"><i>hasta
              tanto volvamos a encontrarnos,</i></font></font><font
          style="font-size: 10pt" size="2"><i><br>
          </i></font><font face="monospace"><font style="font-size:
            10pt" size="2"><i>que
              Dios te lleve en la palma de su mano.</i></font></font></p>
      <p><br>
        <br>
      </p>
    </div>
  </body>
</html>