Search in sources :

Example 21 with SimpleFeatureBuilder

use of org.geotools.feature.simple.SimpleFeatureBuilder in project ddf by codice.

the class CopyFilterDelegateTest method testFilterModification.

@Test
public void testFilterModification() {
    Filter filterIn = FF.equals(TEST_PROPERTY, FOO_LITERAL);
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterDelegate<Filter> delegate = new FilterModifierDelegate(filterBuilder);
    FilterAdapter fa = new GeotoolsFilterAdapterImpl();
    Filter modifiedFilter = null;
    try {
        modifiedFilter = fa.adapt(filterIn, delegate);
    } catch (UnsupportedQueryException e) {
        fail(e.getMessage());
    }
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("testFeatureType");
    b.add(TEST_PROPERTY_VALUE, String.class);
    b.add("classification", String.class);
    SimpleFeatureType featureType = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    builder.add(FOO_LITERAL_VALUE);
    builder.add("UNCLASS");
    SimpleFeature feature = builder.buildFeature("test");
    assertTrue(modifiedFilter.evaluate(feature));
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FilterAdapter(ddf.catalog.filter.FilterAdapter) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Test(org.junit.Test)

Example 22 with SimpleFeatureBuilder

use of org.geotools.feature.simple.SimpleFeatureBuilder in project ddf by codice.

the class CatalogFeatureQueryable method getFeatureForMetacard.

private SimpleFeature getFeatureForMetacard(Metacard metacard) {
    String countryCode = (String) metacard.getAttribute(Core.TITLE).getValue();
    String geometryWkt = (String) metacard.getAttribute(Core.LOCATION).getValue();
    try {
        Geometry geometry = WKT_READER_THREAD_LOCAL.get().read(geometryWkt);
        SimpleFeatureBuilder builder = FeatureBuilder.forGeometry(geometry);
        return builder.buildFeature(countryCode);
    } catch (ParseException e) {
        LOGGER.debug("Failed to parse feature", e);
    }
    return null;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ParseException(org.locationtech.jts.io.ParseException) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 23 with SimpleFeatureBuilder

use of org.geotools.feature.simple.SimpleFeatureBuilder in project ddf by codice.

the class FeatureBuilder method forGeometry.

public static SimpleFeatureBuilder forGeometry(Geometry geometry) {
    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.setName("CountryFeatureType");
    typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
    typeBuilder.add("coordinates", geometry.getClass());
    typeBuilder.add("name", String.class);
    SimpleFeatureType featureType = typeBuilder.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    builder.add(geometry);
    return builder;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 24 with SimpleFeatureBuilder

use of org.geotools.feature.simple.SimpleFeatureBuilder in project hale by halestudio.

the class ShapefileInstanceWriter method createFeatures.

/**
 * * Step 3. method to create features for the shape files and write them as
 * per the schema definition.<br>
 * Always the first entry should be "the_geom" then rest of the properties
 * can be written.
 *
 * @param instances instance to write.
 * @param progress the progress indicator.
 * @param reporter the reporter.
 * @param schemaFtMap type is used as a template to describe the file
 *            contents.
 * @return list all the features to be added to the file bundled in map for
 *         multiple schemas and multiple geometries.
 */
private Map<String, Map<String, List<SimpleFeature>>> createFeatures(InstanceCollection instances, ProgressIndicator progress, IOReporter reporter, Map<String, Map<String, SimpleFeatureType>> schemaFtMap) {
    // 3. create features
    Map<String, Map<String, List<SimpleFeature>>> schemaFeaturesMap = new HashMap<String, Map<String, List<SimpleFeature>>>();
    Map<String, Map<String, SimpleFeatureBuilder>> schemaFbMap = new HashMap<String, Map<String, SimpleFeatureBuilder>>();
    // geometries.
    for (Entry<String, Map<String, SimpleFeatureType>> schemaEntry : schemaFtMap.entrySet()) {
        for (Entry<String, SimpleFeatureType> geomEntry : schemaEntry.getValue().entrySet()) {
            schemaFbMap.computeIfAbsent(schemaEntry.getKey(), k -> new HashMap<String, SimpleFeatureBuilder>()).computeIfAbsent(geomEntry.getKey(), k1 -> new SimpleFeatureBuilder(geomEntry.getValue()));
        }
    }
    // write features to shape file schema.
    try (ResourceIterator<Instance> it = instances.iterator()) {
        while (it.hasNext() && !progress.isCanceled()) {
            Instance instance = it.next();
            TypeDefinition type = instance.getDefinition();
            String localPart = type.getName().getLocalPart();
            if (schemaFtMap.containsKey(localPart)) {
                writeGeometryInstanceData(reporter, schemaFbMap, instance, localPart);
                // add data for the rest of the properties.
                writePropertiesInstanceData(schemaFbMap, instance, type, localPart);
                // create list of simple features.
                Set<String> geometryKeys = schemaFbMap.get(localPart).keySet();
                for (String key : geometryKeys) {
                    SimpleFeature feature = schemaFbMap.get(localPart).get(key).buildFeature(null);
                    schemaFeaturesMap.computeIfAbsent(localPart, k -> new HashMap<String, List<SimpleFeature>>()).computeIfAbsent(key, k1 -> new ArrayList<>()).add(feature);
                }
            }
        // else the schema was deleted as there wasn't any geometry in
        // it.
        }
    }
    return schemaFeaturesMap;
}
Also used : SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) Arrays(java.util.Arrays) AbstractGeoInstanceWriter(eu.esdihumboldt.hale.common.instance.io.impl.AbstractGeoInstanceWriter) Transaction(org.geotools.data.Transaction) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Map(java.util.Map) InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) URI(java.net.URI) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) ProgressIndicator(eu.esdihumboldt.hale.common.core.io.ProgressIndicator) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) AugmentedValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.AugmentedValueFlag) Collection(java.util.Collection) Set(java.util.Set) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ShapefileConstants(eu.esdihumboldt.hale.io.shp.ShapefileConstants) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) List(java.util.List) HasValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag) Entry(java.util.Map.Entry) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Geometry(org.locationtech.jts.geom.Geometry) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) HashMap(java.util.HashMap) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefinitionUtil(eu.esdihumboldt.hale.common.schema.model.DefinitionUtil) ArrayList(java.util.ArrayList) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) GeometryType(eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryType) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) IOException(java.io.IOException) File(java.io.File) Paths(java.nio.file.Paths) InstanceAccessor(eu.esdihumboldt.hale.common.instance.groovy.InstanceAccessor) ResourceIterator(eu.esdihumboldt.hale.common.instance.model.ResourceIterator) DefaultTransaction(org.geotools.data.DefaultTransaction) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) FileSystems(java.nio.file.FileSystems) HashMap(java.util.HashMap) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) SimpleFeature(org.opengis.feature.simple.SimpleFeature) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 25 with SimpleFeatureBuilder

use of org.geotools.feature.simple.SimpleFeatureBuilder 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

SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)56 SimpleFeature (org.opengis.feature.simple.SimpleFeature)34 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)25 Optional (com.google.common.base.Optional)17 ArrayList (java.util.ArrayList)15 RevFeature (org.locationtech.geogig.api.RevFeature)14 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)13 Test (org.junit.Test)11 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)10 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)10 File (java.io.File)9 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)9 Coordinate (com.vividsolutions.jts.geom.Coordinate)8 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)8 Point (com.vividsolutions.jts.geom.Point)8 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)8 Geometry (com.vividsolutions.jts.geom.Geometry)7 List (java.util.List)7