public SimpleFeatureType getFeatureType() { return getSchema(); }
protected boolean add(SimpleFeature feature, boolean fire) { // This cast is necessary to keep with the contract of Set! if (feature == null) return false; // cannot add null! final String ID = feature.getID(); if (ID == null) return false; // ID is required! if (contents.containsKey(ID)) return false; // feature all ready present if (this.schema == null) { this.schema = feature.getFeatureType(); } SimpleFeatureType childType = (SimpleFeatureType) getSchema(); if (!feature.getFeatureType().equals(childType)) { LOGGER.warning("Feature Collection contains a heterogeneous" + " mix of features"); } // Check inheritance with FeatureType here? contents.put(ID, feature); return true; }
public SimpleFeatureCollection collection() throws IOException { DefaultFeatureCollection copy = new DefaultFeatureCollection(null, getSchema()); List<SimpleFeature> list = new ArrayList<SimpleFeature>(contents.size()); SimpleFeatureIterator iterator = features(); try { while (iterator.hasNext()) { SimpleFeature feature = iterator.next(); SimpleFeature duplicate; try { duplicate = SimpleFeatureBuilder.copy(feature); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to copy " + feature.getID(), e); } list.add(duplicate); } } finally { iterator.close(); } copy.addAll(list); return copy; }
/** * Reads a feature collection from GeoJSON. * * <p>Warning that this method will load the entire feature collection into memory. For large * feature collections {@link #streamFeatureCollection(Object)} should be used. * * @param input The input. See {@link GeoJSONUtil#toReader(Object)} for details. * @return The feature collection. * @throws IOException In the event of a parsing error or if the input json is invalid. */ public FeatureCollection readFeatureCollection(Object input) throws IOException { DefaultFeatureCollection features = new DefaultFeatureCollection(null, null); FeatureCollectionIterator it = (FeatureCollectionIterator) streamFeatureCollection(input); while (it.hasNext()) { features.add(it.next()); } // check for the case of a crs specified post features in the json if (features.getSchema() != null && features.getSchema().getCoordinateReferenceSystem() == null && it.getHandler().getCRS() != null) { try { return new ForceCoordinateSystemFeatureResults(features, it.getHandler().getCRS()); } catch (SchemaException e) { throw (IOException) new IOException().initCause(e); } } return features; }
public SimpleFeatureType getFeatureType() { return getSchema(); } public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException {
public FeatureType getFeatureType() { return getSchema(); } public Feature next() throws IOException, IllegalAttributeException, NoSuchElementException {
/** * Test method for {@link * org.geotools.data.collection.SpatialIndexFeatureCollection#subCollection(org.opengis.filter.Filter)}. */ @Test public void testSimpleSubCollection() { // delegate has 5 points running diagonally from -140,45 -> -136,49 ReferencedEnvelope bbox = new ReferencedEnvelope(-145, -139.5, 44, 47, DefaultGeographicCRS.WGS84); Filter filter = ff.bbox( ff.property(delegate.getSchema().getGeometryDescriptor().getLocalName()), bbox); SpatialIndexFeatureCollection collection = null; try { collection = new SpatialIndexFeatureCollection(delegate); } catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } SimpleFeatureCollection sub = collection.subCollection(filter); assertEquals(1, sub.size()); }
DefaultFeatureCollection result = new DefaultFeatureCollection(null, targetSchema); SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) result.getSchema()); FeatureIterator fi = features.features(); try {
public void testSetFeatures() throws IOException { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema()); DefaultFeatureCollection collection = new DefaultFeatureCollection(null, featureStore.getSchema()); for (int i = 3; i < 6; i++) { b.set(aname("intProperty"), Integer.valueOf(i)); b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i))); collection.add(b.buildFeature(null)); } try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = new CollectionFeatureReader( (SimpleFeatureCollection) collection, collection.getSchema())) { featureStore.setFeatures(reader); } SimpleFeatureCollection features = featureStore.getFeatures(); assertEquals(3, features.size()); try (SimpleFeatureIterator iterator = features.features()) { HashSet<Integer> numbers = new HashSet<Integer>(); numbers.add(Integer.valueOf(3)); numbers.add(Integer.valueOf(4)); numbers.add(Integer.valueOf(5)); for (int i = 3; iterator.hasNext(); i++) { SimpleFeature feature = (SimpleFeature) iterator.next(); assertTrue( numbers.contains( ((Number) feature.getAttribute(aname("intProperty"))).intValue())); numbers.remove(feature.getAttribute(aname("intProperty"))); } } }
public void testSchema() throws Exception { // see http://jira.codehaus.org/browse/GEOT-1616 SimpleFeatureType original = delegate.getSchema(); String newName = original.getTypeName() + "xxx"; SimpleFeatureTypeBuilder stb = new SimpleFeatureTypeBuilder(); stb.init(original); stb.setName(newName); SimpleFeatureType renamed = stb.buildFeatureType(); ReTypingFeatureCollection rtc = new ReTypingFeatureCollection(delegate, renamed); assertEquals(renamed, rtc.getSchema()); }
protected boolean add(SimpleFeature feature, boolean fire) { // This cast is neccessary to keep with the contract of Set! if( feature == null ) return false; // cannot add null! final String ID = feature.getID(); if( ID == null ) return false; // ID is required! if( contents.containsKey( ID ) ) return false; // feature all ready present if( this.schema == null ) { this.schema = feature.getFeatureType(); } SimpleFeatureType childType = (SimpleFeatureType) getSchema(); // if ( childType==null ){ // //this.childType= // }else{ if( !feature.getFeatureType().equals(childType) ) LOGGER.warning("Feature Collection contains a heterogeneous" + " mix of features"); // } //TODO check inheritance with FeatureType here!!! contents.put( ID, feature ); if(fire) { fireChange(feature, CollectionEvent.FEATURES_ADDED); } return true; }
public void testFilter() throws Exception { ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(delegate, target); ReferencedEnvelope bounds = delegate.getBounds(); ReferencedEnvelope rbounds = bounds.transform(target, true); // check the bounds filtering works the same way in the standard and reprojected case BBOX filter = ff.bbox( "", bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY(), CRS.toSRS(delegate.getSchema().getCoordinateReferenceSystem())); BBOX rfilter = ff.bbox( "", rbounds.getMinX(), rbounds.getMinY(), rbounds.getMaxX(), rbounds.getMaxY(), CRS.toSRS(target)); assertEquals(delegate.subCollection(filter).size(), rfc.subCollection(rfilter).size()); }
public SimpleFeatureCollection collection() throws IOException { SimpleFeatureCollection copy = new DefaultFeatureCollection( null, getSchema() ); List<SimpleFeature> list = new ArrayList<SimpleFeature>( contents.size() ); SimpleFeatureIterator iterator = features(); try { while( iterator.hasNext() ){ SimpleFeature feature = iterator.next(); SimpleFeature duplicate; try { duplicate = SimpleFeatureBuilder.copy(feature); } catch (IllegalAttributeException e) { throw new DataSourceException( "Unable to copy "+feature.getID(), e ); } list.add( duplicate ); } } finally { iterator.close(); } copy.addAll( list ); return copy; }
@Override public VectorDataNode readVectorDataNode(File file, Product product, ProgressMonitor pm) throws IOException { DefaultFeatureCollection featureCollection = FeatureUtils.loadShapefileForProduct(file, product, crsProvider, pm); Style[] styles = SLDUtils.loadSLD(file); ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup(); String name = VectorDataNodeImporter.findUniqueVectorDataNodeName(featureCollection.getSchema().getName().getLocalPart(), vectorDataGroup); if (styles.length > 0) { SimpleFeatureType featureType = SLDUtils.createStyledFeatureType(featureCollection.getSchema()); VectorDataNode vectorDataNode = new VectorDataNode(name, featureType); DefaultFeatureCollection styledCollection = vectorDataNode.getFeatureCollection(); String defaultCSS = vectorDataNode.getDefaultStyleCss(); SLDUtils.applyStyle(styles[0], defaultCSS, featureCollection, styledCollection); return vectorDataNode; } else { return new VectorDataNode(name, featureCollection); } } }
private VectorDataNode readIn(File file, Product product) throws IOException, FactoryException, TransformException { DefaultFeatureCollection featureCollection = FeatureUtils.loadShapefileForProduct(file, product, new DummyFeatureCrsProvider(), ProgressMonitor.NULL); ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup(); String name = VectorDataNodeImporter.findUniqueVectorDataNodeName(featureCollection.getSchema().getName().getLocalPart(), vectorDataGroup); return new VectorDataNode(name, featureCollection); }