Search in sources :

Example 31 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project GeoGig by boundlessgeo.

the class ImportOpTest method testImportAllWithDifferentFeatureTypesAndDestPathAndAdd.

@Test
public void testImportAllWithDifferentFeatureTypesAndDestPathAndAdd() throws Exception {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setCRS(CRS.decode("EPSG:4326"));
    builder.add("geom", Point.class);
    builder.add("label", String.class);
    builder.setName("dest");
    SimpleFeatureType type = builder.buildFeatureType();
    GeometryFactory gf = new GeometryFactory();
    SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(0, 0)), "feature0" }, "feature");
    geogig.getRepository().workingTree().insert("dest", feature);
    ImportOp importOp = geogig.command(ImportOp.class);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setAll(true);
    importOp.setOverwrite(false);
    importOp.setDestinationPath("dest");
    importOp.setAdaptToDefaultFeatureType(false);
    importOp.call();
    Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
    ArrayList<NodeRef> list = Lists.newArrayList(features);
    assertEquals(5, list.size());
    TreeSet<ObjectId> set = Sets.newTreeSet();
    ArrayList<RevFeatureType> ftlist = new ArrayList<RevFeatureType>();
    for (NodeRef node : list) {
        Optional<RevFeatureType> ft = geogig.command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class);
        assertTrue(ft.isPresent());
        ftlist.add(ft.get());
        set.add(node.getMetadataId());
    }
    assertEquals(4, set.size());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ObjectId(org.locationtech.geogig.api.ObjectId) ArrayList(java.util.ArrayList) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 32 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature 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());
}
Also used : ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) FeatureSource(org.geotools.data.FeatureSource) QueryCapabilities(org.geotools.data.QueryCapabilities) Query(org.geotools.data.Query) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 33 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature 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));
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FilterAdapter(ddf.catalog.filter.FilterAdapter) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Test(org.junit.Test)

Example 34 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project ddf by codice.

the class TestPubSubOgcFilter method testContextualFeatureEvaluate.

@Test
@Ignore
public void testContextualFeatureEvaluate() throws TransformerException {
    SimpleFeature feature = generateSampleFeature();
    FilterFactory filterFactory = new FilterFactoryImpl();
    PropertyIsEqualTo filter = filterFactory.equal(filterFactory.property("name"), filterFactory.literal("FirstFeature"), true);
    printFilter(filter);
    assertTrue(filter.evaluate(feature));
}
Also used : PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project ddf by codice.

the class TestPubSubOgcFilter method testGeospatialFeatureEvaluate.

@Test
@Ignore
public void testGeospatialFeatureEvaluate() throws TransformerException {
    SimpleFeature feature = generateSampleFeature();
    FilterFactoryImpl filterFactory = new FilterFactoryImpl();
    BBOX bboxFilter = filterFactory.bbox("geo", -114, 10, -110, 30, DefaultGeographicCRS.WGS84.toString());
    assertTrue(bboxFilter.evaluate(feature));
    BBOX bboxFilter1 = filterFactory.bbox("geo", -110, 10, 0, 30, DefaultGeographicCRS.WGS84.toString());
    assertFalse(bboxFilter1.evaluate(feature));
}
Also used : BBOX(org.opengis.filter.spatial.BBOX) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SimpleFeature (org.opengis.feature.simple.SimpleFeature)66 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)32 Test (org.junit.Test)27 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)21 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)16 Optional (com.google.common.base.Optional)15 Coordinate (com.vividsolutions.jts.geom.Coordinate)15 NodeRef (org.locationtech.geogig.api.NodeRef)13 ObjectId (org.locationtech.geogig.api.ObjectId)13 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)12 File (java.io.File)10 ArrayList (java.util.ArrayList)10 DefaultTransaction (org.geotools.data.DefaultTransaction)10 WorkingTree (org.locationtech.geogig.repository.WorkingTree)10 IOException (java.io.IOException)9 List (java.util.List)9 Feature (org.opengis.feature.Feature)9 Function (com.google.common.base.Function)8 Transaction (org.geotools.data.Transaction)8