openlink / virtuoso-opensource

Virtuoso is a high-performance and scalable Multi-Model RDBMS, Data Integration Middleware, Linked Data Deployment, and HTTP Application Server Platform
https://vos.openlinksw.com
Other
854 stars 211 forks source link

Use of OGC WKT literals #1314

Open ebremer opened 3 weeks ago

ebremer commented 3 weeks ago

Is it sufficient enough to use Virtuoso geosparql operators if the only portion of geosparql I use are the WKT literals?

Example data

_:oddthing private:weirdthing "POINT(2 2)"^^geo:wktLiteral .

Would then, a query like this work, as in _:oddthing would be selected by the filter?

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX private: <http://dontknow.com/ns/>

SELECT ?s WHERE {
  ?s private:weirdthing ?wkt .
  FILTER(geof:distance(?wkt, "POINT(0 0)"^^geo:wktLiteral) < 10)
}
HughWilliams commented 3 weeks ago

Looks almost OK, although when run, your query gives an error: Virtuoso 22003 Error SR030: Too few (only 2) arguments for GEOS silent SRS distance. This is because the geof:distance function call needs a third parameter, for the unit of measurement to be used, as in the example on the Virtuoso GeoSPARQL Demo Server, i.e.,

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX private: <http://dontknow.com/ns/>
PREFIX units: <http://www.opengis.net/def/uom/OGC/1.0/>

SELECT ?s WHERE {
  ?s private:weirdthing ?wkt .
  FILTER(geof:distance(?wkt, "POINT(0 0)"^^geo:wktLiteral, units:meter) < 10)
}
ebremer commented 3 weeks ago

Thanks for fixing the query, and in fixing it, can I assume the answer is then yes to my question --> "Will Virtuoso's GeoSPARQL functions work on just the WKT literals without any other use of GeoSPARQL properties?" The reason I ask, is that the FHIR RDF group has been discussing an RDF representation of DICOM data. There are some DICOM tags which represent polygonal data. Under DICOM, this data is an ordered sequence of floats, and treating it as an rdf:List of floats isn't particularly useful in RDF for this type of data (https://github.com/w3c/hcls-fhir-rdf/issues/149). We've discussed reformulating those fields that contain polygonal data as a WKT, as it aligns with WKT use in GeoSPARQL, and better yet, will be able to take advantage of Virtuoso's spatial indexing support via GeoSPARQL.

HughWilliams commented 3 weeks ago

Yes, that should work ...

ebremer commented 7 hours ago

Hi @HughWilliams , Im testing this out not. How can I confirm I have the geosparql functions loaded because I am getting a:

Virtuoso 37000 Error SP031: SPARQL compiler: Unknown function http://www.opengis.net/def/function/geosparql/distance

I did add the plugins in the plugins section of the virtuoso.ini file and compiled and installed proj code.

ebremer commented 7 hours ago

I forgot the geo library. Now throwing:

Virtuoso 22003 Error SR030: Too few (only 2) arguments for GEOS silent SRS distance.
ebremer commented 7 hours ago

I added the units:meter and got further with a different error:

Virtuoso 22023 Error GEOxx: The function "GEOS silent SRS distance"() requires access to data about spatial reference systems in order to process geometry with SRID 4326; please try plugin "proj4" or similar

SPARQL query:
define sql:big-data-const 0
#output-format:text/html
define sql:signal-void-variables 1
define input:default-graph-uri <https://halcyon.is/geosparql>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX odd: <https://halcyon.is/geosparql/ns/>
PREFIX units: <http://www.opengis.net/def/uom/OGC/1.0/>
PREFIX : <https://halcyon.is/geosparql/>
select * 
where {
?s :odd ?wkt
FILTER(geof:distance(?wkt, "POINT(0 0)"^^geo:wktLiteral, units:meter ) < 10)
}

here is my sample data:

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX odd: <https://halcyon.is/geosparql/ns/>
PREFIX : <https://halcyon.is/geosparql/>
INSERT DATA
{ 
  graph <https://halcyon.is/geosparql> {
        :thing1 :odd "POINT(0 0)"^^geo:wktLiteral .
        :thing2 :odd "POINT(1 0)"^^geo:wktLiteral .
        :thing3 :odd "POINT(0 1)"^^geo:wktLiteral .
        :thing4 :odd "POINT(100 0)"^^geo:wktLiteral .
        :thing5 :odd "POINT(0 100)"^^geo:wktLiteral .
        :thing6 :odd "POINT(100 100)"^^geo:wktLiteral .
        :thing7 :odd "POINT(33 22)"^^geo:wktLiteral .
        :thing8 :odd "POINT(84 43)"^^geo:wktLiteral .
        :thing9 :odd "POINT(5 5)"^^geo:wktLiteral .
        :thing10 :odd "POINT(94 24)"^^geo:wktLiteral .
        :center :odd "POINT(50 50)"^^geo:wktLiteral 
    }
}
HughWilliams commented 2 hours ago

Loading the. data your query runs against my Virtuoso open source instance via the SPARQL endpoint or isql:

SQL> SPARQL PREFIX geo: <http://www.opengis.net/ont/geosparql#> PREFIX geof: <http://www.opengis.net/def/function/geosparql/> PREFIX odd: <https://halcyon.is/geosparql/ns/> PREFIX units: <http://www.opengis.net/def/uom/OGC/1.0/> PREFIX : <https://halcyon.is/geosparql/> select *  where { ?s :odd ?wkt FILTER(geof:distance(?wkt, "POINT(0 0)"^^geo:wktLiteral, units:meter ) < 10) };
s                                                                                 wkt
LONG VARCHAR                                                                      LONG VARCHAR
_______________________________________________________________________________

https://halcyon.is/geosparql/thing1                                               POINT(0 0)

1 Rows. -- 1 msec.
SQL>

The error reported implies the "proj4" plugin could not be accessed, thus if you check the "virtuoso.log" when the server startup is occurring is the proj4 plugin actually loading successfully ? You should see something like:

17:01:06 { Loading plugin 8: Type `plain', file `proj4' in `../hosting'
17:01:06   plain version 1.1.3239 from OpenLink Software
17:01:06   Cartographic Projections support based on Frank Warmerdam's proj4 library
17:01:06   SUCCESS plugin 8: loaded from ../hosting/proj4.so }
17:01:06 { Loading plugin 9: Type `plain', file `geos' in `../hosting'
17:01:06   plain version 1.2.3239 from OpenLink Software
17:01:06   GEOS plugin based on Geometry Engine Open Source library from Open Source Geospatial Foundation
17:01:06   SUCCESS plugin 9: loaded from ../hosting/geos.so }
17:01:06 { Loading plugin 10: Type `plain', file `shapefileio' in `../hosting'
17:01:06   ShapefileIO version 0.1virt71 from OpenLink Software
17:01:06   Shapefile support based on Frank Warmerdam's Shapelib
17:01:06   SUCCESS plugin 10: loaded from ../hosting/shapefileio.so }