1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.log4j.Logger; import org.geotools.feature.AttributeTypeBuilder; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.filter.text.cql2.CQLException; import org.geotools.geometry.jts.JTSFactoryFinder; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; import mil.nga.giat.geowave.adapter.vector.FeatureDataAdapter; import mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery; import mil.nga.giat.geowave.core.geotime.GeometryUtils; import mil.nga.giat.geowave.core.geotime.ingest.SpatialDimensionalityTypeProvider.SpatialIndexBuilder; import mil.nga.giat.geowave.core.geotime.store.query.SpatialQuery; import mil.nga.giat.geowave.core.index.ByteArrayId; import mil.nga.giat.geowave.core.store.CloseableIterator; import mil.nga.giat.geowave.core.store.DataStore; import mil.nga.giat.geowave.core.store.IndexWriter; import mil.nga.giat.geowave.core.store.adapter.AdapterStore; import mil.nga.giat.geowave.core.store.index.PrimaryIndex; import mil.nga.giat.geowave.core.store.memory.DataStoreUtils; import mil.nga.giat.geowave.core.store.query.QueryOptions; import mil.nga.giat.geowave.datastore.accumulo.AccumuloDataStore; import mil.nga.giat.geowave.datastore.accumulo.BasicAccumuloOperations; import mil.nga.giat.geowave.datastore.accumulo.metadata.AccumuloAdapterStore; /** * This class is intended to provide a few examples on running Geowave queries * of different types: 1- Querying by polygon a set of points. 2- Filtering on * attributes of features using CQL queries 3- Ingesting polygons, and running * polygon intersect queries. You can check all points, geometries and query * accuracy in a more visual manner @ http://geojson.io/ */ public class SpatialQueryExample { private static Logger log = Logger.getLogger(SpatialQueryExample.class); // We'll use GeoWave's VectorDataStore, which allows to run CQL rich queries private static DataStore dataStore; // We need the AccumuloAdapterStore, which keeps a registry of adapter-ids, // used to be able to query specific "tables" or "types" of features. private static AdapterStore adapterStore; public static void main( String[] args ) throws AccumuloSecurityException, AccumuloException, ParseException, CQLException, IOException { SpatialQueryExample example = new SpatialQueryExample(); log.info("Setting up datastores"); example.setupDataStores(); log.info("Running point query examples"); example.runPointExamples(); log.info("Running polygon query examples"); example.runPolygonExamples(); } private void setupDataStores() throws AccumuloSecurityException, AccumuloException { // Initialize VectorDataStore and AccumuloAdapterStore MockInstance instance = new MockInstance(); // For the MockInstance we can user "user" - "password" as our // connection tokens Connector connector = instance.getConnector( "user", new PasswordToken( "password")); BasicAccumuloOperations operations = new BasicAccumuloOperations( connector); dataStore = new AccumuloDataStore( operations); adapterStore = new AccumuloAdapterStore( operations); } /** * We'll run our point related operations. The data ingested and queried is * single point based, meaning the index constructed will be based on a * point. */ private void runPointExamples() throws ParseException, CQLException, IOException { ingestPointData(); pointQueryCase1(); pointQueryCase2(); pointQueryCase3(); pointQueryCase4(); } private void ingestPointData() { log.info("Ingesting point data"); ingestPointBasicFeature(); ingestPointComplexFeature(); log.info("Point data ingested"); } private void ingest( FeatureDataAdapter adapter, PrimaryIndex index, List features ) { try (IndexWriter indexWriter = dataStore.createWriter( adapter, index)) { for (SimpleFeature sf : features) { // indexWriter.write(sf); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void ingestPointBasicFeature() { // First, we'll build our first kind of SimpleFeature, which we'll call // "basic-feature" // We need the type builder to build the feature type SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder(); // AttributeTypeBuilder for the attributes of the SimpleFeature AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder(); // Here we're setting the SimpleFeature name. Later on, we'll be able to // query GW just by this particular feature. sftBuilder.setName("basic-feature"); // Add the attributes to the feature // Add the geometry attribute, which is mandatory for GeoWave to be able // to construct an index out of the SimpleFeature sftBuilder.add(attrBuilder.binding( Point.class).nillable( false).buildDescriptor( "geometry")); // Add another attribute just to be able to filter by it in CQL sftBuilder.add(attrBuilder.binding( String.class).nillable( false).buildDescriptor( "filter")); // Create the SimpleFeatureType SimpleFeatureType sfType = sftBuilder.buildFeatureType(); // We need the adapter for all our operations with GeoWave FeatureDataAdapter sfAdapter = new FeatureDataAdapter( sfType); // Now we build the actual features. We'll create two points. // First point SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder( sfType); sfBuilder.set( "geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate( -80.211181640625, 25.848101000701597))); sfBuilder.set( "filter", "Basic-Stadium"); // When calling buildFeature, we need to pass an unique id for that // feature, or it will be overwritten. SimpleFeature basicPoint1 = sfBuilder.buildFeature("1"); // Construct the second feature. sfBuilder.set( "geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate( -80.191360, 25.777804))); sfBuilder.set( "filter", "Basic-College"); SimpleFeature basicPoint2 = sfBuilder.buildFeature("2"); ArrayList features = new ArrayList(); features.add(basicPoint1); features.add(basicPoint2); // Ingest the data. For that purpose, we need the feature adapter, // the index type (the default spatial index is used here), // and an iterator of SimpleFeature ingest( sfAdapter, new SpatialIndexBuilder().createIndex(), features); } /** * We're going to ingest a more complete simple feature. */ private void ingestPointComplexFeature() { // First, we'll build our second kind of SimpleFeature, which we'll call // "complex-feature" // We need the type builder to build the feature type SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder(); // AttributeTypeBuilder for the attributes of the SimpleFeature AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder(); // Here we're setting the SimpleFeature name. Later on, we'll be able to // query GW just by this particular feature. sftBuilder.setName("complex-feature"); // Add the attributes to the feature // Add the geometry attribute, which is mandatory for GeoWave to be able // to construct an index out of the SimpleFeature sftBuilder.add(attrBuilder.binding( Point.class).nillable( false).buildDescriptor( "geometry")); // Add another attribute just to be able to filter by it in CQL sftBuilder.add(attrBuilder.binding( String.class).nillable( false).buildDescriptor( "filter")); // Add more attributes to use with CQL filtering later on. sftBuilder.add(attrBuilder.binding( Double.class).nillable( false).buildDescriptor( "latitude")); sftBuilder.add(attrBuilder.binding( Double.class).nillable( false).buildDescriptor( "longitude")); // Create the SimpleFeatureType SimpleFeatureType sfType = sftBuilder.buildFeatureType(); // We need the adapter for all our operations with GeoWave FeatureDataAdapter sfAdapter = new FeatureDataAdapter( sfType); // Now we build the actual features. We'll create two more points. // First point SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder( sfType); sfBuilder.set( "geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate( -80.193388, 25.780538))); sfBuilder.set( "filter", "Complex-Station"); sfBuilder.set( "latitude", 25.780538); sfBuilder.set( "longitude", -80.193388); // When calling buildFeature, we need to pass an unique id for that // feature, or it will be overwritten. SimpleFeature basicPoint1 = sfBuilder.buildFeature("1"); // Construct the second feature. sfBuilder.set( "geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate( -118.26713562011719, 33.988349152677955))); sfBuilder.set( "filter", "Complex-LA"); sfBuilder.set( "latitude", 33.988349152677955); sfBuilder.set( "longitude", -118.26713562011719); SimpleFeature basicPoint2 = sfBuilder.buildFeature("2"); ArrayList features = new ArrayList(); features.add(basicPoint1); features.add(basicPoint2); // Ingest the data. For that purpose, we need the feature adapter, // the index type (the default spatial index is used here), // and an iterator of SimpleFeature ingest( sfAdapter, new SpatialIndexBuilder().createIndex(), features); /** * After ingest, a single point might look like this in Accumulo. */ // x1Fx11xCBxFCxB6xEFTx00xFFcomplex_feature4x00x00x00x0Ex00x00x00x01x00x00x00x00 // complex_feature:filter [] Complex-LA // x1Fx11xCBxFCxB6xEFTx00xFFcomplex_feature4x00x00x00x0Ex00x00x00x01x00x00x00x00 // complex_feature:geomx00x00 [] // x1Fx11xCBxFCxB6xEFTx00xFFcomplex_feature4x00x00x00x0Ex00x00x00x01x00x00x00x00 // complex_feature:latitude [] @@xFEx829x9BxE3xFC // x1Fx11xCBxFCxB6xEFTx00xFFcomplex_featurex00x00x00x0Ex00x00x00x01x00x00x00x00 // complex_feature:longitude [] xC0]x91x18xC0x00x00x } /** * This query will search all points using the world's Bounding Box */ private void pointQueryCase1() throws ParseException, IOException { log.info("Running Point Query Case 1"); // First, we need to obtain the adapter for the SimpleFeature we want to // query. // We'll query basic-feature in this example. // Obtain adapter for our "basic-feature" type ByteArrayId bfAdId = new ByteArrayId( "basic-feature"); FeatureDataAdapter bfAdapter = (FeatureDataAdapter) adapterStore.getAdapter(bfAdId); // Define the geometry to query. We'll find all points that fall inside // that geometry String queryPolygonDefinition = "POLYGON (( " + "-180 -90, " + "-180 90, " + "180 90, " + "180 -90, " + "-180 -90" + "))"; Geometry queryPolygon = new WKTReader( JTSFactoryFinder.getGeometryFactory()).read(queryPolygonDefinition); // Perform the query.Parameters are /** * 1- Adapter previously obtained from the feature name. 2- Default * spatial index. 3- A SpatialQuery, which takes the query geometry - * aka Bounding box 4- Filters. For this example, no filter is used. 5- * Limit. Same as standard SQL limit. 0 is no limits. 6- Accumulo * authorizations. For our mock instances, "root" works. In a real * Accumulo setting, whatever authorization is associated to the user in * question. */ final QueryOptions options = new QueryOptions( bfAdapter, new SpatialIndexBuilder().createIndex()); options.setAuthorizations(new String[] { "root" }); int count = 0; try (final CloseableIterator iterator = dataStore.query( options, new SpatialQuery( queryPolygon))) { while (iterator.hasNext()) { SimpleFeature sf = iterator.next(); log.info("Obtained SimpleFeature " + sf.getName().toString() + " - " + sf.getAttribute("filter")); count++; System.out.println("Query match: " + iterator.next().getID()); } log.info("Should have obtained 2 features. -> " + (count == 2)); } } /** * This query will use a specific Bounding Box, and will find only 1 point. */ private void pointQueryCase2() throws ParseException, IOException { log.info("Running Point Query Case 2"); // First, we need to obtain the adapter for the SimpleFeature we want to // query. // We'll query complex-feature in this example. // Obtain adapter for our "complex-feature" type ByteArrayId bfAdId = new ByteArrayId( "complex-feature"); FeatureDataAdapter bfAdapter = (FeatureDataAdapter) adapterStore.getAdapter(bfAdId); // Define the geometry to query. We'll find all points that fall inside // that geometry. String queryPolygonDefinition = "POLYGON (( " + "-118.50059509277344 33.75688594085081, " + "-118.50059509277344 34.1521587488017, " + "-117.80502319335938 34.1521587488017, " + "-117.80502319335938 33.75688594085081, " + "-118.50059509277344 33.75688594085081" + "))"; Geometry queryPolygon = new WKTReader( JTSFactoryFinder.getGeometryFactory()).read(queryPolygonDefinition); // Perform the query.Parameters are /** * 1- Adapter previously obtained from the feature name. 2- Default * spatial index. 3- A SpatialQuery, which takes the query geometry - * aka Bounding box 4- Filters. For this example, no filter is used. 5- * Limit. Same as standard SQL limit. 0 is no limits. 6- Accumulo * authorizations. For our mock instances, "root" works. In a real * Accumulo setting, whatever authorization is associated to the user in * question. */ final QueryOptions options = new QueryOptions( bfAdapter, new SpatialIndexBuilder().createIndex(), new String[] { "root" }); int count = 0; try (final CloseableIterator iterator = dataStore.query( options, new SpatialQuery( queryPolygon))) { while (iterator.hasNext()) { SimpleFeature sf = iterator.next(); log.info("Obtained SimpleFeature " + sf.getName().toString() + " - " + sf.getAttribute("filter")); count++; System.out.println("Query match: " + sf.getID()); } log.info("Should have obtained 1 feature. -> " + (count == 1)); } } /** * This query will use the world's Bounding Box together with a CQL filter. */ private void pointQueryCase3() throws ParseException, CQLException, IOException { log.info("Running Point Query Case 3"); // First, we need to obtain the adapter for the SimpleFeature we want to // query. // We'll query basic-feature in this example. // Obtain adapter for our "basic-feature" type ByteArrayId bfAdId = new ByteArrayId( "basic-feature"); FeatureDataAdapter bfAdapter = (FeatureDataAdapter) adapterStore.getAdapter(bfAdId); String CQLFilter = "filter = 'Basic-Stadium'"; // Perform the query.Parameters are /** * 1- Adapter previously obtained from the feature name. 2- Default * spatial index. 3- A SpatialQuery, which takes the query geometry - * aka Bounding box 4- Filters. For this example, we reduce all returned * points (2) by using a filter. 5- Limit. Same as standard SQL limit. 0 * is no limits. 6- Accumulo authorizations. For our mock instances, * "root" works. In a real Accumulo setting, whatever authorization is * associated to the user in question. */ final QueryOptions options = new QueryOptions( bfAdapter, new SpatialIndexBuilder().createIndex(), new String[] { "root" }); int count = 0; try (final CloseableIterator iterator = dataStore.query( options, new CQLQuery( CQLFilter, bfAdapter))) { // Our query would have found 2 points based only on the Bounding // Box, but using the // filter to match a particular attribute will reduce our result set // size to 1 while (iterator.hasNext()) { SimpleFeature sf = iterator.next(); log.info("Obtained SimpleFeature " + sf.getName().toString() + " - " + sf.getAttribute("filter")); count++; System.out.println("Query match: " + sf.getID()); } log.info("Should have obtained 1 feature. " + (count == 1)); } } /** * This query will use the world's Bounding Box together with a more complex * CQL filter. */ private void pointQueryCase4() throws ParseException, CQLException, IOException { log.info("Running Point Query Case 4"); // First, we need to obtain the adapter for the SimpleFeature we want to // query. // We'll query complex-feature in this example. // Obtain adapter for our "complex-feature" type ByteArrayId bfAdId = new ByteArrayId( "complex-feature"); FeatureDataAdapter bfAdapter = (FeatureDataAdapter) adapterStore.getAdapter(bfAdId); // This CQL query will yield a single point - Complex-LA String CQLFilter = "latitude > 25 AND longitude < -118"; // Perform the query.Parameters are /** * 1- Adapter previously obtained from the feature name. 2- Default * spatial index. 3- A SpatialQuery, which takes the query geometry - * aka Bounding box 4- Filters. For this example, we reduce all returned * points (2) by using a filter. 5- Limit. Same as standard SQL limit. 0 * is no limits. 6- Accumulo authorizations. For our mock instances, * "root" works. In a real Accumulo setting, whatever authorization is * associated to the user in question. */ final QueryOptions options = new QueryOptions( bfAdapter, new SpatialIndexBuilder().createIndex(), new String[] { "root" }); int count = 0; try (final CloseableIterator iterator = dataStore.query( options, new CQLQuery( CQLFilter, bfAdapter))) { // Our query would have found 2 points based only on the Bounding // Box, but using the // filter to match a particular attribute will reduce our result set // size to 1 while (iterator.hasNext()) { SimpleFeature sf = iterator.next(); log.info("Obtained SimpleFeature " + sf.getName().toString() + " - " + sf.getAttribute("filter")); count++; System.out.println("Query match: " + sf.getID()); } log.info("Should have obtained 1 feature. -> " + (count == 1)); } } /** * We'll run our polygon related operations. The data ingested and queried * is single polygon based, meaning the index constructed will be based on a * Geometry. */ private void runPolygonExamples() throws ParseException, IOException { ingestPolygonFeature(); polygonQueryCase1(); } private void ingestPolygonFeature() throws ParseException { log.info("Ingesting polygon data"); // First, we'll build our third kind of SimpleFeature, which we'll call // "polygon-feature" // We need the type builder to build the feature type SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder(); // AttributeTypeBuilder for the attributes of the SimpleFeature AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder(); // Here we're setting the SimpleFeature name. Later on, we'll be able to // query GW just by this particular feature. sftBuilder.setName("polygon-feature"); // Add the attributes to the feature // Add the geometry attribute, which is mandatory for GeoWave to be able // to construct an index out of the SimpleFeature // Will be any arbitrary geometry; in this case, a polygon. sftBuilder.add(attrBuilder.binding( Geometry.class).nillable( false).buildDescriptor( "geometry")); // Add another attribute just to be able to filter by it in CQL sftBuilder.add(attrBuilder.binding( String.class).nillable( false).buildDescriptor( "filter")); // Create the SimpleFeatureType SimpleFeatureType sfType = sftBuilder.buildFeatureType(); // We need the adapter for all our operations with GeoWave FeatureDataAdapter sfAdapter = new FeatureDataAdapter( sfType); // Now we build the actual features. We'll create one polygon. // First point SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder( sfType); // For ease of use, we'll create the polygon geometry with WKT format. String polygonDefinition = "POLYGON (( " + "-80.3045654296875 25.852426562716428, " + "-80.123291015625 25.808545671771615, " + "-80.19195556640625 25.7244467526159, " + "-80.34233093261719 25.772068899816585, " + "-80.3045654296875 25.852426562716428" + "))"; Geometry geom = new WKTReader( JTSFactoryFinder.getGeometryFactory()).read(polygonDefinition); sfBuilder.set( "geometry", geom); sfBuilder.set( "filter", "Polygon"); // When calling buildFeature, we need to pass an unique id for that // feature, or it will be overwritten. SimpleFeature polygon = sfBuilder.buildFeature("1"); ArrayList features = new ArrayList(); features.add(polygon); // Ingest the data. For that purpose, we need the feature adapter, // the index type (the default spatial index is used here), // and an iterator of SimpleFeature ingest( sfAdapter, new SpatialIndexBuilder().createIndex(), features); log.info("Polygon data ingested"); } /** * This query will find a polygon/polygon intersection, returning one match. */ private void polygonQueryCase1() throws ParseException, IOException { log.info("Running Point Query Case 4"); // First, we need to obtain the adapter for the SimpleFeature we want to // query. // We'll query polygon-feature in this example. // Obtain adapter for our "polygon-feature" type ByteArrayId bfAdId = new ByteArrayId( "polygon-feature"); FeatureDataAdapter bfAdapter = (FeatureDataAdapter) adapterStore.getAdapter(bfAdId); // Define the geometry to query. We'll find all polygons that intersect // with this geometry. String queryPolygonDefinition = "POLYGON (( " + "-80.4037857055664 25.81596330265488, " + "-80.27915954589844 25.788144792391982, " + "-80.34370422363281 25.8814655232439, " + "-80.44567108154297 25.896291175546626, " + "-80.4037857055664 25.81596330265488" + "))"; Geometry queryPolygon = new WKTReader( JTSFactoryFinder.getGeometryFactory()).read(queryPolygonDefinition); // Perform the query.Parameters are /** * 1- Adapter previously obtained from the feature name. 2- Default * spatial index. 3- A SpatialQuery, which takes the query geometry - * aka Bounding box 4- Filters. For this example, we don't use filters * 5- Limit. Same as standard SQL limit. 0 is no limits. 6- Accumulo * authorizations. For our mock instances, "root" works. In a real * Accumulo setting, whatever authorization is associated to the user in * question. */ final QueryOptions options = new QueryOptions( bfAdapter, new SpatialIndexBuilder().createIndex(), new String[] { "root" }); int count = 0; try (final CloseableIterator iterator = dataStore.query( options, new SpatialQuery( queryPolygon))) { while (iterator.hasNext()) { SimpleFeature sf = iterator.next(); log.info("Obtained SimpleFeature " + sf.getName().toString() + " - " + sf.getAttribute("filter")); count++; System.out.println("Query match: " + sf.getID()); } log.info("Should have obtained 1 feature. -> " + (count == 1)); } } } |