I'm using Version 7.2.8.3235-pthreads of Virtuoso Open Source Edition with Docker.

I'm using GeoSPARQL with function `bif:st_within` in order to find which set of points are enclosed in a set of polygons. Apparently it works, but I've found lots of false positives, i.e. a point may be assigned to several polygons that are not overlapped.

I've isolated the problem in the attached turtle file, containing a plot with a point geometry and two municipalities, each one with a polygon geometry. The attached pdf shows a map the two municipalities (01042 and 48045) and the plot (yellow point).

I've tried this query:

```
select distinct ?plot ?muni where {
?plot a <http://prueba.es/Plot> ;
   <http://www.opengis.net/ont/geosparql#asWKT> ?wktp .
?muni a <http://prueba.es/Municipality> ;
    <http://www.opengis.net/ont/geosparql#asWKT> ?wktm .   
FILTER ( bif:st_contains( ?wktm, ?wktp ) ) 
}
```
And I get these results:

```
plot | muni
-- | --
http://prueba.es/plot/01-0002-A-4C | http://prueba.es/municipality/01042
http://prueba.es/plot/01-0002-A-4C | http://prueba.es/municipality/48045
```
I've also tried with `bif:st_within` instead of  `bif:st_contains` with the same result.

Then, I've tried a new query using `bif:st_point` to create a point with the same coordinates of the plot:

```
select distinct ?muni where {
?muni a <http://prueba.es/Municipality> ;
    <http://www.opengis.net/ont/geosparql#asWKT> ?wktm .   
FILTER ( bif:st_contains( ?wktm, bif:st_point(-3.02588, 43.206889) ) ) 
}
```
Now I get the correct result:

```
muni
--
http://prueba.es/municipality/01042
```

But if I try the previous query with `bif:st_within` as in:

```
select distinct ?muni where {
?muni a <http://prueba.es/Municipality> ;
    <http://www.opengis.net/ont/geosparql#asWKT> ?wktm .   
FILTER ( bif:st_within( bif:st_point(-3.02588, 43.206889), ?wktm ) ) 
}
```
Then I've obtained again a false positive:
```
muni
--
http://prueba.es/municipality/01042
http://prueba.es/municipality/48045
```

In conclusion, the functioning of functions `bif:st_within` and `bif:st_contains` looks buggy to me. I hope it can be fixed.


[pruebageo.txt](https://github.com/openlink/virtuoso-opensource/files/10492293/pruebageo.txt)

[map.pdf](https://github.com/openlink/virtuoso-opensource/files/10492303/map.pdf)

GeoSPARQL: false positives finding points inside polygons (st_within and st_contains)
This is a GitHub Issue
repo:virtuoso-opensource
owner:openlink
Title : GeoSPARQL: false positives finding points inside polygons (st_within and st_contains)
Issue date:

--- start body ---
I'm using Version 7.2.8.3235-pthreads of Virtuoso Open Source Edition with Docker.

I'm using GeoSPARQL with function `bif:st_within` in order to find which set of points are enclosed in a set of polygons. Apparently it works, but I've found lots of false positives, i.e. a point may be assigned to several polygons that are not overlapped.

I've isolated the problem in the attached turtle file, containing a plot with a point geometry and two municipalities, each one with a polygon geometry. The attached pdf shows a map the two municipalities (01042 and 48045) and the plot (yellow point).

I've tried this query:

```
select distinct ?plot ?muni where {
?plot a <http://prueba.es/Plot> ;
   <http://www.opengis.net/ont/geosparql#asWKT> ?wktp .
?muni a <http://prueba.es/Municipality> ;
    <http://www.opengis.net/ont/geosparql#asWKT> ?wktm .   
FILTER ( bif:st_contains( ?wktm, ?wktp ) ) 
}
```
And I get these results:

```
plot | muni
-- | --
http://prueba.es/plot/01-0002-A-4C | http://prueba.es/municipality/01042
http://prueba.es/plot/01-0002-A-4C | http://prueba.es/municipality/48045
```
I've also tried with `bif:st_within` instead of  `bif:st_contains` with the same result.

Then, I've tried a new query using `bif:st_point` to create a point with the same coordinates of the plot:

```
select distinct ?muni where {
?muni a <http://prueba.es/Municipality> ;
    <http://www.opengis.net/ont/geosparql#asWKT> ?wktm .   
FILTER ( bif:st_contains( ?wktm, bif:st_point(-3.02588, 43.206889) ) ) 
}
```
Now I get the correct result:

```
muni
--
http://prueba.es/municipality/01042
```

But if I try the previous query with `bif:st_within` as in:

```
select distinct ?muni where {
?muni a <http://prueba.es/Municipality> ;
    <http://www.opengis.net/ont/geosparql#asWKT> ?wktm .   
FILTER ( bif:st_within( bif:st_point(-3.02588, 43.206889), ?wktm ) ) 
}
```
Then I've obtained again a false positive:
```
muni
--
http://prueba.es/municipality/01042
http://prueba.es/municipality/48045
```

In conclusion, the functioning of functions `bif:st_within` and `bif:st_contains` looks buggy to me. I hope it can be fixed.


[pruebageo.txt](https://github.com/openlink/virtuoso-opensource/files/10492293/pruebageo.txt)

[map.pdf](https://github.com/openlink/virtuoso-opensource/files/10492303/map.pdf)

--- end body ---
