3

I would like to use the nearby geospatial function which is described as supported here through JENA FUSEKI - https://jena.apache.org/documentation/query/spatial-query.html

I need to build the geospatial Index for the query to work. The instructions are as follows (taken from above link):


Build the TDB dataset:

java -cp $FUSEKI_HOME/fuseki-server.jar tdb.tdbloader --tdb=assembler_file data_file

using the copy of TDB included with Fuseki. Alternatively, use one of the TDB utilities tdbloader or tdbloader2:

$JENA_HOME/bin/tdbloader --loc=directory data_file

then build the spatial index with the jena.spatialindexer:

java -cp jena-spatial.jar jena.spatialindexer --desc=assembler_file


Assuming I knew which file is the assembler file in my FUSEKI folder (I don't), I search for jena-spatial.jar in my latest jena download. Having found it is not there, I search for it and find a copy of the jar here - https://jar-download.com/?detail_search=g%3A%22org.apache.jena%22+AND+a%3A%22jena-spatial%22&search_type=av&a=jena-spatial&p=1

I try running it, but I get the error "Could not find or load main class jena.spatialindexer". I do searchers for jena.spatialindexer and I find a match (cannot post here as at link post limit).

At this point I am wondering would it be possible to make this just a little bit more complicated? You know, I obviously have all the time in the world to search through google trying to figure out these cryptic clues.

In short, if anyone out there has done this before, please could you point out where I am going wrong?

Kindest regards,

Kris.

Kris
  • 63
  • 7
  • 1
    I think they mean `jena-spatial-3.4.0.jar` located in `fuseki.war` (located in your Fuseki distribution). Try `jar xvf fuseki.war "WEB-INF/lib/"` and then `java -cp WEB-INF/lib/* jena.spatialindexer`. The error should be `Multiple assembler descriptions given`. – Stanislav Kralin Aug 24 '17 at 15:11
  • 1
    You need to create an assembler file yourself. There's an example on the same page you link to. – chrisis Aug 25 '17 at 12:51
  • I totally second this question : Is there somewhere a working example of fuseki "data" folder (data+configurations) with a spatial dataset ? The explanations on the doc page pointed in the question are totally cryptic. – daxid Jan 16 '18 at 11:54
  • Any new idea on how to run fuseki with spatial index support? – jlanza Mar 29 '18 at 12:25
  • @jlanza Firstly, many thanks for your effort with this. I tried your recommendations, but I am getting a 'Could not find or load main class org.apache.jena.fuseki.cmd.FusekiCmd' when using the :lib/jts-1.13.jar in the command. Also, are you still using jts-1.13, as the link provided will now direct you to 1.14? – Kris Aug 31 '18 at 08:40
  • I'm sorry but the project I was working with that ended :( so I cannot give you more information. However it seems you are not including `fuseki-server.jar` which if I remember correctly is the one that has the `FusekiCmd`. This should be the reason for not working. JTS is for spatial searchses. – jlanza Aug 31 '18 at 13:10
  • Looks like I was using colon instead of semicolon :) apologies!!! – Kris Sep 04 '18 at 13:07

1 Answers1

0

Just in case it might help, find below my configuration

@prefix fuseki:  <http://jena.apache.org/fuseki#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix :        <#> .

@prefix spatial: <http://jena.apache.org/spatial#> .


# TDB
[] ja:loadClass "org.apache.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

# Spatial
[] ja:loadClass "org.apache.jena.query.spatial.SpatialQuery" .
spatial:SpatialDataset  rdfs:subClassOf  ja:RDFDataset .
#spatial:SpatialIndexSolr  rdfs:subClassOf  spatial:SpatialIndex .
spatial:SpatialIndexLucene  rdfs:subClassOf   spatial:SpatialIndex .

## ---------------------------------------------------------------
## This URI must be fixed - it's used to assemble the spatial dataset.

:spatial_dataset rdf:type     spatial:SpatialDataset ;
    spatial:dataset   <#tdb_dataset_readwrite> ;
    ##spatial:index   <#indexSolr> ;
    spatial:index     <#indexLucene> ;
    .

<#tdb_dataset_readwrite> rdf:type      tdb:DatasetTDB ;
    tdb:location "/myfolder" ;
##     # Query timeout on this dataset (milliseconds)
##     ja:context [ ja:cxtName "arq:queryTimeout" ;  ja:cxtValue "1000" ] ;
##     # Default graph for query is the (read-only) union of all named graphs.
       tdb:unionDefaultGraph true ;
    .

<#indexLucene> a spatial:SpatialIndexLucene ;
    #spatial:directory <file:Lucene> ;
   ## spatial:directory "mem" ;
    spatial:directory <file:/myfolder/spatial> ;
    spatial:definition <#definition> ;
    .

<#definition> a spatial:EntityDefinition ;
    spatial:entityField      "uri" ;
    spatial:geoField     "geo" ;
    # custom geo predicates for 1) Latitude/Longitude Format
    spatial:hasSpatialPredicatePairs (
         [ spatial:latitude :latitude_1 ; spatial:longitude :longitude_1 ]
         [ spatial:latitude :latitude_2 ; spatial:longitude :longitude_2 ]
         ) ;
    # custom geo predicates for 2) Well Known Text (WKT) Literal
    spatial:hasWKTPredicates (:wkt_1 :wkt_2) ;
    # custom SpatialContextFactory for 2) Well Known Text (WKT) Literal
    spatial:spatialContextFactory
         "org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory"
    .
#         "com.spatial4j.core.context.jts.JtsSpatialContextFactory"


<#service_tdb1> rdf:type fuseki:Service ;
    rdfs:label                      "TDB Service" ;
    fuseki:name                     "tdb_spatial" ;
    fuseki:serviceQuery             "query" ;
    fuseki:serviceQuery             "sparql" ;
    fuseki:serviceUpdate            "update" ;
    fuseki:serviceUpload            "upload" ;
    fuseki:serviceReadWriteGraphStore      "data" ;
    # A separate read-only graph store endpoint:
    fuseki:serviceReadGraphStore       "get" ;
    fuseki:dataset                  :spatial_dataset  ;

as you can see I have changed the class name to org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory. Besides when running fuseki I have to include another jar file in the classpath as otherwise I have issues with

EntityDefinitionAssembler WARN  Custom SpatialContextFactory lib is not ready in classpath:com/vividsolutions/jts/geom/CoordinateSequenceFactory

Then my command line looks like:

java -cp "fuseki-server.jar:lib/jts-1.13.jar" org.apache.jena.fuseki.cmd.FusekiCmd -debug

I have downloaded jts-1.13.jar from here

Besides I would like to thank to Kai for pointing me in the right direction.

Note: I still have to fully understand the fields under spatial:EntityDefinition. I will try to edit with more information.

jlanza
  • 1,208
  • 3
  • 23
  • 43
  • You mention a folder called "spatial" for lucene. Can I ask, did you create this yourself, and what should be in this folder? – Kris Sep 04 '18 at 13:56
  • You can try to create if yourself in case it doesn't work. Have in mind that it is '/myfolder/spatial' so it is full path at least in the example. Besides that, if I recall correctly the folder hosts all the files required to mantained the spatial indexes. – jlanza Sep 05 '18 at 07:23