Search in sources :

Example 6 with FeatureType

use of org.opengis.feature.type.FeatureType 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 7 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class DescribeFeatureType method _call.

/**
     * Retrieves the set of property descriptors for the given feature type.
     * 
     * @return a sorted set of all the property descriptors of the feature type.
     */
@Override
protected ImmutableSet<PropertyDescriptor> _call() {
    Preconditions.checkState(featureType != null, "FeatureType has not been set.");
    FeatureType type = featureType.type();
    ImmutableSet.Builder<PropertyDescriptor> propertySetBuilder = new ImmutableSet.Builder<PropertyDescriptor>();
    propertySetBuilder.addAll(type.getDescriptors());
    return propertySetBuilder.build();
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) FeatureType(org.opengis.feature.type.FeatureType) ImmutableSet(com.google.common.collect.ImmutableSet) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor)

Example 8 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class ImportOp method _call.

/**
     * Executes the import operation using the parameters that have been specified. Features will be
     * added to the working tree, and a new working tree will be constructed. Either {@code all} or
     * {@code table}, but not both, must be set prior to the import process.
     * 
     * @return RevTree the new working tree
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected RevTree _call() {
    // check preconditions and get the actual list of type names to import
    final String[] typeNames = checkPreconditions();
    for (int i = 0; i < typeNames.length; i++) {
        try {
            typeNames[i] = URLDecoder.decode(typeNames[i], Charsets.UTF_8.displayName());
        } catch (UnsupportedEncodingException e) {
        // shouldn't reach here.
        }
    }
    ProgressListener progressListener = getProgressListener();
    progressListener.started();
    // use a local variable not to alter the command's state
    boolean overwrite = this.overwrite;
    if (alter) {
        overwrite = false;
    }
    final WorkingTree workTree = workingTree();
    RevFeatureType destPathFeatureType = null;
    final boolean destPathProvided = destPath != null;
    if (destPathProvided) {
        destPathFeatureType = this.command(ResolveFeatureType.class).setRefSpec(destPath).call().orNull();
        // only the last one will be imported.
        if (overwrite) {
            try {
                workTree.delete(destPath);
            } catch (Exception e) {
                throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
            }
            overwrite = false;
        }
    }
    int tableCount = 0;
    for (String typeName : typeNames) {
        {
            tableCount++;
            String tableName = String.format("%-16s", typeName);
            if (typeName.length() > 16) {
                tableName = tableName.substring(0, 13) + "...";
            }
            progressListener.setDescription("Importing " + tableName + " (" + tableCount + "/" + typeNames.length + ")... ");
        }
        FeatureSource featureSource = getFeatureSource(typeName);
        SimpleFeatureType featureType = (SimpleFeatureType) featureSource.getSchema();
        final String fidPrefix = featureType.getTypeName() + ".";
        String path;
        if (destPath == null) {
            path = featureType.getTypeName();
        } else {
            NodeRef.checkValidPath(destPath);
            path = destPath;
            featureType = forceFeatureTypeName(featureType, path);
        }
        featureType = overrideGeometryName(featureType);
        featureSource = new ForceTypeAndFidFeatureSource<FeatureType, Feature>(featureSource, featureType, fidPrefix);
        boolean hasPrimaryKey = hasPrimaryKey(typeName);
        boolean forbidSorting = !usePaging || !hasPrimaryKey;
        ((ForceTypeAndFidFeatureSource) featureSource).setForbidSorting(forbidSorting);
        if (destPathFeatureType != null && adaptToDefaultFeatureType && !alter) {
            featureSource = new FeatureTypeAdapterFeatureSource<FeatureType, Feature>(featureSource, destPathFeatureType.type());
        }
        ProgressListener taskProgress = subProgress(100.f / typeNames.length);
        if (overwrite) {
            try {
                workTree.delete(path);
                workTree.createTypeTree(path, featureType);
            } catch (Exception e) {
                throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
            }
        }
        if (alter) {
            // first we modify the feature type and the existing features, if needed
            workTree.updateTypeTree(path, featureType);
            Iterator<Feature> transformedIterator = transformFeatures(featureType, path);
            try {
                final Integer collectionSize = collectionSize(featureSource);
                workTree.insert(path, transformedIterator, taskProgress, null, collectionSize);
            } catch (Exception e) {
                throw new GeoToolsOpException(StatusCode.UNABLE_TO_INSERT);
            }
        }
        try {
            insert(workTree, path, featureSource, taskProgress);
        } catch (GeoToolsOpException e) {
            throw e;
        } catch (Exception e) {
            throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
        }
    }
    progressListener.setProgress(100.f);
    progressListener.complete();
    return workTree.getTree();
}
Also used : 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) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) DecoratingFeature(org.geotools.feature.DecoratingFeature) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) ProgressListener(org.locationtech.geogig.api.ProgressListener) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 9 with FeatureType

use of org.opengis.feature.type.FeatureType in project ddf by codice.

the class TestPubSubOgcFilter method convertMetacardToFeature.

private Feature convertMetacardToFeature(MetacardImpl metacard) {
    // other available FeatureType's ComplexFeatureTypeImpl (link features),
    // FeatureTypeImpl, NonFeatureTypeProxy, SimpleFeatureTypeImpl,
    // UniqueNameFeatureTypeImpl
    final FeatureType pubSubFeature = generateMetacardFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) pubSubFeature);
    featureBuilder.set(Metacard.TITLE, "Muppet Metacard");
    featureBuilder.set(Metacard.CONTENT_TYPE, "Talking Green Frog");
    featureBuilder.set(Metacard.CREATED, new Date());
    featureBuilder.set(Metacard.MODIFIED, new Date());
    featureBuilder.set(Metacard.EXPIRATION, new Date());
    featureBuilder.set(Metacard.EFFECTIVE, new Date());
    featureBuilder.set(Metacard.METADATA, null);
    com.vividsolutions.jts.geom.GeometryFactory geoFactory = JTSFactoryFinder.getGeometryFactory(null);
    com.vividsolutions.jts.geom.Point point = geoFactory.createPoint(new Coordinate(-112, 28));
    featureBuilder.set(Metacard.GEOGRAPHY, point);
    return featureBuilder.buildFeature("KTF1");
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) Date(java.util.Date) Point(com.vividsolutions.jts.geom.Point) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

FeatureType (org.opengis.feature.type.FeatureType)9 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)8 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 FeatureSource (org.geotools.data.FeatureSource)2 JDBCFeatureSource (org.geotools.jdbc.JDBCFeatureSource)2 Test (org.junit.Test)2 Node (org.locationtech.geogig.api.Node)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 ForwardingFeatureSource (org.locationtech.geogig.api.data.ForwardingFeatureSource)2 ResolveFeatureType (org.locationtech.geogig.api.plumbing.ResolveFeatureType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Point (com.vividsolutions.jts.geom.Point)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1 Query (org.geotools.data.Query)1 DecoratingFeature (org.geotools.feature.DecoratingFeature)1