Search in sources :

Example 1 with ForwardingFeatureCollection

use of org.locationtech.geogig.api.data.ForwardingFeatureCollection in project GeoGig by boundlessgeo.

the class ImportOp method getFeatureSource.

@SuppressWarnings({ "rawtypes", "unchecked" })
private FeatureSource getFeatureSource(String typeName) {
    FeatureSource featureSource;
    try {
        featureSource = dataStore.getFeatureSource(typeName);
    } catch (Exception e) {
        throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_FEATURES);
    }
    return new ForwardingFeatureSource(featureSource) {

        @Override
        public FeatureCollection getFeatures(Query query) throws IOException {
            final FeatureCollection features = super.getFeatures(query);
            return new ForwardingFeatureCollection(features) {

                @Override
                public FeatureIterator features() {
                    final FeatureType featureType = getSchema();
                    final String fidPrefix = featureType.getName().getLocalPart() + ".";
                    FeatureIterator iterator = delegate.features();
                    return new FidAndFtReplacerIterator(iterator, fidAttribute, fidPrefix, (SimpleFeatureType) featureType);
                }
            };
        }
    };
}
Also used : FeatureIterator(org.geotools.feature.FeatureIterator) ForwardingFeatureIterator(org.locationtech.geogig.api.data.ForwardingFeatureIterator) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) JDBCFeatureSource(org.geotools.jdbc.JDBCFeatureSource) FeatureSource(org.geotools.data.FeatureSource) ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) Query(org.geotools.data.Query) ForwardingFeatureCollection(org.locationtech.geogig.api.data.ForwardingFeatureCollection) ForwardingFeatureCollection(org.locationtech.geogig.api.data.ForwardingFeatureCollection) FeatureCollection(org.geotools.feature.FeatureCollection) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 2 with ForwardingFeatureCollection

use of org.locationtech.geogig.api.data.ForwardingFeatureCollection in project GeoGig by boundlessgeo.

the class FeatureTypeAdapterFeatureSource method getFeatures.

@Override
public FeatureCollection<T, F> getFeatures(Query query) throws IOException {
    final FeatureCollection<T, F> features = super.getFeatures(query);
    return new ForwardingFeatureCollection<T, F>(features) {

        @Override
        public FeatureIterator<F> features() {
            if (delegate.getSchema().getDescriptors().size() != featureType.getDescriptors().size()) {
                throw new GeoToolsOpException(GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE);
            }
            GeometryDescriptor geomDescriptorOrg = delegate.getSchema().getGeometryDescriptor();
            GeometryDescriptor geomDescriptorDest = featureType.getGeometryDescriptor();
            if (!geomDescriptorOrg.getType().getBinding().equals(geomDescriptorDest.getType().getBinding()) || !geomDescriptorOrg.getType().getCoordinateReferenceSystem().equals(geomDescriptorDest.getType().getCoordinateReferenceSystem())) {
                throw new GeoToolsOpException(GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE);
            }
            FeatureIterator<F> iterator = delegate.features();
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder((SimpleFeatureType) featureType);
            return new FeatureTypeConverterIterator<F>(iterator, (SimpleFeatureBuilder) builder);
        }

        @Override
        public T getSchema() {
            return featureType;
        }
    };
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) ForwardingFeatureCollection(org.locationtech.geogig.api.data.ForwardingFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

ForwardingFeatureCollection (org.locationtech.geogig.api.data.ForwardingFeatureCollection)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 FeatureSource (org.geotools.data.FeatureSource)1 Query (org.geotools.data.Query)1 FeatureCollection (org.geotools.feature.FeatureCollection)1 FeatureIterator (org.geotools.feature.FeatureIterator)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 JDBCFeatureSource (org.geotools.jdbc.JDBCFeatureSource)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 ForwardingFeatureIterator (org.locationtech.geogig.api.data.ForwardingFeatureIterator)1 ForwardingFeatureSource (org.locationtech.geogig.api.data.ForwardingFeatureSource)1 ResolveFeatureType (org.locationtech.geogig.api.plumbing.ResolveFeatureType)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 FeatureType (org.opengis.feature.type.FeatureType)1 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)1