use of org.geotools.data.FeatureSource in project GeoGig by boundlessgeo.
the class WorkingTreeTest method testInsertPagingFeatureSource.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInsertPagingFeatureSource() throws Exception {
assertEquals(2, super.getGeogig().getPlatform().availableProcessors());
final List<SimpleFeature> features = ImmutableList.of((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3);
MemoryDataStore store = new MemoryDataStore();
store.addFeatures(features);
final QueryCapabilities caps = mock(QueryCapabilities.class);
when(caps.isOffsetSupported()).thenReturn(true);
FeatureSource source = new ForwardingFeatureSource(store.getFeatureSource(pointsName)) {
@Override
public QueryCapabilities getQueryCapabilities() {
return caps;
}
@Override
public FeatureCollection getFeatures(Query query) throws IOException {
Integer startIndex = query.getStartIndex();
if (startIndex == null) {
return super.getFeatures();
}
int toIndex = (int) Math.min((long) startIndex + query.getMaxFeatures(), features.size());
List<SimpleFeature> result = features.subList(startIndex, toIndex);
return DataUtilities.collection(result);
}
};
assertTrue(source.getQueryCapabilities().isOffsetSupported());
String treePath = "target_typename";
workTree.insert(treePath, source, Query.ALL, LISTENER);
assertEquals(3, workTree.countUnstaged(treePath).featureCount());
}
use of org.geotools.data.FeatureSource 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.geotools.data.FeatureSource in project sldeditor by robward-scisys.
the class DataSourceImpl method getUserLayerFeatureSource.
/*
* (non-Javadoc)
*
* @see com.sldeditor.datasource.DataSourceInterface#getUserLayerFeatureSource()
*/
@Override
public // CHECKSTYLE:OFF
Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> getUserLayerFeatureSource() {
// CHECKSTYLE:ON
Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> map = new HashMap<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>>();
for (DataSourceInfo dsInfo : userLayerDataSourceInfo) {
FeatureSource<SimpleFeatureType, SimpleFeature> features = dsInfo.getFeatures();
UserLayer userLayer = dsInfo.getUserLayer();
map.put(userLayer, features);
}
return map;
}
use of org.geotools.data.FeatureSource in project polymap4-core by Polymap4.
the class RDataStore method updateSchema.
@Override
public void updateSchema(Name name, final FeatureType newSchema) throws IOException {
assert name != null && newSchema != null;
final Updater tx = store.prepareUpdate();
try {
// check modified property names
boolean namesModified = false;
for (PropertyDescriptor desc : newSchema.getDescriptors()) {
// set by FeatureTypeEditor/AttributeCellModifier
String origName = (String) desc.getUserData().get(ORIG_NAME_KEY);
if (origName != null) {
namesModified = true;
}
}
// find deleted properties
// XXX check complex schemas
FeatureType schema = getSchema(name);
final List<PropertyDescriptor> deleted = new ArrayList();
for (PropertyDescriptor desc : schema.getDescriptors()) {
if (newSchema.getDescriptor(desc.getName()) == null) {
deleted.add(desc);
}
}
// schema name changed or prop deleted? -> update features
final String newName = newSchema.getName().getLocalPart();
if (!name.getLocalPart().equals(newSchema.getName().getLocalPart()) || !deleted.isEmpty() || namesModified) {
FeatureSource fs = getFeatureSource(name);
fs.getFeatures().accepts(new FeatureVisitor() {
public void visit(Feature feature) {
try {
// typeName
((RFeature) feature).state.put(RFeature.TYPE_KEY, newName);
// List<Name> origModifiedNames = new ArrayList();
for (PropertyDescriptor desc : newSchema.getDescriptors()) {
// set by FeatureTypeEditor/AttributeCellModifier
String origName = (String) desc.getUserData().get(ORIG_NAME_KEY);
if (origName != null) {
RAttribute prop = (RAttribute) feature.getProperty(origName);
if (prop != null) {
if (prop.getValue() != null) {
((RFeature) feature).state.put(desc.getName().getLocalPart(), prop.getValue());
}
((RFeature) feature).state.remove(prop.key.toString());
}
}
}
// deleted attributes
for (PropertyDescriptor desc : deleted) {
// XXX check complex schemas
RProperty prop = (RProperty) feature.getProperty(desc.getName());
((RFeature) feature).state.remove(prop.key.toString());
}
tx.store(((RFeature) feature).state);
} catch (Exception e) {
// Designing a visitor interface without Exception is not a good idea!
throw new RuntimeException("", e);
}
}
}, null);
}
// update schema record
ResultSet rs = store.find(new SimpleQuery().setMaxResults(1).eq("type", "FeatureType").eq("name", name.getLocalPart()));
IRecordState record = rs.get(0);
String schemaContent = schemaCoder.encode(newSchema);
record.put("content", schemaContent);
record.put("name", newName);
tx.store(record);
log.debug("Current schema: " + schemaCoder.encode(schema));
log.debug("Updated schema: " + schemaContent);
tx.apply();
} catch (Throwable e) {
log.debug("", e);
tx.discard();
throw new RuntimeException(e);
}
}
use of org.geotools.data.FeatureSource in project OpenTripPlanner by opentripplanner.
the class ShapefileBoundaryResolver method initialize.
public void initialize() throws IOException {
if (shapefile == null) {
throw new IllegalStateException("shapefile path is not set");
}
// get feature results
ShapefileDataStore store = new ShapefileDataStore(new File(shapefile).toURI().toURL());
String name = store.getTypeNames()[0];
FeatureSource source = store.getFeatureSource(name);
collection = source.getFeatures();
}
Aggregations