use of org.geotools.data.simple.SimpleFeatureCollection in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromWorkingTree.
@Test
public void testExportFromWorkingTree() throws Exception {
Feature[] points = new Feature[] { points1, points2, points3 };
for (Feature feature : points) {
insert(feature);
}
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), points.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, points));
}
use of org.geotools.data.simple.SimpleFeatureCollection in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId.
@Test
public void testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId() throws Exception {
Feature[] points = new Feature[] { points2, points1B, points3 };
for (Feature feature : points) {
insert(feature);
}
Feature[] expectedPoints = new Feature[] { points1B };
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).setFilterFeatureTypeId(RevFeatureTypeImpl.build(modifiedPointsType).getId()).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(expectedPoints.length, featureCollection.size());
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, expectedPoints));
}
use of org.geotools.data.simple.SimpleFeatureCollection in project spatial-portal by AtlasOfLivingAustralia.
the class AreaUploadShapefileWizardController method executeShapeImageRenderer.
private void executeShapeImageRenderer(Filter filter) {
try {
LOGGER.debug("Generating image");
SimpleFeatureCollection features1;
if (filter == null) {
features1 = source.getFeatures();
} else {
features1 = source.getFeatures(filter);
}
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
org.geotools.styling.Style style = SLD.createSimpleStyle(source.getSchema());
Layer layer = new FeatureLayer(features1, style);
map.addLayer(layer);
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(map);
int imageWidth = 800;
int imageHeight = 300;
Rectangle imageBounds;
ReferencedEnvelope mapBounds;
mapBounds = map.getMaxBounds();
double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
if (heightToWidth * imageWidth > imageHeight) {
imageBounds = new Rectangle(0, 0, (int) Math.round(imageHeight / heightToWidth), imageHeight);
} else {
imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth));
}
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB);
Graphics2D gr = image.createGraphics();
gr.setPaint(Color.WHITE);
gr.fill(imageBounds);
renderer.paint(gr, imageBounds, mapBounds);
img.setContent(image);
} catch (Exception e) {
LOGGER.debug("Unable to generate image for selected shapefile", e);
}
}
use of org.geotools.data.simple.SimpleFeatureCollection in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testDiffFeatures.
private void testDiffFeatures(ObjectId oldRoot, ObjectId newRoot, int expectedAdded, int expectedRemoved, int expectedChanged) throws IOException {
dataStore.setHead(newRoot.toString());
List<String> fids;
SimpleFeatureCollection features;
ChangeType changeType = ChangeType.ADDED;
features = dataStore.getDiffFeatureSource(pointsName, oldRoot.toString(), changeType).getFeatures();
fids = toIdList(features);
assertEquals(changeType + fids.toString(), expectedAdded, fids.size());
assertEquals(changeType + fids.toString(), expectedAdded, features.size());
changeType = ChangeType.REMOVED;
features = dataStore.getDiffFeatureSource(pointsName, oldRoot.toString(), changeType).getFeatures();
fids = toIdList(features);
assertEquals(changeType + fids.toString(), expectedRemoved, fids.size());
assertEquals(changeType + fids.toString(), expectedRemoved, features.size());
changeType = ChangeType.CHANGED_NEW;
features = dataStore.getDiffFeatureSource(pointsName, oldRoot.toString(), changeType).getFeatures();
fids = toIdList(features);
assertEquals(changeType + fids.toString(), expectedChanged, fids.size());
assertEquals(changeType + fids.toString(), expectedChanged, features.size());
changeType = ChangeType.CHANGED_OLD;
features = dataStore.getDiffFeatureSource(pointsName, oldRoot.toString(), changeType).getFeatures();
fids = toIdList(features);
assertEquals(changeType + fids.toString(), expectedChanged, fids.size());
assertEquals(changeType + fids.toString(), expectedChanged, features.size());
}
use of org.geotools.data.simple.SimpleFeatureCollection in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testGetFeaturesFilter.
@Test
public void testGetFeaturesFilter() throws Exception {
SimpleFeatureCollection collection;
Set<List<Object>> actual;
Set<List<Object>> expected;
Filter filter;
filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = Collections.singleton(((SimpleFeature) points2).getAttributes());
assertEquals(expected, actual);
ReferencedEnvelope queryBounds = boundsOf(points1, points2);
Polygon geometry = JTS.toGeometry(queryBounds);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
assertEquals(expected, actual);
ReferencedEnvelope transformedQueryBounds;
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
transformedQueryBounds = queryBounds.transform(queryCrs, true);
geometry = JTS.toGeometry(transformedQueryBounds);
geometry.setUserData(queryCrs);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
assertEquals(expected.size(), actual.size());
assertEquals(expected, actual);
filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
collection = linesSource.getFeatures(new Query(linesName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) lines2).getAttributes(), ((SimpleFeature) lines3).getAttributes());
assertEquals(expected, actual);
}
Aggregations