62
62
*/
63
63
public class SpatialDatabaseService implements Constants {
64
64
65
+ public static final String RTREE_INDEX_NAME = "rtree" ;
66
+ public static final String GEOHASH_INDEX_NAME = "geohash" ;
67
+
65
68
public final IndexManager indexManager ;
66
69
67
70
public SpatialDatabaseService (IndexManager indexManager ) {
@@ -179,30 +182,29 @@ public DynamicLayer asDynamicLayer(Transaction tx, Layer layer) {
179
182
return (DynamicLayer ) LayerUtilities .makeLayerFromNode (tx , indexManager , node );
180
183
}
181
184
182
- public DefaultLayer getOrCreateDefaultLayer (Transaction tx , String name ) {
183
- return (DefaultLayer ) getOrCreateLayer (tx , name , WKBGeometryEncoder .class , EditableLayerImpl .class , "" );
185
+ public DefaultLayer getOrCreateDefaultLayer (Transaction tx , String name , String indexConfig ) {
186
+ return (DefaultLayer ) getOrCreateLayer (tx , name , WKBGeometryEncoder .class , EditableLayerImpl .class , "" ,
187
+ indexConfig );
184
188
}
185
189
186
- public EditableLayer getOrCreateEditableLayer (Transaction tx , String name , String format ,
187
- String propertyNameConfig ) {
190
+ public EditableLayer getOrCreateEditableLayer (Transaction tx , String name , String format , String propertyNameConfig ,
191
+ String indexConfig ) {
188
192
Class <? extends GeometryEncoder > geClass = WKBGeometryEncoder .class ;
189
193
if (format != null && format .toUpperCase ().startsWith ("WKT" )) {
190
194
geClass = WKTGeometryEncoder .class ;
191
195
}
192
- return (EditableLayer ) getOrCreateLayer (tx , name , geClass , EditableLayerImpl .class , propertyNameConfig );
196
+ return (EditableLayer ) getOrCreateLayer (tx , name , geClass , EditableLayerImpl .class , propertyNameConfig ,
197
+ indexConfig );
193
198
}
194
199
195
- public EditableLayer getOrCreateEditableLayer (Transaction tx , String name ) {
196
- return getOrCreateEditableLayer (tx , name , "WKB" , "" );
200
+ public EditableLayer getOrCreateEditableLayer (Transaction tx , String name , String indexConfig ) {
201
+ return getOrCreateEditableLayer (tx , name , "WKB" , "" , indexConfig );
197
202
}
198
203
199
- public EditableLayer getOrCreateEditableLayer (Transaction tx , String name , String wktProperty ) {
200
- return getOrCreateEditableLayer (tx , name , "WKT" , wktProperty );
204
+ public EditableLayer getOrCreateEditableLayer (Transaction tx , String name , String wktProperty , String indexConfig ) {
205
+ return getOrCreateEditableLayer (tx , name , "WKT" , wktProperty , indexConfig );
201
206
}
202
207
203
- public static final String RTREE_INDEX_NAME = "rtree" ;
204
- public static final String GEOHASH_INDEX_NAME = "geohash" ;
205
-
206
208
public static Class <? extends LayerIndexReader > resolveIndexClass (String index ) {
207
209
if (index == null ) {
208
210
return LayerRTreeIndex .class ;
@@ -217,23 +219,25 @@ public static Class<? extends LayerIndexReader> resolveIndexClass(String index)
217
219
}
218
220
219
221
public EditableLayer getOrCreateSimplePointLayer (Transaction tx , String name , String index , String xProperty ,
220
- String yProperty ) {
221
- return getOrCreatePointLayer (tx , name , resolveIndexClass (index ), SimplePointEncoder .class , xProperty ,
222
+ String yProperty , String indexConfig ) {
223
+ return getOrCreatePointLayer (tx , name , resolveIndexClass (index ), SimplePointEncoder .class , indexConfig ,
224
+ xProperty ,
222
225
yProperty );
223
226
}
224
227
225
228
public EditableLayer getOrCreateNativePointLayer (Transaction tx , String name , String index ,
226
- String locationProperty ) {
227
- return getOrCreatePointLayer (tx , name , resolveIndexClass (index ), SimplePointEncoder .class , locationProperty );
229
+ String locationProperty , String indexConfig ) {
230
+ return getOrCreatePointLayer (tx , name , resolveIndexClass (index ), SimplePointEncoder .class , indexConfig ,
231
+ locationProperty );
228
232
}
229
233
230
234
public EditableLayer getOrCreatePointLayer (Transaction tx , String name ,
231
235
Class <? extends LayerIndexReader > indexClass , Class <? extends GeometryEncoder > encoderClass ,
232
- String ... encoderConfig ) {
236
+ String indexConfig , String ... encoderConfig ) {
233
237
Layer layer = getLayer (tx , name );
234
238
if (layer == null ) {
235
239
return (EditableLayer ) createLayer (tx , name , encoderClass , SimplePointLayer .class , indexClass ,
236
- makeEncoderConfig (encoderConfig ), DefaultGeographicCRS .WGS84 );
240
+ makeEncoderConfig (encoderConfig ), indexConfig , DefaultGeographicCRS .WGS84 );
237
241
}
238
242
if (layer instanceof EditableLayer ) {
239
243
return (EditableLayer ) layer ;
@@ -243,10 +247,10 @@ public EditableLayer getOrCreatePointLayer(Transaction tx, String name,
243
247
}
244
248
245
249
public Layer getOrCreateLayer (Transaction tx , String name , Class <? extends GeometryEncoder > geometryEncoder ,
246
- Class <? extends Layer > layerClass , String config ) {
250
+ Class <? extends Layer > layerClass , String encoderConfig , String indexConfig ) {
247
251
Layer layer = getLayer (tx , name );
248
252
if (layer == null ) {
249
- layer = createLayer (tx , name , geometryEncoder , layerClass , null , config );
253
+ layer = createLayer (tx , name , geometryEncoder , layerClass , null , encoderConfig , indexConfig );
250
254
} else if (!(layerClass == null || layerClass .isInstance (layer ))) {
251
255
throw new SpatialDatabaseException (
252
256
"Existing layer '" + layer + "' is not of the expected type: " + layerClass );
@@ -255,8 +259,8 @@ public Layer getOrCreateLayer(Transaction tx, String name, Class<? extends Geome
255
259
}
256
260
257
261
public Layer getOrCreateLayer (Transaction tx , String name , Class <? extends GeometryEncoder > geometryEncoder ,
258
- Class <? extends Layer > layerClass ) {
259
- return getOrCreateLayer (tx , name , geometryEncoder , layerClass , "" );
262
+ Class <? extends Layer > layerClass , String indexConfig ) {
263
+ return getOrCreateLayer (tx , name , geometryEncoder , layerClass , "" , indexConfig );
260
264
}
261
265
262
266
/**
@@ -299,8 +303,8 @@ public boolean containsLayer(Transaction tx, String name) {
299
303
return getLayer (tx , name ) != null ;
300
304
}
301
305
302
- public Layer createWKBLayer (Transaction tx , String name ) {
303
- return createLayer (tx , name , WKBGeometryEncoder .class , EditableLayerImpl .class );
306
+ public Layer createWKBLayer (Transaction tx , String name , String indexConfig ) {
307
+ return createLayer (tx , name , WKBGeometryEncoder .class , EditableLayerImpl .class , indexConfig );
304
308
}
305
309
306
310
public SimplePointLayer createSimplePointLayer (Transaction tx , String name ) {
@@ -312,7 +316,7 @@ public SimplePointLayer createSimplePointLayer(Transaction tx, String name, Stri
312
316
}
313
317
314
318
public SimplePointLayer createSimplePointLayer (Transaction tx , String name , String ... xybProperties ) {
315
- return createPointLayer (tx , name , LayerRTreeIndex .class , SimplePointEncoder .class , xybProperties );
319
+ return createPointLayer (tx , name , LayerRTreeIndex .class , SimplePointEncoder .class , null , xybProperties );
316
320
}
317
321
318
322
public SimplePointLayer createNativePointLayer (Transaction tx , String name ) {
@@ -325,13 +329,14 @@ public SimplePointLayer createNativePointLayer(Transaction tx, String name, Stri
325
329
}
326
330
327
331
public SimplePointLayer createNativePointLayer (Transaction tx , String name , String ... encoderConfig ) {
328
- return createPointLayer (tx , name , LayerRTreeIndex .class , NativePointEncoder .class , encoderConfig );
332
+ return createPointLayer (tx , name , LayerRTreeIndex .class , NativePointEncoder .class , null , encoderConfig );
329
333
}
330
334
331
335
public SimplePointLayer createPointLayer (Transaction tx , String name , Class <? extends LayerIndexReader > indexClass ,
332
- Class <? extends GeometryEncoder > encoderClass , String ... encoderConfig ) {
336
+ Class <? extends GeometryEncoder > encoderClass , String indexConfig , String ... encoderConfig
337
+ ) {
333
338
return (SimplePointLayer ) createLayer (tx , name , encoderClass , SimplePointLayer .class , indexClass ,
334
- makeEncoderConfig (encoderConfig ), org .geotools .referencing .crs .DefaultGeographicCRS .WGS84 );
339
+ makeEncoderConfig (encoderConfig ), indexConfig , org .geotools .referencing .crs .DefaultGeographicCRS .WGS84 );
335
340
}
336
341
337
342
public static String makeEncoderConfig (String ... args ) {
@@ -350,19 +355,27 @@ public static String makeEncoderConfig(String... args) {
350
355
}
351
356
352
357
public Layer createLayer (Transaction tx , String name , Class <? extends GeometryEncoder > geometryEncoderClass ,
353
- Class <? extends Layer > layerClass ) {
354
- return createLayer (tx , name , geometryEncoderClass , layerClass , null , null );
355
- }
356
-
357
- public Layer createLayer (Transaction tx , String name , Class <? extends GeometryEncoder > geometryEncoderClass ,
358
- Class <? extends Layer > layerClass , Class <? extends LayerIndexReader > indexClass ,
359
- String encoderConfig ) {
360
- return createLayer (tx , name , geometryEncoderClass , layerClass , indexClass , encoderConfig , null );
358
+ Class <? extends Layer > layerClass , String indexConfig ) {
359
+ return createLayer (tx , name , geometryEncoderClass , layerClass , null , null , indexConfig );
361
360
}
362
361
363
362
public Layer createLayer (Transaction tx , String name , Class <? extends GeometryEncoder > geometryEncoderClass ,
364
363
Class <? extends Layer > layerClass , Class <? extends LayerIndexReader > indexClass ,
365
- String encoderConfig , CoordinateReferenceSystem crs ) {
364
+ String encoderConfig ,
365
+ String indexConfig
366
+ ) {
367
+ return createLayer (tx , name , geometryEncoderClass , layerClass , indexClass , encoderConfig , indexConfig , null );
368
+ }
369
+
370
+ public Layer createLayer (Transaction tx ,
371
+ String name ,
372
+ Class <? extends GeometryEncoder > geometryEncoderClass ,
373
+ Class <? extends Layer > layerClass ,
374
+ Class <? extends LayerIndexReader > indexClass ,
375
+ String encoderConfig ,
376
+ String indexConfig ,
377
+ CoordinateReferenceSystem crs
378
+ ) {
366
379
if (containsLayer (tx , name )) {
367
380
throw new SpatialDatabaseException ("Layer " + name + " already exists" );
368
381
}
@@ -380,6 +393,17 @@ public Layer createLayer(Transaction tx, String name, Class<? extends GeometryEn
380
393
+ geometryEncoderClass );
381
394
}
382
395
}
396
+ if (indexConfig != null && !indexConfig .isEmpty ()) {
397
+ LayerIndexReader index = layer .getIndex ();
398
+ if (index instanceof Configurable ) {
399
+ ((Configurable ) index ).setConfiguration (indexConfig );
400
+ layer .getLayerNode (tx ).setProperty (PROP_INDEX_CONFIG , indexConfig );
401
+ } else {
402
+ System .out .println (
403
+ "Warning: index configuration '" + indexConfig + "' passed to non-configurable index: "
404
+ + indexClass );
405
+ }
406
+ }
383
407
if (crs != null && layer instanceof EditableLayer ) {
384
408
((EditableLayer ) layer ).setCoordinateReferenceSystem (tx , crs );
385
409
}
@@ -466,7 +490,7 @@ public static int convertJtsClassToGeometryType(Class<? extends Geometry> jtsCla
466
490
* @return new Layer with copy of all geometries
467
491
*/
468
492
public Layer createResultsLayer (Transaction tx , String layerName , List <SpatialDatabaseRecord > results ) {
469
- EditableLayer layer = (EditableLayer ) createWKBLayer (tx , layerName );
493
+ EditableLayer layer = (EditableLayer ) createWKBLayer (tx , layerName , "" );
470
494
for (SpatialDatabaseRecord record : results ) {
471
495
layer .add (tx , record .getGeometry ());
472
496
}
@@ -547,15 +571,16 @@ private static void addRegisteredLayerType(RegisteredLayerType type) {
547
571
registeredLayerTypes .put (type .typeName .toLowerCase (), type );
548
572
}
549
573
550
- public Layer getOrCreateRegisteredTypeLayer (Transaction tx , String name , String type , String config ) {
574
+ public Layer getOrCreateRegisteredTypeLayer (Transaction tx , String name , String type , String encoderConfig ,
575
+ String indexConfig ) {
551
576
RegisteredLayerType registeredLayerType = registeredLayerTypes .get (type .toLowerCase ());
552
- return getOrCreateRegisteredTypeLayer (tx , name , registeredLayerType , config );
577
+ return getOrCreateRegisteredTypeLayer (tx , name , registeredLayerType , encoderConfig , indexConfig );
553
578
}
554
579
555
580
public Layer getOrCreateRegisteredTypeLayer (Transaction tx , String name , RegisteredLayerType registeredLayerType ,
556
- String config ) {
581
+ String encoderConfig , String indexConfig ) {
557
582
return getOrCreateLayer (tx , name , registeredLayerType .geometryEncoder , registeredLayerType .layerClass ,
558
- (config == null ) ? registeredLayerType .defaultConfig : config );
583
+ (encoderConfig == null ) ? registeredLayerType .defaultConfig : encoderConfig , indexConfig );
559
584
}
560
585
561
586
public static Map <String , String > getRegisteredLayerTypes () {
0 commit comments