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));
}
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;
}
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;
}
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;
}
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");
}
Aggregations