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