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