Search in sources :

Example 76 with SimpleFeatureType

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

the class ExportDiffOp method addFidAttribute.

private static SimpleFeatureType addFidAttribute(RevFeatureType revFType) {
    SimpleFeatureType featureType = (SimpleFeatureType) revFType.type();
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.add("geogig_fid", String.class);
    for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
        builder.add(descriptor);
    }
    builder.setName(featureType.getName());
    builder.setCRS(featureType.getCoordinateReferenceSystem());
    featureType = builder.buildFeatureType();
    return featureType;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 77 with SimpleFeatureType

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

the class ExportDiffOp method getFeatures.

private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old, final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) {
    final SimpleFeatureType featureType = addFidAttribute(database.getFeatureType(metadataId));
    final RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
    final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
    Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() {

        @Override
        @Nullable
        public SimpleFeature apply(final DiffEntry input) {
            NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject();
            if (nodeRef == null) {
                return null;
            }
            final RevFeature revFeature = database.getFeature(nodeRef.objectId());
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < values.size(); i++) {
                String name = featureType.getDescriptor(i + 1).getLocalName();
                Object value = values.get(i).orNull();
                featureBuilder.set(name, value);
            }
            featureBuilder.set("geogig_fid", nodeRef.name());
            Feature feature = featureBuilder.buildFeature(nodeRef.name());
            feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
            feature.getUserData().put(RevFeature.class, revFeature);
            feature.getUserData().put(RevFeatureType.class, revFeatureType);
            if (feature instanceof SimpleFeature) {
                return (SimpleFeature) feature;
            }
            return null;
        }
    };
    Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature);
    UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());
    return filterNulls;
}
Also used : Optional(com.google.common.base.Optional) RevFeature(org.locationtech.geogig.api.RevFeature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Function(com.google.common.base.Function) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 78 with SimpleFeatureType

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

Example 79 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project ddf by codice.

the class TestPubSubOgcFilter method generateSampleFeature.

private SimpleFeature generateSampleFeature() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("PubSubFeature");
    // add properties
    b.add("name", String.class);
    b.add("classification", Integer.class);
    b.add("height", Double.class);
    com.vividsolutions.jts.geom.GeometryFactory geoFactory = JTSFactoryFinder.getGeometryFactory(null);
    // add geo
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("geo", Point.class);
    final SimpleFeatureType pubSubFeature = b.buildFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(pubSubFeature);
    featureBuilder.set("name", "FirstFeature");
    featureBuilder.set("classification", 10);
    featureBuilder.set("height", 5.8);
    com.vividsolutions.jts.geom.Point point = geoFactory.createPoint(new Coordinate(-112, 28));
    featureBuilder.set("geo", point);
    SimpleFeature feature = featureBuilder.buildFeature("f1");
    // it looks like if I add an attribute into the feature that is of geometry type, it
    // automatically
    // becomes the default geo property. If no geo is specified, getDefaultGeometryProperty
    // returns null
    GeometryAttribute defaultGeo = feature.getDefaultGeometryProperty();
    LOGGER.debug("geo name: {}", defaultGeo.getName());
    LOGGER.debug("geo: {}", defaultGeo);
    return feature;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryAttribute(org.opengis.feature.GeometryAttribute) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 80 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project dhis2-core by dhis2.

the class MapUtils method createFeatureLayerFromMapObject.

/**
     * Creates a feature layer based on a map object.
     */
public static Layer createFeatureLayerFromMapObject(InternalMapObject mapObject) {
    Style style = mapObject.getStyle();
    SimpleFeatureType featureType = mapObject.getFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    featureBuilder.add(mapObject.getGeometry());
    SimpleFeature feature = featureBuilder.buildFeature(null);
    featureCollection.add(feature);
    return new FeatureLayer(featureCollection, style);
}
Also used : FeatureLayer(org.geotools.map.FeatureLayer) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Style(org.geotools.styling.Style) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)80 SimpleFeature (org.opengis.feature.simple.SimpleFeature)35 Test (org.junit.Test)22 IOException (java.io.IOException)20 ObjectId (org.locationtech.geogig.api.ObjectId)20 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)18 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)17 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)15 NodeRef (org.locationtech.geogig.api.NodeRef)15 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)15 Feature (org.opengis.feature.Feature)14 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)12 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)12 Optional (com.google.common.base.Optional)10 RevTree (org.locationtech.geogig.api.RevTree)10 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)10 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)10 DefaultTransaction (org.geotools.data.DefaultTransaction)9 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)9 Function (com.google.common.base.Function)8