Java Code Examples for org.opengis.filter.Filter#toString()

The following examples show how to use org.opengis.filter.Filter#toString() . 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: HibernateLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Bounds are calculated locally, can use any filter, but slower than native.
 * 
 * @param filter
 *            filter which needs to be applied
 * @return the bounds of the specified features
 * @throws LayerException
 *             oops
 */
private Envelope getBoundsLocal(Filter filter) throws LayerException {
	try {
		Session session = getSessionFactory().getCurrentSession();
		Criteria criteria = session.createCriteria(getFeatureInfo().getDataSourceName());
		CriteriaVisitor visitor = new CriteriaVisitor((HibernateFeatureModel) getFeatureModel(), dateFormat);
		Criterion c = (Criterion) filter.accept(visitor, criteria);
		if (c != null) {
			criteria.add(c);
		}
		criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
		List<?> features = criteria.list();
		Envelope bounds = new Envelope();
		for (Object f : features) {
			Envelope geomBounds = getFeatureModel().getGeometry(f).getEnvelopeInternal();
			if (!geomBounds.isNull()) {
				bounds.expandToInclude(geomBounds);
			}
		}
		return bounds;
	} catch (HibernateException he) {
		throw new HibernateLayerException(he, ExceptionCode.HIBERNATE_LOAD_FILTER_FAIL, getFeatureInfo()
				.getDataSourceName(), filter.toString());
	}
}
 
Example 2
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBinaryTemporal() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    Date date1 = null;
    try {
        date1 = FORMAT.parse("2001-07-05T12:08:56.235-0700");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));

    // Simple check if property is after provided temporal instant
    Filter filter = ff.after(ff.property("date"), ff.literal(temporalInstant));

    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 3
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testInFunction() {

    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    List<Expression> expList = new ArrayList<Expression>();
    expList.add(ff.literal(1));
    expList.add(ff.literal(2));

    Function func = functionFactory.function("in", expList, null);
    Filter filter = ff.equal(func, ff.literal(true), true);
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 4
Source File: HibernateLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This implementation does not support the 'offset' parameter. The maxResultSize parameter is not used (limiting
 * the result needs to be done after security {@link org.geomajas.internal.layer.vector.GetFeaturesEachStep}). If
 * you expect large results to be returned enable scrollableResultSet to retrieve only as many records as needed.
 */
public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException {
	try {
		Session session = getSessionFactory().getCurrentSession();
		Criteria criteria = session.createCriteria(getFeatureInfo().getDataSourceName());
		if (filter != null) {
			if (filter != Filter.INCLUDE) {
				CriteriaVisitor visitor = new CriteriaVisitor((HibernateFeatureModel) featureModel, dateFormat);
				Criterion c = (Criterion) filter.accept(visitor, criteria);
				if (c != null) {
					criteria.add(c);
				}
			}
		}

		// Sorting of elements.
		if (getFeatureInfo().getSortAttributeName() != null) {
			if (SortType.ASC.equals(getFeatureInfo().getSortType())) {
				criteria.addOrder(Order.asc(getFeatureInfo().getSortAttributeName()));
			} else {
				criteria.addOrder(Order.desc(getFeatureInfo().getSortAttributeName()));
			}
		}

		criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

		if (isScrollableResultSet()) {
			return (Iterator<?>) new ScrollIterator(criteria.scroll());
		} else {
			List<?> list = criteria.list();
			return list.iterator();
		}
	} catch (HibernateException he) {
		throw new HibernateLayerException(he, ExceptionCode.HIBERNATE_LOAD_FILTER_FAIL, getFeatureInfo()
				.getDataSourceName(), filter.toString());
	}
}
 
Example 5
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWithin() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.within(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 6
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTouches() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.touches(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 7
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOverlappedBy() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.overlappedBy(ff.property("age"), ff.literal(1));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 8
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEquals() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.equals(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 9
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBeyond() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.beyond(ff.property("the_geom"), ff.literal(bbox), 10.0, "km");
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 10
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfter() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.after(ff.property("age"), ff.literal(1));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 11
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDisjoint() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.disjoint(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 12
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCrosses() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.crosses(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 13
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testMetBy() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.metBy(ff.property("age"), ff.literal(1));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 14
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBBox() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.bbox(ff.property("the_geom"), bbox);
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 15
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBetween() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.between(ff.property("age"), ff.literal(1), ff.literal(10));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 16
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testMeets() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.meets(ff.property("age"), ff.literal(1));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 17
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.filter.v2.expression.FilterPanelv2#getFilter()}. */
@Test
public void testIsNull() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.isNull(ff.property("approved"));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 18
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLike() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.like(ff.property("code"), "2300%");
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 19
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAnyInteracts() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.anyInteracts(ff.property("age"), ff.literal(1));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 20
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBegunBy() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    Filter filter = ff.begunBy(ff.property("age"), ff.literal(1));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}