Java Code Examples for org.geotools.data.FeatureReader#next()

The following examples show how to use org.geotools.data.FeatureReader#next() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoWaveFeatureReaderTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testSmallBBOX() throws IllegalArgumentException, NoSuchElementException, IOException {
  final FilterFactoryImpl factory = new FilterFactoryImpl();
  final Query query =
      new Query(
          "GeoWaveFeatureReaderTest",
          factory.bbox("geometry", 28, 41, 28.5, 41.5, "EPSG:4326"),
          new String[] {"geometry", "pid"});

  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    assertTrue(fids.contains(feature.getID()));
    count++;
  }
  assertEquals(1, count);
}
 
Example 2
Source File: WFSTemporalQueryTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testTemporal() throws CQLException, IOException, ParseException {

  populate();
  final Transaction transaction2 = new DefaultTransaction();
  final Query query =
      new Query(
          "geostuff",
          CQL.toFilter(
              "BBOX(geometry,44,27,42,30) and start during 2005-05-16T20:32:56Z/2005-05-20T21:32:56Z and end during 2005-05-18T20:32:56Z/2005-05-22T21:32:56Z"),
          new String[] {"geometry", "start", "end", "pid"});
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, transaction2);
  int c = 0;
  while (reader.hasNext()) {
    reader.next();
    c++;
  }
  reader.close();
  transaction2.commit();
  transaction2.close();
  assertEquals(2, c);
}
 
Example 3
Source File: GeoToolsAttributesSubsetTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubsetAttributes() throws CQLException, IOException {
  final Query query =
      new Query(
          typeName,
          CQL.toFilter(cqlPredicate),
          new String[] {geometry_attribute, string_attribute});
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      geotoolsDataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    count++;
    Assert.assertTrue(feature.getAttribute(geometry_attribute) != null);
    Assert.assertTrue(feature.getAttribute(long_attribute) == null);
    Assert.assertTrue(feature.getAttribute(string_attribute) != null);
  }
  Assert.assertTrue(count == 3);
}
 
Example 4
Source File: GeoWaveFeatureReaderTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testLike()
    throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
  System.out.println(pids);
  final Query query =
      new Query(
          "GeoWaveFeatureReaderTest",
          ECQL.toFilter("pid like '" + pids.get(0).substring(0, 1) + "%'"),
          new String[] {"geometry", "pid"});
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    assertTrue(fids.contains(feature.getID()));
    count++;
  }
  assertEquals(1, count);
}
 
Example 5
Source File: GeoWaveFeatureReaderTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testBBOX() throws IllegalArgumentException, NoSuchElementException, IOException {
  final FilterFactoryImpl factory = new FilterFactoryImpl();
  final Query query =
      new Query(
          "GeoWaveFeatureReaderTest",
          factory.bbox("geometry", -180, -90, 180, 90, "EPSG:4326"),
          new String[] {"geometry", "pid"});

  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    assertTrue(fids.contains(feature.getID()));
    count++;
  }
  assertTrue(count > 0);
}
 
Example 6
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testLike() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            ECQL.toFilter("pid like '" + pids.get(
                    0).substring(
                    0,
                    1) + "%'"),
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertEquals(1, count);
}
 
Example 7
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testPidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    // Filter it so that it only queries for everything but the first pid.
    // There's only 2 pids total so it should just return the second one.
    final String pidsString = pids.subList(1, pids.size()).stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("pid IN (" + pidsString + ")");
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            filter,
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == pids.size() - 1);
}
 
Example 8
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testFidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final String fidsString = fids.stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("IN (" + fidsString + ")");
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            filter,
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == fids.size());
}
 
Example 9
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testRangeIndex() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertEquals(1, count);
}
 
Example 10
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveFeature() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            ECQL.toFilter("pid like '" + pids.get(
                    0).substring(
                    0,
                    1) + "%'"),
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertEquals(1, count);

    // Remove
    final FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
        dataStore.getFeatureWriter(type.getTypeName(), Transaction.AUTO_COMMIT);
    try {
        while (writer.hasNext()) {
            writer.next();
            writer.remove();
        }
    } finally {
        writer.close();
    }

    // Re-query
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader2 =
            dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int recount = 0;
    while (reader2.hasNext()) {
        reader2.next();
        recount++;
    }
    assertEquals(0, recount);
}
 
Example 11
Source File: GeoWaveFeatureReaderTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testFID()
    throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    assertTrue(fids.contains(feature.getID()));
    count++;
  }
  assertTrue(count > 0);
}
 
Example 12
Source File: AbstractGeotoolsDataStoreImporter.java    From TomboloDigitalConnector with MIT License 5 votes vote down vote up
private void withSubjects(FeatureReader<SimpleFeatureType, SimpleFeature> featureReader, DataStore dataStore, BiConsumer<SimpleFeature, Subject> fn) throws IOException, FactoryException, TransformException {
    MathTransform crsTransform = GeotoolsDataStoreUtils.makeCrsTransform(getSourceEncoding());

    while(featureReader.hasNext()) {
        SimpleFeature feature = featureReader.next();
        buildSubjectFromFeature(feature, crsTransform).ifPresent(subject -> {
            fn.accept(feature, subject);
            subjectBuffer.add(subject);
        });
        flushBufferIfRequired();
    }

    flushBuffer();
}
 
Example 13
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testBBOX() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FilterFactoryImpl factory = new FilterFactoryImpl();
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            factory.bbox(
                    "",
                    -180,
                    -90,
                    180,
                    90,
                    "EPSG:4326"),
            new String[] {
                "geometry",
                "pid"
            });

    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count > 0);
}
 
Example 14
Source File: GeoWaveFeatureReaderTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testRangeIndex()
    throws IllegalArgumentException, NoSuchElementException, IOException {
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    assertTrue(fids.contains(feature.getID()));
    count++;
  }
  assertEquals(1, count);
}
 
Example 15
Source File: WFSSpatialTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws IOException, CQLException, ParseException {
  final Transaction transaction1 = new DefaultTransaction();

  final FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
      dataStore.getFeatureWriter(type.getTypeName(), transaction1);
  assertFalse(writer.hasNext());
  SimpleFeature newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T18:33:55Z"));
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));

  newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:33:55Z"));
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
  writer.write();
  writer.close();

  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, transaction1);
  assertTrue(reader.hasNext());
  final SimpleFeature priorFeature = reader.next();
  assertEquals(newFeature.getAttribute("pid"), priorFeature.getAttribute("pid"));
  assertFalse(reader.hasNext());
  reader.close();

  transaction1.commit();
  transaction1.close();
}
 
Example 16
Source File: GeoToolsAttributesSubsetTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllAttributes() throws CQLException, IOException {
  final Query query = new Query(typeName, CQL.toFilter(cqlPredicate), Query.ALL_PROPERTIES);
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      geotoolsDataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    count++;
    Assert.assertTrue(feature.getAttribute(geometry_attribute) != null);
    Assert.assertTrue(feature.getAttribute(long_attribute) != null);
    Assert.assertTrue(feature.getAttribute(string_attribute) != null);
  }
  Assert.assertTrue(count == 3);
}
 
Example 17
Source File: GeoWaveFeatureReaderTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testFID() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count > 0);
}
 
Example 18
Source File: WFSTransactionTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Test
public void testInsertIsolation() throws IOException, CQLException {
  final Transaction transaction1 = new DefaultTransaction();

  final FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
      dataStore.getFeatureWriter(type.getTypeName(), transaction1);
  assertFalse(writer.hasNext());
  final SimpleFeature newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
  writer.write();
  writer.close();

  FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, transaction1);
  assertTrue(reader.hasNext());
  final SimpleFeature priorFeature = reader.next();
  assertEquals(newFeature.getAttribute("pid"), priorFeature.getAttribute("pid"));
  reader.close();

  // uncommitted at this point, so this next transaction should not see
  // it.

  final Transaction transaction2 = new DefaultTransaction();
  reader = dataStore.getFeatureReader(query, transaction2);
  assertFalse(reader.hasNext());
  reader.close();

  transaction1.commit();
  reader = dataStore.getFeatureReader(query, transaction1);
  assertTrue(reader.hasNext());
  reader.next();
  assertFalse(reader.hasNext());
  reader.close();

  transaction1.close();

  // since this implementation does not support serializable, transaction2
  // can see the changes even though
  // it started after transaction1 and before the commit.
  reader = dataStore.getFeatureReader(query, transaction2);
  assertTrue(reader.hasNext());
  reader.next();
  assertFalse(reader.hasNext());
  reader.close();
  transaction2.commit();
  transaction2.close();

  // stats check
  final Transaction transaction3 = new DefaultTransaction();
  reader =
      ((GeoWaveFeatureSource) ((GeoWaveGTDataStore) dataStore).getFeatureSource(
          "geostuff",
          transaction3)).getReaderInternal(query);
  final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> transStats =
      ((GeoWaveFeatureReader) reader).getTransaction().getDataStatistics();
  assertNotNull(
      transStats.get(
          FeatureNumericRangeStatistics.STATS_TYPE.newBuilder().fieldName(
              "pop").build().getId()));
  transaction3.close();
}