public SimpleFeature next() throws NoSuchElementException { final SimpleFeature next = delegate.next(); // check all write protected attributes are null final SimpleFeatureType featureType = next.getFeatureType(); for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { String name = att.getLocalName(); if (!writableAttributes.contains(name)) { Object value = next.getAttribute(name); if (value != null) { String typeName = getSchema().getName().getLocalPart(); if (response == Response.CHALLENGE) { throw SecureCatalogImpl.unauthorizedAccess(typeName); } else { throw new UnsupportedOperationException( "Trying to write on the write protected attribute " + name); } } } } return next; } }
static SimpleFeature retype(SimpleFeature source, SimpleFeatureBuilder builder) throws IllegalAttributeException { SimpleFeatureType target = builder.getFeatureType(); for (int i = 0; i < target.getAttributeCount(); i++) { AttributeDescriptor attributeType = target.getDescriptor(i); Object value = null; if (source.getFeatureType().getDescriptor(attributeType.getName()) != null) { value = source.getAttribute(attributeType.getName()); } builder.add(value); } FeatureId id = reTypeId(source.getIdentifier(), source.getFeatureType(), target); SimpleFeature retyped = builder.buildFeature(id.getID()); retyped.getUserData().putAll(source.getUserData()); return retyped; }
public boolean isCompatible(SimpleFeature sf) { SimpleFeatureType schema = sf.getFeatureType(); return this.featureType == schema || this.featureType.equals(schema); } }
@Test public void testGetFeaturesReader() throws Exception { FeatureReader<SimpleFeatureType, SimpleFeature> fr; fr = rts.getFeatureReader(new Query(RENAMED), Transaction.AUTO_COMMIT); SimpleFeature sf = fr.next(); fr.close(); assertEquals(primitive, sf.getFeatureType()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
@Test public void testGetFeaturesReader() throws Exception { FeatureReader<SimpleFeatureType, SimpleFeature> fr; fr = rts.getFeatureReader(new Query(RENAMED), Transaction.AUTO_COMMIT); SimpleFeature sf = fr.next(); fr.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
/** * Create a new instance. * * @param featuresArg an of features. <b>All features must be of the same FeatureType</b> */ public CollectionFeatureReader(SimpleFeature[] featuresArg) { assert featuresArg.length > 0; Iterator<SimpleFeature> iterator = Arrays.asList(featuresArg).iterator(); this.features = new DelegateSimpleFeatureIterator(iterator); type = featuresArg[0].getFeatureType(); }
@Override public SimpleFeatureType getSchema() { if (schema == null) { if (isEmpty()) { return PLACEHOLDER; } else { schema = list.get(0).getFeatureType(); } } return schema; }
private String fixPropertyName(String name) { if (name.length() > 10 && delegate.getFeatureType().getDescriptor(name) == null) { String reduced = name.substring(0, 10); if (delegate.getFeatureType().getDescriptor(name) == null) { return reduced; } } return name; }
public Object evaluate(SimpleFeature feature) { return FeatureUtilities.isWrappedCoverageReader(feature.getFeatureType()) || FeatureUtilities.isWrappedCoverage(feature.getFeatureType()); }
public FeatureTypeContext getFeatureTypeContext(SimpleFeature f) { if (last != null && last.isCompatible(f)) { return last; } else { FeatureTypeContext result = featureTypeContexts.get(f.getFeatureType()); if (result == null) { result = new FeatureTypeContext(f, gml); featureTypeContexts.put(f.getFeatureType(), result); } return result; } } }
private void addFeatureInternal(SimpleFeature feature) { if (feature == null) { throw new IllegalArgumentException("Provided Feature is empty"); } SimpleFeatureType featureType = feature.getFeatureType(); try { MemoryEntry entry = entry(featureType); entry.addFeature(feature); } catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } }
/** * @return {@link Boolean#TRUE} if the <code>feature</code>'s {@link FeatureType} contains an * attribute named as the property name passed as this function argument, {@link * Boolean#FALSE} otherwise. */ public Object evaluate(SimpleFeature feature) { String propName = getPropertyName(); AttributeDescriptor attributeType = feature.getFeatureType().getDescriptor(propName); return Boolean.valueOf(attributeType != null); }
@Test public void testModify() throws Exception { final Query queryAll = new Query(RENAMED); SimpleFeatureStore store; store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED); SimpleFeature original = store.getFeatures(fidFilter).features().next(); String newAddress = ((String) original.getAttribute("ADDRESS")) + " xxx"; store.modifyFeatures( original.getFeatureType().getDescriptor("ADDRESS"), newAddress, fidFilter); SimpleFeature modified = store.getFeatures(fidFilter).features().next(); assertEquals(newAddress, modified.getAttribute("ADDRESS")); }
public WFSFeatureReader(final GetFeatureParser parser) throws IOException { this.parser = parser; this.next = parser.parse(); if (this.next != null) { FeatureType parsedType = next.getFeatureType(); if (parsedType instanceof SimpleFeatureType) { this.featureType = (SimpleFeatureType) parsedType; } else { // this is the FeatureType as parsed by the StreamingParser, we need a simple view this.featureType = EmfAppSchemaParser.toSimpleFeatureType(parsedType); } } }
public WFSFeatureReader(final GetFeatureParser parser) throws IOException { this.parser = parser; this.next = parser.parse(); if (this.next != null) { FeatureType parsedType = next.getFeatureType(); if (parsedType instanceof SimpleFeatureType) { this.featureType = (SimpleFeatureType) parsedType; } else { // this is the FeatureType as parsed by the StreamingParser, we need a simple view this.featureType = EmfAppSchemaParser.toSimpleFeatureType(parsedType); } } }
@Test public void testModify() throws Exception { final Query queryAll = new Query(RENAMED); SimpleFeatureStore store; store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED); SimpleFeature original = store.getFeatures(fidFilter).features().next(); // test a non mapped attribute String newDescription = ((String) original.getAttribute("description")) + " xxx"; store.modifyFeatures( original.getFeatureType().getDescriptor("description"), newDescription, fidFilter); SimpleFeature modified = store.getFeatures(fidFilter).features().next(); assertEquals(newDescription, modified.getAttribute("description")); // test a mapped attribute MultiPoint mpo = (MultiPoint) original.getAttribute("pointProperty"); MultiPoint mpm = mpo.getFactory().createMultiPoint(new Coordinate[] {new Coordinate(10, 12)}); store.modifyFeatures( original.getFeatureType().getDescriptor("pointProperty"), mpm, fidFilter); modified = store.getFeatures(fidFilter).features().next(); assertTrue(mpm.equalsExact((Geometry) modified.getAttribute("pointProperty"))); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(RENAMED, fs.getSchema().getName().getLocalPart()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(primitive, fs.getSchema()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(primitive, fc.getSchema()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(primitive, sf.getFeatureType()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); // check mappings occurred assertEquals("description-f001", sf.getAttribute("description")); assertTrue( new WKTReader() .read("MULTIPOINT(39.73245 2.00342)") .equalsExact((Geometry) sf.getAttribute("pointProperty"))); assertEquals(Long.valueOf(155), sf.getAttribute("intProperty")); assertNull(sf.getAttribute("newProperty")); }
@Override public void write() throws IOException { try { super.write(); String typeName = feature.getFeatureType().getTypeName(); state.addChange(typeName); } catch (IOException e) { state.getTransaction().rollback(); throw e; } }
private void writeToShapefile( SimpleFeature f, FeatureWriter<SimpleFeatureType, SimpleFeature> writer) throws IOException { SimpleFeature fw = writer.next(); // we cannot trust attribute order, shapefile changes the location and name of the geometry for (AttributeDescriptor d : fw.getFeatureType().getAttributeDescriptors()) { fw.setAttribute(d.getLocalName(), f.getAttribute(d.getLocalName())); } fw.setDefaultGeometry(f.getDefaultGeometry()); writer.write(); }