I'm using ST_Intersection
function in Postgis with a Multipoint and Polygon geometries and I can't figure out the result of it.
Here an example of my SQL request using ST_Intersection :
SELECT ST_AsText(
ST_Intersection(
ST_GeomFromText('MULTIPOINT(1 1, 1 1)'),
ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')
)
);
Output :
'POINT(1 1)' /* I expected MULTIPOINT(1 1, 1 1) as result */
As we can see ST_Intersection
has removed the duplicates and that's not what I expected
The result is the same for all lib using GEOSlib
In a mathematical approach, let's consider 2 sets of number :
Logically, the intersection of these two sets must return all the numbers included in both even if they are duplicates like this:
S1 = {1, 2, 3, 4}
S2 = {1, 1}
S1 intersection S2 = {1, 1}
So, am I missing something ?
Unlike a Set, a Multiset can contain duplicates elements but the result of an intersection of two multisets is a multiset that contains the minimum multiplicity of an element of both multisets.
For example : {1,1,2,3} intersection {1,2,2,4} = {1,2}
So ST_intersection(Geometry A, Geometry B)
will remove duplicates included in both geometries