org.opengis.filter.expression.PropertyName Java Examples

The following examples show how to use org.opengis.filter.expression.PropertyName. 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: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private void visitDistanceSpatialOperator(DistanceBufferOperator filter,
                                          PropertyName property, Literal geometry, boolean swapped,
                                          Object extraData) {

    property.accept(delegate, extraData);
    key = (String) delegate.field;
    geometry.accept(delegate, extraData);
    final Geometry geo = delegate.currentGeometry;
    double lat = geo.getCentroid().getY();
    double lon = geo.getCentroid().getX();
    final double inputDistance = filter.getDistance();
    final String inputUnits = filter.getDistanceUnits();
    double distance = Double.valueOf(toMeters(inputDistance, inputUnits));

    delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL,
            "filter", ImmutableMap.of("geo_distance", 
                    ImmutableMap.of("distance", distance +"m", key, ImmutableList.of(lon, lat)))));

    if ((filter instanceof DWithin && swapped)
            || (filter instanceof Beyond && !swapped)) {
        delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must_not", delegate.queryBuilder));
    }
}
 
Example #2
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private void visitComparisonSpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry,
                                            boolean swapped, Object extraData) {

    // if geography case, sanitize geometry first
    Literal geometry1 = clipToWorld(geometry);

    //noinspection RedundantCast
    visitBinarySpatialOperator(filter, (Expression)property, (Expression) geometry1, swapped, extraData);

    // if geography case, sanitize geometry first
    if(isWorld(geometry1)) {
        // nothing to filter in this case
        delegate.queryBuilder = MATCH_ALL;
        return;
    } else if(isEmpty(geometry1)) {
        if(!(filter instanceof Disjoint)) {
            delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must_not", MATCH_ALL));
        } else {
            delegate.queryBuilder = MATCH_ALL;
        }
        return;
    }

    //noinspection RedundantCast
    visitBinarySpatialOperator(filter, (Expression)property, (Expression) geometry1, swapped, extraData);
}
 
Example #3
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private Object visitBinaryTemporalOperator(BinaryTemporalOperator filter,
                                           Object extraData) {
    if (filter == null) {
        throw new NullPointerException("Null filter");
    }

    Expression e1 = filter.getExpression1();
    Expression e2 = filter.getExpression2();

    if (e1 instanceof Literal && e2 instanceof PropertyName) {
        e1 = filter.getExpression2();
        e2 = filter.getExpression1();
    }

    if (e1 instanceof PropertyName && e2 instanceof Literal) {
        //call the "regular" method
        return visitBinaryTemporalOperator(filter, (PropertyName)e1, (Literal)e2, 
                filter.getExpression1() instanceof Literal, extraData);
    }
    else {
        //call the join version
        return visitBinaryTemporalOperator();
    }
}
 
Example #4
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Filter createCompareFilter(String name, String comparator, Date value) {
	PropertyName attribute = FF.property(name);
	Expression val = FF.literal(value);
	if ("<".equals(comparator)) {
		return FF.less(attribute, val);
	} else if (">".equals(comparator)) {
		return FF.greater(attribute, val);
	} else if (">=".equals(comparator)) {
		return FF.greaterOrEqual(attribute, val);
	} else if ("<=".equals(comparator)) {
		return FF.lessOrEqual(attribute, val);
	} else if ("=".equals(comparator)) {
		return FF.equals(attribute, val);
	} else if ("==".equals(comparator)) {
		return FF.equals(attribute, val);
	} else if ("<>".equals(comparator)) {
		return FF.notEqual(attribute, val, false);
	} else {
		throw new IllegalArgumentException("Could not interpret compare filter. Argument (" + value
				+ ") not known.");
	}
}
 
Example #5
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Filter createCompareFilter(String name, String comparator, String value) {
	PropertyName attribute = FF.property(name);
	Expression val = FF.literal(value);
	if ("<".equals(comparator)) {
		return FF.less(attribute, val);
	} else if (">".equals(comparator)) {
		return FF.greater(attribute, val);
	} else if (">=".equals(comparator)) {
		return FF.greaterOrEqual(attribute, val);
	} else if ("<=".equals(comparator)) {
		return FF.lessOrEqual(attribute, val);
	} else if ("=".equals(comparator)) {
		return FF.equals(attribute, val);
	} else if ("==".equals(comparator)) {
		return FF.equals(attribute, val);
	} else if ("<>".equals(comparator)) {
		return FF.notEqual(attribute, val, false);
	} else {
		throw new IllegalArgumentException("Could not interpret compare filter. Argument (" + value
				+ ") not known.");
	}
}
 
Example #6
Source File: FilterToCQLTool.java    From geowave with Apache License 2.0 6 votes vote down vote up
public FixedDWithinImpl(
    final Expression e1,
    final Expression e2,
    final String units,
    final double distance) throws IllegalFilterException, TransformException {
  super(
      new LiteralExpressionImpl(
          GeometryUtils.buffer(
              getCRS(e1, e2),
              e1 instanceof PropertyName
                  ? e2.evaluate(null, org.locationtech.jts.geom.Geometry.class)
                  : e1.evaluate(null, org.locationtech.jts.geom.Geometry.class),
              units,
              distance).getLeft()),
      e1 instanceof PropertyName ? e1 : e2);
  this.units = units;
  this.distance = distance;
}
 
Example #7
Source File: FilterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testParseFidFilter() throws GeomajasException {
	Filter f1 = filterService.parseFilter("IN( 1 )");
	Filter f2 = filterService.parseFilter("a.@id = 1");
	Assert.assertTrue(f1 instanceof Id);
	Assert.assertTrue(f2 instanceof PropertyIsEqualTo);
	PropertyIsEqualTo piet = (PropertyIsEqualTo)f2;
	Assert.assertTrue(piet.getExpression1() instanceof PropertyName);
	Assert.assertEquals("a/@id",((PropertyName)piet.getExpression1()).getPropertyName());
	
}
 
Example #8
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
Object visitBinarySpatialOperator(BinarySpatialOperator filter,
                                  PropertyName property, Literal geometry, boolean swapped,
                                  Object extraData) {

    if (filter instanceof DistanceBufferOperator) {
        visitDistanceSpatialOperator((DistanceBufferOperator) filter,
                property, geometry, swapped, extraData);
    } else {
        visitComparisonSpatialOperator(filter, property, geometry,
                swapped, extraData);
    }
    return extraData;
}
 
Example #9
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Filter createBetweenFilter(String name, String lower, String upper) {
	PropertyName attribute = FF.property(name);
	Expression d1 = FF.literal(lower);
	Expression d2 = FF.literal(upper);
	return FF.between(attribute, d1, d2);
}
 
Example #10
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get the property name from the expression.
 * 
 * @param expression expression
 * @return property name
 */
private String getPropertyName(Expression expression) {
	if (!(expression instanceof PropertyName)) {
		throw new IllegalArgumentException("Expression " + expression + " is not a PropertyName.");
	}
	String name = ((PropertyName) expression).getPropertyName();
	if (name.endsWith(FilterService.ATTRIBUTE_ID)) {
		// replace by Hibernate id property, always refers to the id, even if named differently
		name = name.substring(0, name.length() - FilterService.ATTRIBUTE_ID.length()) + HIBERNATE_ID;
	}
	return name;
}
 
Example #11
Source File: ExtractTimeFilterVisitor.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public Object visit(final PropertyName expression, final Object data) {
  final String name = expression.getPropertyName();
  if (validateName(expression.getPropertyName())) {
    // for (final String[] range : validParamRanges) {
    // if (range[0].equals(name) || range[1].equals(name)) {
    // return new ParameterTimeConstraint(
    // range[0] + "_" + range[1]);
    // }
    // }
    return new ParameterTimeConstraint(name);
  }
  return new TemporalConstraints();
}
 
Example #12
Source File: ExtractAttributesFilter.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public Object visit(final PropertyName expression, final Object data) {
  if ((data != null) && (data instanceof Collection)) {
    ((Collection) data).add(expression.getPropertyName());
    return data;
  }
  final Set<String> names = new HashSet<>();
  names.add(expression.getPropertyName());
  return names;
}
 
Example #13
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Writes the FilterBuilder for the attribute Expression.
 * 
 * @param expression the attribute.
 *
 */
@Override
public Object visit(PropertyName expression, Object extraData) {
    LOGGER.finest("exporting PropertyName");

    SimpleFeatureType featureType = this.featureType;

    Class<?> target = null;
    if(extraData instanceof Class) {
        target = (Class<?>) extraData;
    }

    //first evaluate expression against feature type get the attribute, 
    AttributeDescriptor attType = (AttributeDescriptor) expression.evaluate(featureType);

    String encodedField; 
    if ( attType != null ) {
        Map<Object, Object> userData = attType.getUserData();
        if( userData != null && userData.containsKey("full_name") ) {
            encodedField = userData.get("full_name").toString();
        } else {
            encodedField = attType.getLocalName();
        }
        if(target != null && target.isAssignableFrom(attType.getType().getBinding())) {
            // no need for casting, it's already the right type
            target = null;
        }
    } else {
        // fall back to just encoding the property name
        encodedField = expression.getPropertyName();
    }

    if (target != null) {
        LOGGER.fine("PropertyName type casting not implemented");
    }
    field = encodedField;

    return extraData;
}
 
Example #14
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
private Object visitBinarySpatialOperator(BinarySpatialOperator filter,
                                          Object extraData) {
    // basic checks
    if (filter == null)
        throw new NullPointerException(
                "Filter to be encoded cannot be null");

    // extract the property name and the geometry literal
    Expression e1 = filter.getExpression1();
    Expression e2 = filter.getExpression2();

    if (e1 instanceof Literal && e2 instanceof PropertyName) {
        e1 = filter.getExpression2();
        e2 = filter.getExpression1();
    }

    if (e1 instanceof PropertyName && e2 instanceof Literal) {
        //call the "regular" method
        return visitBinarySpatialOperator(filter, (PropertyName)e1, (Literal)e2, filter
                .getExpression1() instanceof Literal, extraData);
    }
    else {
        //call the join version
        return visitBinarySpatialOperator(filter, e1, e2, extraData);
    }

}
 
Example #15
Source File: ExtractGeometryFilterVisitor.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Object visit(final PropertyName expression, final Object data) {
  return new ExtractGeometryFilterVisitorResult(null, null);
}
 
Example #16
Source File: OmsVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * You cannot call this once the dialog is closed, see the okPressed method.
 * @param originalFeatureType 
 * @param expressions 
 * @param names 
 * @return a SimpleFeatureType created based on the contents of Text
 */
private SimpleFeatureType createFeatureType( String expressionString, SimpleFeatureType originalFeatureType,
        List<String> names, List<Expression> expressions ) throws SchemaException {

    SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();

    for( int i = 0; i < names.size(); i++ ) {
        String name = names.get(i);

        Expression expression = expressions.get(i);

        Object value = expression.evaluate(sample);

        // hack because sometimes expression returns null. I think the real bug is with
        // AttributeExpression
        Class< ? > binding = null;
        if (value == null) {
            if (expression instanceof PropertyName) {
                String path = ((PropertyName) expression).getPropertyName();
                AttributeType attributeType = sample.getFeatureType().getType(path);
                if (attributeType == null) {
                    throw new ModelsIllegalargumentException("Attribute type is null", this.getClass().getSimpleName(), pm);
                }
                binding = attributeType.getClass();
            }
        } else {
            binding = value.getClass();
        }

        if (binding == null) {
            throw new ModelsIllegalargumentException("Binding is null", this.getClass().getSimpleName(), pm);
        }

        if (Geometry.class.isAssignableFrom(binding)) {
            CoordinateReferenceSystem crs;
            AttributeType originalAttributeType = originalFeatureType.getType(name);
            if (originalAttributeType instanceof GeometryType) {
                crs = ((GeometryType) originalAttributeType).getCoordinateReferenceSystem();
            } else {
                crs = originalFeatureType.getCoordinateReferenceSystem();
            }
            build.crs(crs);

            build.add(name, binding);
        } else {
            build.add(name, binding);
        }
    }
    build.setName(getNewTypeName(originalFeatureType.getTypeName()));

    return build.buildFeatureType();
}
 
Example #17
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Filter createLikeFilter(String name, String pattern) {

	PropertyName attribute = FF.property(name);
	return FF.like(attribute, pattern, "*", "?", "\\");
}
 
Example #18
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
private Object visitBinarySpatialOperator(BinarySpatialOperator filter,
                                          PropertyName property, Literal geometry, boolean swapped,
                                          Object extraData) {
    return helper.visitBinarySpatialOperator(filter, property, geometry,
            swapped, extraData);
}
 
Example #19
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Object visit(PropertyName expression, Object extraData) {
	return getFactory(extraData).property(replaceId(expression.getPropertyName()),
			expression.getNamespaceContext());
}
 
Example #20
Source File: NonLenientFilterFactoryImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public PropertyName property(String name) {
	AttributeExpressionImpl expression = (AttributeExpressionImpl) super.property(name);
	expression.setLenient(false);
	return expression;
}
 
Example #21
Source File: NonLenientFilterFactoryImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public PropertyName property(Name name) {
	AttributeExpressionImpl expression = (AttributeExpressionImpl) super.property(name);
	expression.setLenient(false);
	return expression;
}
 
Example #22
Source File: NonLenientFilterFactoryImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public PropertyName property(String name, NamespaceSupport namespaceContext) {
	AttributeExpressionImpl expression = (AttributeExpressionImpl) super.property(name, namespaceContext);
	expression.setLenient(false);
	return expression;
}