18
18
19
19
package org .apache .jena .geosparql .assembler ;
20
20
21
- import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .*;
21
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pApplyDefaultGeometry ;
22
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pDataset ;
23
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pIndexEnabled ;
24
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pIndexExpiries ;
25
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pIndexSizes ;
26
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pInference ;
27
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pQueryRewrite ;
28
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pSpatialIndexFile ;
29
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pSpatialIndexPerGraph ;
30
+ import static org .apache .jena .geosparql .assembler .VocabGeoSPARQL .pSrsUri ;
22
31
import static org .apache .jena .sparql .util .graph .GraphUtils .getBooleanValue ;
23
32
24
33
import java .io .IOException ;
34
43
import org .apache .jena .geosparql .configuration .GeoSPARQLOperations ;
35
44
import org .apache .jena .geosparql .configuration .SrsException ;
36
45
import org .apache .jena .geosparql .spatial .SpatialIndexException ;
46
+ import org .apache .jena .geosparql .spatial .index .v2 .SpatialIndexUtils ;
37
47
import org .apache .jena .graph .Graph ;
38
48
import org .apache .jena .graph .Node ;
39
49
import org .apache .jena .query .Dataset ;
@@ -117,9 +127,21 @@ public DatasetGraph createDataset(Assembler a, Resource root) {
117
127
if (root .hasProperty (pSpatialIndexFile ) )
118
128
spatialIndexFilename = GraphUtils .getStringValue (root , pSpatialIndexFile );
119
129
120
- // ---- Build
130
+ // spatial index per named graph option
131
+ boolean spatialIndexPerGraph = false ;
132
+ if (root .hasProperty (pSpatialIndexPerGraph ) )
133
+ spatialIndexPerGraph = getBooleanValue (root , pSpatialIndexPerGraph );
134
+
135
+ // SRS URI
136
+ String srsURI = null ;
137
+ if (root .hasProperty (pSrsUri ) )
138
+ srsURI = GraphUtils .getStringValue (root , pSrsUri );
121
139
140
+
141
+ // ---- Build
122
142
Dataset dataset = DatasetFactory .wrap (base );
143
+ dataset .getContext ().set (SpatialIndexUtils .symSpatialIndexPerGraph , spatialIndexPerGraph );
144
+ dataset .getContext ().set (SpatialIndexUtils .symSrsUri , srsURI );
123
145
124
146
// Conversion of data. Startup-only.
125
147
// needed for w3c:geo/wgs84_pos#lat/log.
@@ -142,13 +164,13 @@ public DatasetGraph createDataset(Assembler a, Resource root) {
142
164
//Setup GeoSPARQL
143
165
if (indexEnabled ) {
144
166
GeoSPARQLConfig .setupMemoryIndex (indexSizes .get (0 ), indexSizes .get (1 ), indexSizes .get (2 ),
145
- (long )indexExpiries .get (0 ), (long )indexExpiries .get (1 ), (long )indexExpiries .get (2 ),
146
- queryRewrite );
167
+ (long )indexExpiries .get (0 ), (long )indexExpiries .get (1 ), (long )indexExpiries .get (2 ),
168
+ queryRewrite );
147
169
} else {
148
170
GeoSPARQLConfig .setupNoIndex (queryRewrite );
149
171
}
150
172
151
- prepareSpatialExtension (dataset , spatialIndexFilename );
173
+ prepareSpatialExtension (dataset , spatialIndexFilename , spatialIndexPerGraph );
152
174
return base ;
153
175
}
154
176
@@ -165,8 +187,8 @@ private static List<Integer> getListInteger(Resource r, Property p, int len) {
165
187
return integerList ;
166
188
}
167
189
168
- private static void prepareSpatialExtension (Dataset dataset , String spatialIndex ){
169
- boolean isEmpty = dataset .calculateRead (()-> dataset . isEmpty () );
190
+ private static void prepareSpatialExtension (Dataset dataset , String spatialIndex , boolean spatialIndexPerGraph ){
191
+ boolean isEmpty = dataset .calculateRead (dataset :: isEmpty );
170
192
if ( isEmpty && spatialIndex != null ) {
171
193
LOG .warn ("Dataset empty. Spatial Index not constructed. Server will require restarting after adding data and any updates to build Spatial Index." );
172
194
return ;
@@ -185,12 +207,12 @@ private static void prepareSpatialExtension(Dataset dataset, String spatialIndex
185
207
// file given but empty -> compute and serialize index
186
208
Path spatialIndexPath = Path .of (spatialIndex );
187
209
if ( ! Files .exists (spatialIndexPath ) || Files .size (spatialIndexPath ) == 0 ) {
188
- GeoSPARQLConfig .setupSpatialIndex (dataset , spatialIndexPath . toFile () );
210
+ GeoSPARQLConfig .setupSpatialIndex (dataset , spatialIndexPath , spatialIndexPerGraph );
189
211
return ;
190
212
}
191
213
192
214
// load and setup the precomputed index
193
- GeoSPARQLConfig .setupPrecomputedSpatialIndex (dataset , spatialIndexPath . toFile () );
215
+ GeoSPARQLConfig .setupPrecomputedSpatialIndex (dataset , spatialIndexPath );
194
216
}
195
217
catch (SrsException ex ) {
196
218
// Data but no spatial data.
0 commit comments