@SuppressWarnings("unchecked") public int compare(SimpleFeature f1, SimpleFeature f2) { Object value1 = propertyName.evaluate(f1, Comparable.class); Object value2 = propertyName.evaluate(f2, Comparable.class); if (value1 == null || value2 == null) { return 0; // cannot perform comparison } if (value1 instanceof Comparable && value1.getClass().isInstance(value2)) { if (sortOrder == SortOrder.ASCENDING) { return ((Comparable<Object>) value1).compareTo(value2); } else { return ((Comparable<Object>) value2).compareTo(value1); } } else { return 0; // cannot perform comparison } } };
public boolean isComplexType(final StepList attrXPath, final AttributeDescriptor featureType) { PropertyName attExp = FF.property(attrXPath.toString()); Object type = attExp.evaluate(featureType); if (type == null) { type = attExp.evaluate(featureType); throw new IllegalArgumentException("path not found: " + attrXPath); } AttributeDescriptor node = (AttributeDescriptor) type; return node.getType() instanceof ComplexType; }
@SuppressWarnings("unchecked") protected int compare( SimpleFeature feature1, SimpleFeature feature2, SortBy order) { PropertyName name = order.getPropertyName(); Comparable value1 = (Comparable) name.evaluate(feature1); Comparable value2 = (Comparable) name.evaluate(feature2); if (value1 == value2) { return 0; } if (order.getSortOrder() == SortOrder.ASCENDING) { if (value1 == null) { return -1; } return value1.compareTo(value2); } else { if (value2 == null) { return -1; } return value2.compareTo(value1); } } });
@Override public Object visit(PropertyName expression, Object extraData) { AttributeDescriptor ad = expression.evaluate(schema, AttributeDescriptor.class); if (ad == null) { throw new IllegalArgumentException( "Original feature type does not have a property named " + expression.getPropertyName()); } else if (ad instanceof GeometryDescriptor) { return ((GeometryDescriptor) ad).getCoordinateReferenceSystem(); } return null; }
/** * Returns the type cast needed to match this property * * @param pn * @return */ String getArrayTypeCast(PropertyName pn) { AttributeDescriptor at = pn.evaluate(delegate.getFeatureType(), AttributeDescriptor.class); if (at != null) { Object value = at.getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME); if (value instanceof String) { String typeName = (String) value; if (typeName.startsWith("_")) { return "::" + typeName.substring(1) + "[]"; } } } return ""; }
public boolean evaluate(Object feature) { if (feature == null) return false; Geometry other = (Geometry) property.evaluate(feature); if (other == null) return false; return other.getEnvelopeInternal().intersects(envelope); }
@Override public Object visit(PropertyName expression, Object extraData) { AttributeDescriptor ad = expression.evaluate(featureType, AttributeDescriptor.class); if (ad != null) { return ad.getType().getBinding(); } else { return Object.class; } } }
/** * Helper method for executing a property name against a feature type. * * <p>This method will fall back on {@link PropertyName#getPropertyName()} if it does not * evaulate against the feature type. */ protected String getPropertyName(SimpleFeatureType featureType, PropertyName propertyName) { AttributeDescriptor att = (AttributeDescriptor) propertyName.evaluate(featureType); if (att != null) { return att.getLocalName(); } return propertyName.getPropertyName(); }
public Object evaluate(Object feature) { String name = getExpression(0).evaluate(feature, String.class); if (name == null) { return null; } PropertyName pn = lastPropertyName; if (pn != null && pn.getPropertyName().equals(name)) { return pn.evaluate(feature); } else { pn = FF.property(name); Object result = pn.evaluate(feature); lastPropertyName = pn; return result; } } }
public Object visit(PropertyName expression, Object data) { if (data != null && data != attributeNames) { attributeNames = (Set<String>) data; } propertyNames.add(expression); if (featureType != null) { // evaluate against the feature type instead of using straight name // since the path from the property name may be an XPath or a // namespace prefixed string AttributeDescriptor type = (AttributeDescriptor) expression.evaluate(featureType); if (type != null) { attributeNames.add(type.getLocalName()); } else { attributeNames.add(expression.getPropertyName()); } } else { attributeNames.add(expression.getPropertyName()); } return attributeNames; }
public Object visit(PropertyName expression, Object notUsed) { // JD: use an expression to get at the attribute type intead of accessing directly if (parent != null && expression.evaluate(parent) == null) { throw new IllegalArgumentException( "Property '" + expression.getPropertyName() + "' could not be found in " + parent.getTypeName()); } if (transactionAccessor != null) { Filter updateFilter = (Filter) transactionAccessor.getUpdateFilter(expression.getPropertyName()); if (updateFilter != null) { changedStack.add(updateFilter); preStack.push(updateFilter); } else preStack.push(expression); } else { preStack.push(expression); } return null; }
public boolean evaluate(Object feature) { Geometry other = Converters.convert(property.evaluate(feature), Geometry.class); if (other == null) return false; return get3DEnvelope(other).intersects(envelope); }
@Override public Object visit(PropertyName expression, Object extraData) { AttributeDescriptor result = expression.evaluate(schema, AttributeDescriptor.class); if (result == null) { throw new IllegalArgumentException( "Original feature type does not have a property named " + expression.getPropertyName()); } if (result instanceof GeometryDescriptor) { this.crs = ((GeometryDescriptor) result).getCoordinateReferenceSystem(); } return result.getType().getBinding(); }
public Object visit(PropertyName expression, Object extraData) { if ("".equals(expression.getPropertyName())) { return super.visit(expression, extraData); } AttributeDescriptor att = expression.evaluate(featureType, null); if (att != null) { return getFactory(extraData).property(att.getLocalName()); } return super.visit(expression, extraData); } }
@Override public Object evaluate(Object object) { PropertyName name = (PropertyName) getParameters().get(0); Object literal = getParameters().get(1).evaluate(null); Object o = name.evaluate(object); return o.equals(Converters.convert(literal, o.getClass())); } }
/** * Finds the CRS of the specified attribute (or uses the default geometry instead) * * @param geomName * @param schema * @return */ org.opengis.referencing.crs.CoordinateReferenceSystem getAttributeCRS( PropertyName geomName, FeatureType schema) { if (geomName == null || "".equals(geomName.getPropertyName())) { GeometryDescriptor geom = schema.getGeometryDescriptor(); return geom.getType().getCoordinateReferenceSystem(); } else { GeometryDescriptor geom = (GeometryDescriptor) geomName.evaluate(schema); return geom.getType().getCoordinateReferenceSystem(); } }
private void setDefaultGeometryAttribute(Feature feature) { String defaultGeomXPath = mapping.getDefaultGeometryXPath(); if (defaultGeomXPath != null && !defaultGeomXPath.isEmpty()) { GeometryDescriptor defaultGeomDescr = feature.getType().getGeometryDescriptor(); if (defaultGeomDescr != null) { PropertyName geomProperty = filterFac.property(defaultGeomXPath, namespaces); Object geomValue = geomProperty.evaluate(feature); if (geomValue instanceof Collection) { throw new RuntimeException( "Error setting default geometry value: multiple values were found"); } String geomName = Types.toPrefixedName(defaultGeomDescr.getName(), namespaces); StepList fakeDefaultGeomXPath = XPath.steps(targetFeature, geomName, namespaces); xpathAttributeBuilder.set( feature, fakeDefaultGeomXPath, geomValue, null, null, false, null); } } }
/** * Checks for sorting support in the given sort order for a specific attribute type, given by a * PropertyName expression. * * <p>This default implementation assumes both orders are supported as long as the property name * corresponds to the name of one of the attribute types in the complete FeatureType, and that * the attribute is not a geometry. * * @param propertyName the expression holding the property name to check for sortability support * @param sortOrder the order, ascending or descending, to check for sortability support over * the given property name. * @return true if propertyName refers to one of the FeatureType attributes */ protected boolean supportsPropertySorting(PropertyName propertyName, SortOrder sortOrder) { AttributeDescriptor descriptor = (AttributeDescriptor) propertyName.evaluate(source.getSchema()); if (descriptor == null) { String attName = propertyName.getPropertyName(); descriptor = source.getSchema().getDescriptor(attName); } return descriptor != null && !(Geometry.class.isAssignableFrom(descriptor.getType().getBinding())); }
private void next() { if (iterator.hasNext()) { this.currentFeature = iterator.next(); // update the current key for (int i = 0; i < sortBy.length; i++) { SortBy sb = sortBy[i]; if (sb == SortBy.NATURAL_ORDER || sb == SortBy.REVERSE_ORDER) { currentKey.components[i] = currentFeature.getIdentifier().getID(); } else { Object value = sb.getPropertyName().evaluate(currentFeature); currentKey.components[i] = value; } } } else { // mark as complete but don't close, we might have // other fts to paint complete = true; } }
@Test public void testRetrieveTimeInstantGmlId() throws IOException { FilterFactory2 ff = new FilterFactoryImplNamespaceAware(namespaces); PropertyName gmlIdProperty = ff.property("om:resultTime/gml:TimeInstant/@gml:id"); try (FeatureIterator featureIt = obsSource.getFeatures().features()) { Feature f = featureIt.next(); String gmlId = (String) gmlIdProperty.evaluate(f); assertTrue(gmlId != null && !gmlId.trim().isEmpty()); } } }