I have a table which contains GPS coordinates at certain times. I created a
LINESTRING from them ordered from the oldest to newest.
I also have a
POLYGON and I would like to determine the subset of my
LINESTRING which lies inside my polygon. This subset should be only the points from the table - no interpolated points from the linestring. All my geometries have SRID 4326.
I used the
ST_Intersection(myLinestring,myPolygon). Because the linestring goes in and out of the polygon multiple times I expect the intersection will be
GEOMETRYCOLLECTION of multiple
LINESTRINGs (which correspond to the individual continuous components of the path inside my polygon).
As a quick check to determine the number of components inside I ran:
ST_NumGeometries(ST_Intersection(myLinestring,myPolygon)) but I got some really big number which actually exceeds even the number of coordinates in my table.
When I ran
ST_AsText(ST_Intersection(myLinestring,myPolygon)) I saw that the result is rather a collection of many individual points which lie inside the polygon AND the linestring, but they ARE NOT the samples from my table.
How do I do this right?
EDIT: I need to know the connected path components lying inside the polygon, not just the isolated points inside the polygon.
I need to know the inner linestrings so I can determine the total approximate time spent inside the polygon (the time differences of the first and last point of the inner path component summed over all those components would give a precise estimate of the time spent inside the polygon).