Java Code Examples for org.opengis.filter.Filter#accept()
The following examples show how to use
org.opengis.filter.Filter#accept() .
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: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
/** * Common implementation for BinaryLogicOperator filters. This way * they're all handled centrally. * * @param filter the logic statement. * @param extraData extra filter data. Not modified directly by this method. */ private Object visit(BinaryLogicOperator filter, Object extraData) { LOGGER.finest("exporting LogicFilter"); final List<Map<String,Object>> filters = new ArrayList<>(); for (final Filter child : filter.getChildren()) { child.accept(this, extraData); filters.add(queryBuilder); } if (extraData.equals("AND")) { queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", filters)); } else if (extraData.equals("OR")) { queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("should", filters)); } return extraData; }
Example 2
Source File: ExtractGeometryFilterVisitor.java From geowave with Apache License 2.0 | 6 votes |
/** * @param filter * @param crs * @return null if empty constraint (infinite not supported) */ public static ExtractGeometryFilterVisitorResult getConstraints( final Filter filter, final CoordinateReferenceSystem crs, final String attributeOfInterest) { final ExtractGeometryFilterVisitorResult geoAndCompareOpData = (ExtractGeometryFilterVisitorResult) filter.accept( new ExtractGeometryFilterVisitor(crs, attributeOfInterest), null); if (geoAndCompareOpData == null) { return null; } final Geometry geo = geoAndCompareOpData.getGeometry(); // empty or infinite geometry simply return null as we can't create // linear constraints from if ((geo == null) || geo.isEmpty()) { return null; } final double area = geo.getArea(); if (Double.isInfinite(area) || Double.isNaN(area)) { return null; } return geoAndCompareOpData; }
Example 3
Source File: ExtractTimeFilterVisitor.java From geowave with Apache License 2.0 | 6 votes |
@Override public Object visit(final Or filter, final Object data) { final TemporalConstraintsSet constraints = new TemporalConstraintsSet(); for (final Filter f : filter.getChildren()) { final Object output = f.accept(this, data); if (output instanceof ParameterTimeConstraint) { final ParameterTimeConstraint ranges = (ParameterTimeConstraint) output; constraints.getConstraintsFor(ranges.getName()).replaceWithMerged(ranges); } else if (output instanceof TemporalConstraintsSet) { final TemporalConstraintsSet rangeSet = (TemporalConstraintsSet) output; for (final Map.Entry<String, TemporalConstraints> entry : rangeSet.getSet()) { constraints.getConstraintsFor(entry.getKey()).replaceWithMerged(entry.getValue()); } } } return constraints; }
Example 4
Source File: HibernateLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Override public List<Attribute<?>> getAttributes(String attributeName, Filter filter) throws LayerException { if (attributeName == null) { throw new HibernateLayerException(ExceptionCode.ATTRIBUTE_UNKNOWN, (Object) null); } AssociationAttributeInfo attributeInfo = getRecursiveAttributeInfo(attributeName, getFeatureInfo() .getAttributes()); Session session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(attributeInfo.getFeature().getDataSourceName()); CriteriaVisitor visitor = new CriteriaVisitor((HibernateFeatureModel) getFeatureModel(), dateFormat); if (filter != null) { Criterion c = (Criterion) filter.accept(visitor, null); if (c != null) { criteria.add(c); } } List<Attribute<?>> attributes = new ArrayList<Attribute<?>>(); for (Object object : criteria.list()) { try { attributes.add(converterService.toDto(object, attributeInfo)); } catch (GeomajasException e) { throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_ATTRIBUTE_TYPE_PROBLEM, attributeName); } } return attributes; }
Example 5
Source File: HibernateLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * 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 6
Source File: ElasticCapabilities.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Override public boolean fullySupports(Filter filter) { if( fullySupportedVisitor == null ){ fullySupportedVisitor = new ElasticIsFullySupportedFilterVisitor(); } return filter != null ? (Boolean) filter.accept( fullySupportedVisitor, null ) : false; }
Example 7
Source File: FilterToCQLTool.java From geowave with Apache License 2.0 | 5 votes |
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 8
Source File: ExtractGeometryFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
@Override public Object visit(final And filter, final Object data) { ExtractGeometryFilterVisitorResult finalResult = null; for (final Filter f : filter.getChildren()) { final Object obj = f.accept(this, data); if ((obj != null) && (obj instanceof ExtractGeometryFilterVisitorResult)) { final ExtractGeometryFilterVisitorResult currentResult = (ExtractGeometryFilterVisitorResult) obj; final Geometry currentGeom = currentResult.getGeometry(); final double currentArea = currentGeom.getArea(); if (finalResult == null) { finalResult = currentResult; } else if (!Double.isInfinite(currentArea) && !Double.isNaN(currentArea)) { // if predicates match then we can combine the geometry as // well as predicate if (currentResult.matchPredicate(finalResult)) { finalResult = new ExtractGeometryFilterVisitorResult( finalResult.getGeometry().intersection(currentGeom), currentResult.getCompareOp()); } else { // if predicate doesn't match then still combine // geometry but set predicate to null finalResult = new ExtractGeometryFilterVisitorResult( finalResult.getGeometry().intersection(currentGeom), null); } } else { finalResult = new ExtractGeometryFilterVisitorResult(finalResult.getGeometry(), null); } } } return finalResult; }
Example 9
Source File: ExtractGeometryFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
@Override public Object visit(final Or filter, final Object data) { ExtractGeometryFilterVisitorResult finalResult = new ExtractGeometryFilterVisitorResult( new GeometryFactory().toGeometry(new Envelope()), null); for (final Filter f : filter.getChildren()) { final Object obj = f.accept(this, data); if ((obj != null) && (obj instanceof ExtractGeometryFilterVisitorResult)) { final ExtractGeometryFilterVisitorResult currentResult = (ExtractGeometryFilterVisitorResult) obj; final Geometry currentGeom = currentResult.getGeometry(); final double currentArea = currentGeom.getArea(); if (finalResult.getGeometry().isEmpty()) { finalResult = currentResult; } else if (!Double.isInfinite(currentArea) && !Double.isNaN(currentArea)) { if (currentResult.matchPredicate(finalResult)) { finalResult = new ExtractGeometryFilterVisitorResult( finalResult.getGeometry().union(currentGeom), currentResult.getCompareOp()); } else { finalResult = new ExtractGeometryFilterVisitorResult( finalResult.getGeometry().union(currentGeom), null); } } else { finalResult = new ExtractGeometryFilterVisitorResult(finalResult.getGeometry(), null); } } } if (finalResult.getGeometry().isEmpty()) { return new ExtractGeometryFilterVisitorResult(infinity(), null); } return finalResult; }
Example 10
Source File: ExtractTimeFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
private TemporalConstraintsSet getRawConstraints(final Filter filter) { final Object output = filter.accept(this, null); if (output instanceof TemporalConstraintsSet) { return (TemporalConstraintsSet) output; } else if (output instanceof ParameterTimeConstraint) { final ParameterTimeConstraint paramConstraint = (ParameterTimeConstraint) output; final TemporalConstraintsSet constraintSet = new TemporalConstraintsSet(); constraintSet.getConstraintsFor(paramConstraint.getName()).replaceWithMerged(paramConstraint); return constraintSet; } return new TemporalConstraintsSet(); }
Example 11
Source File: HibernateLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 12
Source File: ExtractTimeFilterVisitor.java From geowave with Apache License 2.0 | 4 votes |
@Override public Object visit(final And filter, final Object data) { final TemporalConstraintsSet constraints = new TemporalConstraintsSet(); for (final Filter f : filter.getChildren()) { final Object output = f.accept(this, data); if (output instanceof ParameterTimeConstraint) { final ParameterTimeConstraint ranges = (ParameterTimeConstraint) output; constraints.getConstraintsFor(ranges.getName()).replaceWithIntersections(ranges); } else if (output instanceof TemporalConstraintsSet) { final TemporalConstraintsSet rangeSet = (TemporalConstraintsSet) output; for (final Map.Entry<String, TemporalConstraints> entry : rangeSet.getSet()) { constraints.getConstraintsFor(entry.getKey()).replaceWithIntersections(entry.getValue()); } } } for (final String[] range : validParamRanges) { if (constraints.hasConstraintsFor(range[0]) && constraints.hasConstraintsFor(range[1])) { final TemporalConstraints start = constraints.getConstraintsFor(range[0]); final TemporalConstraints end = constraints.getConstraintsFor(range[1]); constraints.removeConstraints(range[0], range[1]); // TODO: make this logic more robust if (start.getEndRange().getEndTime().after(end.getStartRange().getStartTime())) { // does this really make sense? seems like start should always be the start time and end // should always be the end time, but perhaps with multiple and's and or's it probably // gets complicated such that this is the only working logic constraints.getConstraintsForRange(range[0], range[1]).add( new TemporalRange( end.getStartRange().getStartTime(), start.getEndRange().getEndTime())); } else { // if there are multiple non-instersecting ranges, this is // an approximation approximation |= (start.getRanges().size() > 1) || (end.getRanges().size() > 1); constraints.getConstraintsForRange(range[0], range[1]).add( new TemporalRange( start.getStartRange().getStartTime(), end.getEndRange().getEndTime())); } } } return constraints; }
Example 13
Source File: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 2 votes |
/** * Performs the encoding. * * @param filter the Filter to be encoded. * * @throws FilterToElasticException If there were io problems. */ public void encode(Filter filter) throws FilterToElasticException { fullySupported = getCapabilities().fullySupports(filter); filter.accept(this, null); }