Search in sources :

Example 36 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getCountInternal.

@Override
protected int getCountInternal(Query query) throws IOException {
    final Filter filter = (Filter) query.getFilter().accept(new SimplifyingFilterVisitor(), null);
    if (Filter.EXCLUDE.equals(filter)) {
        return 0;
    }
    final Integer offset = query.getStartIndex();
    final Integer maxFeatures = query.getMaxFeatures() == Integer.MAX_VALUE ? null : query.getMaxFeatures();
    int size;
    if (Filter.INCLUDE.equals(filter) && oldRoot == null && ChangeType.ADDED.equals(changeType())) {
        RevTree tree = getTypeTree();
        size = (int) tree.size();
        if (offset != null) {
            size = size - offset.intValue();
        }
        if (maxFeatures != null) {
            size = Math.min(size, maxFeatures.intValue());
        }
        return size;
    }
    FeatureReader<SimpleFeatureType, SimpleFeature> features;
    if (isNaturalOrder(query.getSortBy())) {
        ScreenMap screenMap = (ScreenMap) query.getHints().get(Hints.SCREENMAP);
        features = getNativeReader(Query.NO_NAMES, filter, offset, maxFeatures, screenMap);
    } else {
        features = getReader(query);
    }
    int count = 0;
    try {
        while (features.hasNext()) {
            features.next();
            count++;
        }
    } finally {
        features.close();
    }
    return count;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) ScreenMap(org.geotools.renderer.ScreenMap) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) RevTree(org.locationtech.geogig.api.RevTree) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 37 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method buildFeatureType.

@Override
protected SimpleFeatureType buildFeatureType() throws IOException {
    SimpleFeatureType featureType = getNativeType();
    final Name name = featureType.getName();
    final Name assignedName = getEntry().getName();
    if (assignedName.getNamespaceURI() != null && !assignedName.equals(name)) {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.init(featureType);
        builder.setName(assignedName);
        featureType = builder.buildFeatureType();
    }
    return featureType;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Name(org.opengis.feature.type.Name)

Example 38 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getNativeReader.

/**
     * @param propertyNames properties to retrieve, empty array for no properties at all
     *        {@link Query#NO_NAMES}, {@code null} means all properties {@link Query#ALL_NAMES}
     */
private FeatureReader<SimpleFeatureType, SimpleFeature> getNativeReader(@Nullable String[] propertyNames, Filter filter, @Nullable Integer offset, @Nullable Integer maxFeatures, @Nullable final ScreenMap screenMap) {
    if (screenMap == null) {
        LOGGER.trace("GeoGigFeatureSource.getNativeReader: no screenMap provided");
    } else {
        LOGGER.trace("GeoGigFeatureSource.getNativeReader: using screenMap filter");
    }
    LOGGER.trace("Query filter: {}", filter);
    filter = (Filter) filter.accept(new SimplifyingFilterVisitor(), null);
    LOGGER.trace("Simplified filter: {}", filter);
    GeogigFeatureReader<SimpleFeatureType, SimpleFeature> nativeReader;
    final String rootRef = getRootRef();
    final String featureTypeTreePath = getTypeTreePath();
    final SimpleFeatureType fullType = getSchema();
    boolean ignoreAttributes = false;
    if (propertyNames != null && propertyNames.length == 0) {
        String[] inProcessFilteringAttributes = Filters.attributeNames(filter, fullType);
        ignoreAttributes = inProcessFilteringAttributes.length == 0;
    }
    final String compareRootRef = oldRoot();
    final GeoGigDataStore.ChangeType changeType = changeType();
    final Context context = getCommandLocator();
    nativeReader = new GeogigFeatureReader<SimpleFeatureType, SimpleFeature>(context, fullType, filter, featureTypeTreePath, rootRef, compareRootRef, changeType, offset, maxFeatures, screenMap, ignoreAttributes);
    return nativeReader;
}
Also used : Context(org.locationtech.geogig.api.Context) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ChangeType(org.locationtech.geogig.geotools.data.GeoGigDataStore.ChangeType) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 39 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType 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 40 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeogigFeatureStore method getWriterInternal.

@Override
protected FeatureWriter<SimpleFeatureType, SimpleFeature> getWriterInternal(Query query, final int flags) throws IOException {
    Preconditions.checkArgument(flags != 0, "no write flags set");
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    FeatureReader<SimpleFeatureType, SimpleFeature> features;
    if ((flags | WRITER_UPDATE) == WRITER_UPDATE) {
        features = delegate.getReader(query);
    } else {
        features = new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(getSchema());
    }
    String path = delegate.getTypeTreePath();
    WorkingTree wtree = getFeatureSource().getWorkingTree();
    GeoGigFeatureWriter writer;
    if ((flags | WRITER_ADD) == WRITER_ADD) {
        writer = GeoGigFeatureWriter.createAppendable(features, path, wtree);
    } else {
        writer = GeoGigFeatureWriter.create(features, path, wtree);
    }
    return writer;
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)149 SimpleFeature (org.opengis.feature.simple.SimpleFeature)75 Test (org.junit.Test)47 IOException (java.io.IOException)46 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)29 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)24 DataStore (org.geotools.data.DataStore)23 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)23 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)21 HashMap (java.util.HashMap)20 ObjectId (org.locationtech.geogig.api.ObjectId)20 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)19 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)18 Feature (org.opengis.feature.Feature)18 ArrayList (java.util.ArrayList)16 File (java.io.File)15 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)15 NodeRef (org.locationtech.geogig.api.NodeRef)15 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)15 DefaultTransaction (org.geotools.data.DefaultTransaction)14