org.geotools.filter.text.ecql.ECQL Java Examples

The following examples show how to use org.geotools.filter.text.ecql.ECQL. 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: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 7 votes vote down vote up
@Test
public void testGeoShapeIntersectsFilter() throws CQLException {
    Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(\"geom\", LINESTRING(0 0,1.1 1.1))");
    List<List<Double>> coords = new ArrayList<>();
    coords.add(ImmutableList.of(0.,0.));
    coords.add(ImmutableList.of(1.1,1.1));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape", 
                    ImmutableMap.of("geom", ImmutableMap.of("shape", 
                            ImmutableMap.of("coordinates", coords, "type", "LineString"),
                            "relation", "INTERSECTS")))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    // TODO: Why doesn't equality check on objects work here
    assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
 
Example #2
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoShapeIntersectsFilterReversed() throws CQLException {
    Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(LINESTRING(0 0,1.1 1.1), \"geom\")");
    List<List<Double>> coords = new ArrayList<>();
    coords.add(ImmutableList.of(0.,0.));
    coords.add(ImmutableList.of(1.1,1.1));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape", 
                    ImmutableMap.of("geom", ImmutableMap.of("shape", 
                            ImmutableMap.of("coordinates", coords, "type", "LineString"),
                            "relation", "INTERSECTS")))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
 
Example #3
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/** @inheritDoc */
public Filter parseFilter(String filter) throws GeomajasException {
	if (null == filter || filter.length() == 0) {
		return createTrueFilter();
	}
	try {
		if (idReplacer.shouldParse(filter)) {
			return idReplacer.parse(filter);
		} else {
			return ECQL.toFilter(filter, FF);
		}
	} catch (CQLException e) {
		// ECQL should be a superset of CQL, but there are apparently extra key words like "id"
		// fall back to CQL for backwards compatibility
		log.warn("Filter not parsable by ECQL, falling back to CQL", e);
		try {
			return CQL.toFilter(filter, FF);
		} catch (CQLException ce) {
			throw new GeomajasException(ce, ExceptionCode.FILTER_PARSE_PROBLEM, filter);
		}
	}
}
 
Example #4
Source File: CQLQueryFilter.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] toBinary() {
  byte[] filterBytes;
  if (filter == null) {
    LOGGER.warn("CQL filter is null");
    filterBytes = new byte[] {};
  } else {
    filterBytes = StringUtils.stringToBinary(ECQL.toCQL(filter));
  }
  byte[] adapterBytes;
  if (adapter != null) {
    adapterBytes = PersistenceUtils.toBinary(adapter);
  } else {
    LOGGER.warn("Feature Data Adapter is null");
    adapterBytes = new byte[] {};
  }
  final ByteBuffer buf =
      ByteBuffer.allocate(
          filterBytes.length
              + adapterBytes.length
              + VarintUtils.unsignedIntByteLength(filterBytes.length));
  VarintUtils.writeUnsignedInt(filterBytes.length, buf);
  buf.put(filterBytes);
  buf.put(adapterBytes);
  return buf.array();
}
 
Example #5
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 #6
Source File: GeoWaveVectorRecordReader.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(InputSplit split, TaskAttemptContext context) throws IOException,
    InterruptedException
{
  delegateReader.initialize(split, context);
  // No need to initialize the delegateReader since it was already done in the
  // GeoWaveInputFormat.createRecordReader method
  strCqlFilter = context.getConfiguration().get(CQL_FILTER);
  if (strCqlFilter != null && !strCqlFilter.isEmpty())
  {
    try
    {
      log.info("Creating the CQL filter");
      cqlFilter = ECQL.toFilter(strCqlFilter);
      log.info("Done creating the CQL filter");
    }
    catch (CQLException e)
    {
      throw new IOException("Unable to instantiate CQL filter for: " + strCqlFilter, e);
    }
  }
}
 
Example #7
Source File: RuleParametersController.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
* Default constructor
 * @param mainController 
*/
public RuleParametersController( RuleWrapper ruleWrapper, MainController mainController ) {
    this.ruleWrapper = ruleWrapper;
    _applyButton.addActionListener(e -> {
        try {
            String filterText = _filterTextArea.getText().trim();
            if (filterText.length() > 0) {
                Filter filter = ECQL.toFilter(filterText);
                ruleWrapper.getRule().setFilter(filter);
            }else {
                ruleWrapper.getRule().setFilter(null);
            }
        } catch (CQLException e1) {
            e1.printStackTrace();
        }

        mainController.applyStyle();
    });
    init();
}
 
Example #8
Source File: GeoWaveGTQueryTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void executeCQLQueryTest() throws IOException, CQLException {
    System.out.println("Executing query, expecting to match two points...");

    final Filter cqlFilter = ECQL.toFilter("BBOX(geometry,-77.6167,38.6833,-76.6,38.9200) and locationName like 'W%'");

    final QueryOptions queryOptions = new QueryOptions(ADAPTER, INDEX);
    final CQLQuery cqlQuery = new CQLQuery(null, cqlFilter, ADAPTER);

    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(queryOptions, cqlQuery)) {
        int count = 0;
        while (iterator.hasNext()) {
            System.out.println("Query match: " + iterator.next().getID());
            count++;
        }
        System.out.println("executeCQLQueryTest count: " + count);
        // Should match "Washington Monument" and "White House"
        assertEquals(2, count);
    }
}
 
Example #9
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 #10
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 #11
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoPolygonFilter() throws CQLException {
    Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(\"geo_point\", POLYGON((0 0, 0 1.1, 1.1 1.1, 1.1 0, 0 0)))");
    List<List<Double>> points = ImmutableList.of(
            ImmutableList.of(0.,0.),
            ImmutableList.of(0.,1.1),
            ImmutableList.of(1.1,1.1),
            ImmutableList.of(1.1,0.),
            ImmutableList.of(0.,0.));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_polygon", 
                    ImmutableMap.of("geo_point", ImmutableMap.of("points", points)))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #12
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testCompoundFilter() throws CQLException {
    Filter filter = ECQL.toFilter("time > \"1970-01-01\" and INTERSECTS(\"geom\", LINESTRING(0 0,1.1 1.1))");
    List<List<Double>> coords = new ArrayList<>();
    coords.add(ImmutableList.of(0.,0.));
    coords.add(ImmutableList.of(1.1,1.1));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", ImmutableList.of(ImmutableMap.of("range", ImmutableMap.of("time", ImmutableMap.of("gt", "1970-01-01"))),
                    ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL, 
                            "filter", ImmutableMap.of("geo_shape", 
                                    ImmutableMap.of("geom", ImmutableMap.of("shape", 
                                            ImmutableMap.of("coordinates", coords, "type", "LineString"),
                                            "relation", "INTERSECTS"))))))));

    builder.encode(filter);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
 
Example #13
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 #14
Source File: FilterToCQLToolTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void tesFid() {
  final FilterFactoryImpl factory = new FilterFactoryImpl();
  final Id f = factory.id(new FeatureIdImpl("123-abc"));
  final String ss = ECQL.toCQL(f);
  System.out.println(ss);
  assertTrue(ss.contains("'123-abc'"));
}
 
Example #15
Source File: EcqlTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testParseFilter() throws Exception {
	Filter res = ECQL.toFilter(FILTER_SIMPLE_LARGE);
	Assert.assertNotNull(res);
	res = ECQL.toFilter(FILTER_SIMPLE_MEDIUM);
	Assert.assertNotNull(res);
	res = ECQL.toFilter(FILTER_SIMPLE_SMALL);
	Assert.assertNotNull(res);
}
 
Example #16
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDWithinFilter() throws CQLException {
    DWithin filter = (DWithin) ECQL.toFilter("DWITHIN(\"geo_point\", POINT(0 1.1), 1.0, meters)");
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_distance", 
                    ImmutableMap.of("distance", "1.0m",
                            "geo_point", ImmutableList.of(0.,1.1)))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());       
}
 
Example #17
Source File: OptimalCQLQuery.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] toBinary() {
  byte[] filterBytes;
  if (filter == null) {
    LOGGER.warn("CQL filter is null");
    filterBytes = new byte[] {};
  } else {
    filterBytes = StringUtils.stringToBinary(ECQL.toCQL(filter));
  }
  return filterBytes;
}
 
Example #18
Source File: OptimalCQLQuery.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static QueryConstraints createOptimalQuery(
    final String cql,
    final GeotoolsFeatureDataAdapter adapter,
    final CompareOperation geoCompareOp,
    final Index index,
    final BasicQueryByClass baseQuery) throws CQLException {
  final Filter cqlFilter = ECQL.toFilter(cql);
  return createOptimalQuery(cqlFilter, adapter, geoCompareOp, index, baseQuery);
}
 
Example #19
Source File: FilterToCQLTool.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Filter fixDWithin(final Filter filter) {
  final HasDWithinFilterVisitor dwithinCheck = new HasDWithinFilterVisitor();
  filter.accept(dwithinCheck, null);
  if (dwithinCheck.hasDWithin()) {
    try {
      final Filter retVal = (Filter) filter.accept(new DWithinFilterVisitor(), null);
      // We do not have a way to transform a filter directly from one
      // to another.
      return FilterToCQLTool.toFilter(ECQL.toCQL(retVal));
    } catch (final CQLException e) {
      LOGGER.trace("Filter is not a CQL Expression", e);
    }
  }
  return filter;
}
 
Example #20
Source File: GaussianCellMapper.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected void setup(final Context context) throws IOException, InterruptedException {
  super.setup(context);
  minLevel = context.getConfiguration().getInt(KDEJobRunner.MIN_LEVEL_KEY, 1);
  maxLevel = context.getConfiguration().getInt(KDEJobRunner.MAX_LEVEL_KEY, 25);
  valueRangePerDimension =
      new ValueRange[] {
          new ValueRange(
              context.getConfiguration().getDouble(KDEJobRunner.X_MIN_KEY, -180),
              context.getConfiguration().getDouble(KDEJobRunner.X_MAX_KEY, 180)),
          new ValueRange(
              context.getConfiguration().getDouble(KDEJobRunner.Y_MIN_KEY, -90),
              context.getConfiguration().getDouble(KDEJobRunner.Y_MAX_KEY, 90))};
  inputCrsCode = context.getConfiguration().get(KDEJobRunner.INPUT_CRSCODE_KEY);
  outputCrsCode = context.getConfiguration().get(KDEJobRunner.OUTPUT_CRSCODE_KEY);

  final String cql = context.getConfiguration().get(CQL_FILTER_KEY);
  if ((cql != null) && !cql.isEmpty()) {
    try {
      filter = ECQL.toFilter(cql);
    } catch (final CQLException e) {
      LOGGER.warn("Unable to parse CQL filter", e);
    }
  }
  levelStoreMap = new HashMap<>();

  for (int level = maxLevel; level >= minLevel; level--) {
    final int numXPosts = (int) Math.pow(2, level + 1) * KDEJobRunner.TILE_SIZE;
    final int numYPosts = (int) Math.pow(2, level) * KDEJobRunner.TILE_SIZE;
    populateLevelStore(context, numXPosts, numYPosts, level);
  }
}
 
Example #21
Source File: ClientSideCQLQuery.java    From geowave with Apache License 2.0 5 votes vote down vote up
private void getFilter() {
  try {
    filter = ECQL.toFilter(cql);
  } catch (final CQLException e) {
    LOGGER.warn("Unable to retrive filter", e);
  }
}
 
Example #22
Source File: FilterToCQLToolTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testDWithinFromCQLFilter() throws CQLException {
  final Filter filter = CQL.toFilter("DWITHIN(geom, POINT(-122.7668 0.4979), 233.7, meters)");
  final String gtFilterStr = ECQL.toCQL(FilterToCQLTool.fixDWithin(filter));
  System.out.println(gtFilterStr);
  assertTrue(gtFilterStr.contains("INTERSECTS(geom, POLYGON (("));

  testFilter(FilterToCQLTool.toFilter(gtFilterStr));
}
 
Example #23
Source File: FilterToCQLToolTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
  final FilterFactoryImpl factory = new FilterFactoryImpl();
  final Expression exp1 = factory.property("pid");
  final Expression exp2 = factory.literal("a89dhd-123-abc");
  final Filter f = factory.equal(exp1, exp2, false);
  final String ss = ECQL.toCQL(f);
  assertTrue(ss.contains("'a89dhd-123-abc'"));
}
 
Example #24
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDWithinPolygonFilter() throws CQLException {
    DWithin filter = (DWithin) ECQL.toFilter("DWITHIN(\"geo_point\", POLYGON((0 0, 0 1, 1 1, 1 0, 0 0)), 1.0, meters)");
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_distance", 
                    ImmutableMap.of("distance", "1.0m",
                            "geo_point", ImmutableList.of(0.5,0.5)))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());       
}
 
Example #25
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqual() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Date etime = DateUtilities.parseISO("2005-05-19T21:32:56Z");
  final Filter filter = ECQL.toFilter("when = 2005-05-19T21:32:56Z");
  final Query query = new Query("type", filter);
  final TemporalConstraints range = (TemporalConstraints) query.getFilter().accept(visitor, null);
  assertNotNull(range);
  assertEquals(etime, range.getStartRange().getStartTime());
  assertEquals(etime, range.getEndRange().getEndTime());
}
 
Example #26
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDBeyondFilter() throws CQLException {
    Beyond filter = (Beyond) ECQL.toFilter("BEYOND(\"geo_point\", POINT(0 1.1), 1.0, meters)");
    Map<String,Object> expected = ImmutableMap.of("bool", ImmutableMap.of("must_not", ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_distance", ImmutableMap.of("distance", "1.0m",
                    "geo_point", ImmutableList.of(0.,1.1)))))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());       
}
 
Example #27
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCql() throws CQLException {
    Filter filter = ECQL.toFilter("\"object.field\"='value'");
    Map<String,Object> expected = ImmutableMap.of("term", ImmutableMap.of("object.field", "value"));

    builder.encode(filter);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #28
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 #29
Source File: GeoWaveFeatureReaderTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws SchemaException, CQLException, Exception {
  dataStore = createDataStore();
  type =
      DataUtilities.createType(
          "GeoWaveFeatureReaderTest",
          "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");
  ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex(
      new SpatialIndexBuilder().createIndex());
  ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex(
      new SpatialTemporalIndexBuilder().createIndex());
  dataStore.createSchema(type);

  stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
  mtime = DateUtilities.parseISO("2005-05-20T20:32:56Z");
  etime = DateUtilities.parseISO("2005-05-25T20:32:56Z");

  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", "a" + UUID.randomUUID().toString());
  newFeature.setAttribute("start", stime);
  newFeature.setAttribute("end", mtime);
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
  fids.add(newFeature.getID());
  pids.add(newFeature.getAttribute("pid").toString());
  writer.write();
  newFeature = writer.next();
  newFeature.setAttribute("pop", Long.valueOf(101));
  newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString());
  newFeature.setAttribute("start", mtime);
  newFeature.setAttribute("end", etime);
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25)));
  fids.add(newFeature.getID());
  pids.add(newFeature.getAttribute("pid").toString());
  writer.write();
  writer.close();
  transaction1.commit();
  transaction1.close();

  query =
      new Query(
          "GeoWaveFeatureReaderTest",
          ECQL.toFilter("IN ('" + fids.get(0) + "')"),
          new String[] {"geometry", "pid"});
}
 
Example #30
Source File: AnalyticFeatureTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Test
public void testGeometryCreation() throws MismatchedDimensionException,
    NoSuchAuthorityCodeException, FactoryException, CQLException, ParseException {
  final SimpleFeatureType ftype =
      AnalyticFeature.createGeometryFeatureAdapter(
          "centroid",
          new String[] {"extra1"},
          BasicFeatureTypes.DEFAULT_NAMESPACE,
          ClusteringUtils.CLUSTERING_CRS).getFeatureType();
  final GeometryFactory factory = new GeometryFactory();
  SimpleFeature feature =
      AnalyticFeature.createGeometryFeature(
          ftype,
          "b1",
          "123",
          "fred",
          "NA",
          20.30203,
          factory.createPoint(new Coordinate(02.33, 0.23)),
          new String[] {"extra1"},
          new double[] {0.022},
          1,
          1,
          0);
  assertEquals(
      new Coordinate(02.33, 0.23),
      ((Geometry) feature.getDefaultGeometry()).getCoordinate());
  System.out.println(((Geometry) feature.getDefaultGeometry()).getPrecisionModel());
  System.out.println(((Geometry) feature.getDefaultGeometry()).getEnvelope());

  feature =
      AnalyticFeature.createGeometryFeature(
          ftype,
          "b1",
          "123",
          "fred",
          "NA",
          20.30203,
          factory.createPoint(new Coordinate(02.33, 0.23)),
          new String[] {"extra1"},
          new double[] {0.022},
          10,
          1,
          0);

  assertEquals(
      new Coordinate(02.33, 0.23),
      ((Geometry) feature.getDefaultGeometry()).getCoordinate());

  assertEquals(
      "geometry",
      feature.getFeatureType().getGeometryDescriptor().getName().getLocalPart());

  assertEquals(
      new Integer(10),
      feature.getAttribute(ClusterFeatureAttribute.ZOOM_LEVEL.attrName()));

  Filter gtFilter = ECQL.toFilter("BBOX(geometry,2,0,3,1) and level = 10");
  assertTrue(gtFilter.evaluate(feature));
  gtFilter = ECQL.toFilter("BBOX(geometry,2,0,3,1) and level = 9");
  assertFalse(gtFilter.evaluate(feature));
  gtFilter = ECQL.toFilter("BBOX(geometry,2,0,3,1) and batchID = 'b1'");
  assertTrue(gtFilter.evaluate(feature));
}