Did you mean to have this:
tdb:unionDefaultGraph true ;
The default graph of the data store will be the union of *named* graphs
so if you loaded your data into the default grtaph it will be hidden.
Try a simpler query to see if the spatial index is active:
SELECT * {
?place spatial:nearby (51.38 -2.7 10 'km') .
}
On 25/07/14 19:33, Luigi Selmi wrote:
Hi all,
I wanted to make some interesting query with spatial data but I couldn't make
it work with jena so far. I've read the documentation about the support
available in Jena for spatial searches and it seems I can make SPARQL queries
to know what locations are within a circle around a given position, if a
location is inside a box area and some other. I wrote an assembler file (shown
below) to set fuseki, jena TDB and the Lucene spatial index. I started
importing some triples with geographical data (shown below), points and
polygons, in my dataset using tdbloader and the assembler file running the
command
$tdbloader --loc Store/fusepoolp3/ spatial-data.ttl
After that I run the indexer running the command
$java jena.spatialindexer --desc=jena-spatial-assembler.ttl
and I got the message
INFO 36 (36 per second) properties indexed
I checked that the indexer based on Lucene had created its index files in the
folder defined in the assembler file. After this I have started fuseki using
the same assembler file and tried the following query to search for locations
within a circle of 10 km from a position close to the Bristol International
Airport (lat: 51.3827, long: -2.71909)
PREFIX spatial: <http://jena.apache.org/spatial#>PREFIX rdfs:
<http://www.w3.org/2000/01/rdf-schema#>
SELECT ?placeName { ?place spatial:nearby (51.38 -2.7 10 'km') . ?place
rdfs:label ?placeName}
The response was
---------------------------------------------------------------------| placeName
|===========================================| "Birmingham International Airport" || "Birmingham International Airport (wktLiteral)"
|| "Birmingham International Airport (wktLiteral_2)" | | "Cardiff International Airport" || "Bristol International
Airport" || "London Gatwick Airport" || "Roma Fiumicino Airport"
|| "London Stansted Airport" || "Fake in Box Airport (wktLiteral)" ||
"Fake out of Box Airport (wktLiteral)" |--------------------------------------------------------------------
That is, also locations far from the reference position have been included like
the airport of Rome (lat: 41.7998, long 12.2469). This result must be related
with the following log message of Fuseki
20:12:33 WARN Failed to find the spatial index : tried context and as a
spatial-enabled dataset20:12:33 WARN No text index - no text search performed
but as I started fuseki using the same assembler file used to import the data I
can't figure out why it's not able to find the index. I add below the content
of the assembler file and the data file.
=============================================== Assembler File
=======================================## Example of a TDB dataset and spatial
index
@prefix : <http://localhost/jena_example/#> .@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 spatial: <http://jena.apache.org/spatial#> .@prefix
fuseki: <http://jena.apache.org/fuseki#> .
#Fuseki[] rdf:type fuseki:Server ;fuseki:services ( <#service_spatial_tdb>) .
<#service_spatial_tdb> rdf:type fuseki:Service ; rdfs:label "TDB/spatial service" ; fuseki:name
"ds" ; fuseki:serviceQuery "query" ; fuseki:serviceQuery "sparql" ; fuseki:serviceUpdate
"update" ; fuseki:serviceUpload "upload" ; fuseki:serviceReadGraphStore "get" ;
fuseki:serviceReadWriteGraphStore "data" ; fuseki:dataset :spatial_dataset ; .
# TDB[] ja:loadClass "com.hp.hpl.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:SpatialtDataset 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
<#fusepoolp3> ; spatial:index <#indexLucene> ; .
<#fusepoolp3> rdf:type tdb:DatasetTDB ; tdb:location
"/home/luigi/jena/apache-jena-2.11.1/Store/fusepoolp3" ; tdb:unionDefaultGraph
true ; .
<#indexLucene> a spatial:SpatialIndexLucene ; spatial:directory
<file:/home/luigi/jena/apache-jena-2.11.1/lucene> ; #spatial:directory "mem" ;
spatial:definition <#definition> ; .
<#definition> a spatial:EntityDefinition ; spatial:entityField "uri" ; spatial:geoField
"geo" ; # custom SpatialContextFactory for 2) Well Known Text Literal
spatial:spatialContextFactory "com.spatial4j.core.context.jts.JtsSpatialContextFactory" .
============================= RDF Data (turtle) =================================================@prefix rdf:
<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .@prefix xsd:
<http://www.w3.org/2001/XMLSchema#> .@prefix dbp: <http://dbpedia.org/resource/> .@prefix airports:
<http://airports.dataincubator.org/airports/> .@prefix airports_sc: <http://airports.dataincubator.org/schema/>
.@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .@prefix ogc: <http://www.opengis.net/ont/geosparql#> .
airports:EGBB rdf:type airports_sc:LargeAirport ; geo:lat "52.4539"^^xsd:float ; geo:long
"-1.74803"^^xsd:float ; rdfs:label "Birmingham International Airport" .
airports:EGBB_WKT rdf:type airports_sc:LargeAirport ; ogc:asWKT "POINT(-1.74803
52.4539)"^^ogc:wktLiteral ; rdfs:label "Birmingham International Airport
(wktLiteral)" .
airports:EGBB_WKT_2 rdf:type airports_sc:LargeAirport ; ogc:asWKT "POINT(-1.74803
52.4539)"^^ogc:wktLiteral ; rdfs:label "Birmingham International Airport
(wktLiteral_2)" .
airports:EGFF rdf:type airports_sc:LargeAirport ; geo:lat "51.3967"^^xsd:float ; geo:long
"-3.34333"^^xsd:float ; rdfs:label "Cardiff International Airport" .
airports:EGGD rdf:type airports_sc:LargeAirport ; geo:lat "51.3827"^^xsd:float ; geo:long
"-2.71909"^^xsd:float ; rdfs:label "Bristol International Airport" .
airports:EGKK rdf:type airports_sc:LargeAirport ; geo:lat "51.1481"^^xsd:float ; geo:long
"-0.190278"^^xsd:float ; rdfs:label "London Gatwick Airport" .
airports:FMO rdf:type airports_sc:LargeAirport ; geo:lat "41.7998"^^xsd:float ; geo:long
"12.2469"^^xsd:float ; rdfs:label "Roma Fiumicino Airport" .
airports:EGSS rdf:type airports_sc:LargeAirport ; geo:lat "51.885"^^xsd:float ; geo:long
"0.235"^^xsd:float ; rdfs:label "London Stansted Airport" .
airports:EGBB_Fake_In_Box rdf:type airports_sc:LargeAirport ; ogc:asWKT "Polygon ((-2.0000
51.2000, 1.0000 51.2000, 1.0000 51.8000, -2.0000 51.8000, -2.0000 51.2000))"^^ogc:wktLiteral ;
rdfs:label "Fake in Box Airport (wktLiteral)" .
airports:EGBB_Fake_out_of_Box rdf:type airports_sc:LargeAirport ; ogc:asWKT "Polygon
((-2.0000 50.2000, 1.0000 50.2000, 1.0000 50.8000, -2.0000 50.8000, -2.0000
50.2000))"^^ogc:wktLiteral ; rdfs:label "Fake out of Box Airport (wktLiteral)"
.