private static SimpleFeature buildSimpleFeature(
      final String locationName, final Coordinate coordinate) {

    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(getPointSimpleFeatureType());
    builder.set("locationName", locationName);
    builder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(coordinate));

    return builder.buildFeature(locationName);
  }
  private static void executeBoundingBoxQuery() throws IOException {

    System.out.println(
        "Constructing bounding box for the area contained by [Baltimore, MD and Richmond, VA.");

    final Geometry boundingBox =
        GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(baltimore, richmond));

    System.out.println("Executing query, expecting to match ALL points...");

    try (final CloseableIterator<SimpleFeature> iterator =
        dataStore.query(new QueryOptions(index), new SpatialQuery(boundingBox))) {

      while (iterator.hasNext()) {
        System.out.println("Query match: " + iterator.next().getID());
      }
    }
  }
  private static void executePolygonQuery() throws IOException {

    System.out.println(
        "Constructing polygon for the area contained by [Baltimore, MD; Richmond, VA; Harrisonburg, VA].");

    final Polygon polygon =
        GeometryUtils.GEOMETRY_FACTORY.createPolygon(
            new Coordinate[] {baltimore, richmond, harrisonburg, baltimore});

    System.out.println("Executing query, expecting to match ALL points...");

    /**
     * NOTICE: In this query, the adapter is added to the query options. If an index has data from
     * more than one adapter, the data associated with a specific adapter can be selected.
     */
    try (final CloseableIterator<SimpleFeature> closableIterator =
        dataStore.query(new QueryOptions(ADAPTER, index), new SpatialQuery(polygon))) {

      while (closableIterator.hasNext()) {
        System.out.println("Query match: " + closableIterator.next().getID());
      }
    }
  }