ft.setId(Integer.toString(i)); } else { ft.setId(feature.getProperty(originIDField).getValue().toString()); val = (Integer)prop.getValue(); } else if(binding.equals(Long.class)){ val = ((Long)prop.getValue()).intValue(); } else if(binding.equals(String.class)){ try{ val = Integer.parseInt((String)prop.getValue()); } catch (NumberFormatException ex ){ continue;
value = buildComplex((ComplexAttribute) property); } else if (property != null) { value = property.getValue();
public void setValue(Collection<Property> value) { int i = 0; for (Property p : value) { this.values[i] = p.getValue(); } }
public void setValue(Collection<Property> values) { int i = 0; for (Property p : values) { this.values[i++] = p.getValue(); } }
public Attribute set(int index, Property element) { values[index] = element.getValue(); return null; }
public Object get(Object object, String xpath, Class target) throws IllegalArgumentException { return ((Property) object).getValue(); }
/** * Return the simple content of a {@link ComplexAttribute} if it represents a complexType with * simpleContent, otherwise null. * * @param complex * @return */ public static Object getSimpleContent(ComplexAttribute complex) { Property simpleContent = complex.getProperty(new NameImpl("simpleContent")); if (simpleContent == null) { return null; } else { return simpleContent.getValue(); } }
/** @see AbstractComplexBinding#getProperty(java.lang.Object, javax.xml.namespace.QName) */ @Override public Object getProperty(Object object, QName name) throws Exception { if (object instanceof ComplexAttribute) { ComplexAttribute complex = (ComplexAttribute) object; Property property = complex.getProperty(toTypeName(name)); if (property != null && !(property instanceof ComplexAttribute)) { return property.getValue(); } if ("id".equals(name.getLocalPart())) { return complex.getIdentifier(); } } return null; }
/** * Unpacks a value from an attribute container * * @param value * @return */ public static Object unpack(Object value) { if (value instanceof org.opengis.feature.ComplexAttribute) { Property simpleContent = ((org.opengis.feature.ComplexAttribute) value).getProperty(SIMPLE_CONTENT); if (simpleContent == null) { return null; } else { return simpleContent.getValue(); } } if (value instanceof org.opengis.feature.Attribute) { return ((org.opengis.feature.Attribute) value).getValue(); } return value; } }
public void visit(Feature feature) { assertEquals(1, feature.getProperty("someAtt").getValue()); } },
/** * Perform the visitation of an individual Feature. * * @param feature The Feature to explore. */ protected void walker(Feature feature) { handler.handleFeature(feature); for (Property property : feature.getProperties()) { Class<?> binding = property.getType().getBinding(); // recurse if attribute type is another collection if (FeatureCollection.class.isAssignableFrom(binding)) { walker((FeatureCollection) property.getValue()); // } else if (type instanceof FeatureType) { } else if (Feature.class.isAssignableFrom(binding)) { // recurse if attribute type is another feature walker((Feature) property.getValue()); } else { // normal handling handler.handleAttribute(property.getDescriptor(), property.getValue()); } } handler.endFeature(feature); }
private void applySingleUpdate( QName remoteTypeName, SimpleFeature feature, TransactionRequest transactionRequest) throws IOException { // so bad, this is going to update a lot of unnecessary properties. We'd need to make // DiffContentFeatureWriter's live and current attributes protected and extend write so that // it records the truly modified attributes instead Collection<Property> properties = feature.getProperties(); List<QName> propertyNames = new ArrayList<QName>(); List<Object> newValues = new ArrayList<Object>(); for (Property p : properties) { QName attName = new QName(remoteTypeName.getNamespaceURI(), p.getName().getLocalPart()); Object attValue = p.getValue(); propertyNames.add(attName); newValues.add(attValue); } Filter updateFilter = dataStore.getFilterFactory().id(Collections.singleton(feature.getIdentifier())); Update update = transactionRequest.createUpdate( remoteTypeName, propertyNames, newValues, updateFilter); transactionRequest.add(update); }
/** * Unpacks a value from an attribute container * * @param value * @return */ private Object unpack(Object value) { if (value instanceof org.opengis.feature.ComplexAttribute) { Property simpleContent = ((org.opengis.feature.ComplexAttribute) value) .getProperty(new NameImpl("simpleContent")); if (simpleContent == null) { return null; } else { return simpleContent.getValue(); } } if (value instanceof org.opengis.feature.Attribute) { return ((org.opengis.feature.Attribute) value).getValue(); } return value; }
public void testGetPropertyNullValue() { assertNotNull(feature.getProperty("the_geom")); assertNull(feature.getProperty("the_geom").getValue()); }
public void testGetProperty() { assertEquals("ABC", feature.getProperty("name").getValue()); assertNull(feature.getProperty("NOWHERE")); assertEquals(0, feature.getProperties("NOWHERE").size()); }
/** * Helper method that tests that mappings files obtained through an hTTP request are correctly * handled, as well the included types and schemas. */ private void testHttpMapping(String mappingFileName) throws Exception { // instantiate a store for the mapping file AppSchemaDataAccess store = buildAppSchemaDataStore(mappingFileName); // check that a stations type is available assertThat(store.getTypeNames().length, is(1)); Name name = new NameImpl("http://www.stations.org/1.0", "Station"); assertThat(store.getTypeNames()[0], is(name)); // read the complex features FeatureIterator iterator = store.getFeatureSource(name).getFeatures().features(); List<Feature> features = new ArrayList<>(); while (iterator.hasNext()) { features.add(iterator.next()); } // three stations should be available assertThat(features.size(), is(3)); for (Feature feature : features) { // check that each station has at least a measurement Name measurements = new NameImpl("http://www.stations.org/1.0", "measurements"); Property property = feature.getProperty(measurements); assertThat(property.getValue(), instanceOf(List.class)); List values = (List) property.getValue(); assertThat(values.size() > 0, is(true)); } }
@Test public void testSweValues() { Map<String, String> expected = new HashMap<String, String>(); expected.put( "ID1.2", "missing missing 8.9 7.9 14.2 15.4 18.1 19.1 21.7 20.8 19.6 14.9 10.8 8.8 8.5 10.4"); expected.put( "ID2.2", "16.2 17.1 22.0 25.1 23.9 22.8 17.0 10.2 9.2 7.1 12.3 12.9 17.2 23.6 21.6 21.9 17.6 14.0 9.3 3.8"); FeatureIterator<? extends Feature> featIt = obsFeatures.features(); while (featIt.hasNext()) { Feature f = featIt.next(); PropertyName pf = ff.property("om:result/swe:DataArray/swe:values", namespaces); Object sweValues = pf.evaluate(f); assertNotNull(sweValues); assertTrue(sweValues instanceof ComplexAttribute); ComplexAttribute sweValuesAttr = (ComplexAttribute) sweValues; assertEquals( expected.get(f.getIdentifier().getID()), sweValuesAttr.getProperty(ComplexFeatureConstants.SIMPLE_CONTENT).getValue()); } } }
/** * Perform a "deep copy" an existing feature resuling in a duplicate of any geometry attributes. * * <p>This method is scary, expensive and will result in a deep copy of Geometry which may take * a significant amount of memory/time to perform. * * @param original Content * @return copy */ public static SimpleFeature deep(SimpleFeature original) { if (original == null) return null; SimpleFeatureBuilder builder = new SimpleFeatureBuilder(original.getFeatureType()); for (Property property : original.getProperties()) { Object value = property.getValue(); try { Object copy = value; if (value instanceof Geometry) { Geometry geometry = (Geometry) value; copy = geometry.copy(); } builder.set(property.getName(), copy); } catch (Exception e) { throw new IllegalAttributeException( (AttributeDescriptor) property.getDescriptor(), value, e); } } return builder.buildFeature(original.getID()); }
/** Test CategorizeFunction */ @Test public void testCategorizeFunction() { final Map<String, String> VALUE_MAP = new HashMap<String, String>() { { put("sc.1", "missing value"); put("sc.2", "a valid value"); put("sc.3", "a valid value"); } }; FeatureIterator<Feature> features = exCollection.features(); try { while (features.hasNext()) { Feature feature = features.next(); String fId = feature.getIdentifier().getID(); Property attribute = feature.getProperty("someAttribute"); // <OCQL>Categorize(getID(), 'missing value', 2, 'a valid value')</OCQL> assertEquals(attribute.getValue(), VALUE_MAP.get(fId)); } } finally { features.close(); } }
/** * Mapping specifies station_no --> wq_plus/@id. A FidFilter over wq_plus type should result in * a compare equals filter over the station_no attribute of wq_ir_results simple type. */ @Test public void testUnrollFidMappedToAttribute() throws Exception { String fid = "station_no.1"; Id fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); Filter unrolled = (Filter) fidFilter.accept(visitor, null); assertNotNull(unrolled); FeatureCollection<SimpleFeatureType, SimpleFeature> results = mapping.getSource().getFeatures(unrolled); assertEquals(1, getCount(results)); FeatureIterator<SimpleFeature> features = results.features(); SimpleFeature unmappedFeature = (SimpleFeature) features.next(); features.close(); assertNotNull(unmappedFeature); Object object = unmappedFeature.getProperty("station_no").getValue(); assertEquals(fid, object); }