Search in sources :

Example 11 with SimpleFeatureTypeBuilder

use of org.geotools.feature.simple.SimpleFeatureTypeBuilder 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 12 with SimpleFeatureTypeBuilder

use of org.geotools.feature.simple.SimpleFeatureTypeBuilder in project ddf by codice.

the class TestPubSubOgcFilter method generateMetacardFeatureType.

private final FeatureType generateMetacardFeatureType() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("PubSubFeature");
    // add properties
    b.add(Metacard.TITLE, String.class);
    b.add(Metacard.CONTENT_TYPE, String.class);
    b.add(Metacard.CREATED, Date.class);
    b.add(Metacard.MODIFIED, Date.class);
    b.add(Metacard.EXPIRATION, Date.class);
    b.add(Metacard.EFFECTIVE, Date.class);
    b.add(Metacard.METADATA, Document.class);
    // add geo
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add(Metacard.GEOGRAPHY, Geometry.class);
    return b.buildFeatureType();
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder)

Example 13 with SimpleFeatureTypeBuilder

use of org.geotools.feature.simple.SimpleFeatureTypeBuilder in project GeoGig by boundlessgeo.

the class TestHelper method createTestFactory.

public static AbstractDataStoreFactory createTestFactory() throws Exception {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setCRS(CRS.decode("EPSG:4326"));
    builder.add("geom", Point.class);
    builder.add("label", String.class);
    builder.setName("table1");
    SimpleFeatureType type = builder.buildFeatureType();
    SimpleFeatureTypeBuilder builder2 = new SimpleFeatureTypeBuilder();
    builder2.setCRS(CRS.decode("EPSG:4326"));
    builder2.add("geom", Point.class);
    builder2.add("name", String.class);
    builder2.setName("table2");
    SimpleFeatureType type2 = builder2.buildFeatureType();
    SimpleFeatureTypeBuilder builder3 = new SimpleFeatureTypeBuilder();
    builder3.setCRS(CRS.decode("EPSG:4326"));
    builder3.add("geom", Point.class);
    builder3.add("name", String.class);
    builder3.add("number", Long.class);
    builder3.setName("table3");
    SimpleFeatureTypeBuilder builder4 = new SimpleFeatureTypeBuilder();
    builder4.setCRS(CRS.decode("EPSG:4326"));
    builder4.add("geom", Point.class);
    builder4.add("number", Double.class);
    builder4.setName("table4");
    // A table with a shp-like structure
    SimpleFeatureTypeBuilder builderShp = new SimpleFeatureTypeBuilder();
    builderShp.setCRS(CRS.decode("EPSG:4326"));
    builderShp.add("the_geom", Point.class);
    builderShp.add("number", Double.class);
    builderShp.add("number2", Double.class);
    builderShp.setName("shpLikeTable");
    SimpleFeatureTypeBuilder builderShp2 = new SimpleFeatureTypeBuilder();
    builderShp2.setCRS(CRS.decode("EPSG:4326"));
    builderShp2.add("the_geom", Point.class);
    builderShp2.add("number", Double.class);
    builderShp2.add("number2", Integer.class);
    builderShp2.setName("shpLikeTable2");
    // A table with a geojson-like structure
    SimpleFeatureTypeBuilder builderGeoJson = new SimpleFeatureTypeBuilder();
    builderGeoJson.setCRS(CRS.decode("EPSG:4326"));
    builderGeoJson.add("number", Double.class);
    builderGeoJson.add("number2", Double.class);
    builderGeoJson.add("geom", Point.class);
    builderGeoJson.setName("GeoJsonLikeTable");
    SimpleFeatureTypeBuilder builderGeoJson2 = new SimpleFeatureTypeBuilder();
    builderGeoJson2.setCRS(CRS.decode("EPSG:23030"));
    builderGeoJson2.add("number", Double.class);
    builderGeoJson2.add("number2", Double.class);
    builderGeoJson2.add("geom", Point.class);
    builderGeoJson2.setName("GeoJsonLikeTable2");
    SimpleFeatureType type3 = builder3.buildFeatureType();
    SimpleFeatureType typeShp = builderShp.buildFeatureType();
    SimpleFeatureType typeShp2 = builderShp2.buildFeatureType();
    SimpleFeatureType typeGeoJson = builderGeoJson.buildFeatureType();
    SimpleFeatureType typeGeoJson2 = builderGeoJson2.buildFeatureType();
    GeometryFactory gf = new GeometryFactory();
    SimpleFeature f1 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 8)), "feature1" }, "table1.feature1");
    SimpleFeature f2 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 4)), "feature2" }, "table1.feature2");
    SimpleFeature f3 = SimpleFeatureBuilder.build(type2, new Object[] { gf.createPoint(new Coordinate(3, 2)), "feature3" }, "table2.feature3");
    SimpleFeature f4 = SimpleFeatureBuilder.build(type3, new Object[] { gf.createPoint(new Coordinate(0, 5)), "feature4", 1000 }, "table2.feature4");
    SimpleFeature f5 = SimpleFeatureBuilder.build(typeShp, new Object[] { gf.createPoint(new Coordinate(0, 6)), 2.2, 1000 }, "feature1");
    SimpleFeature f6 = SimpleFeatureBuilder.build(typeShp2, new Object[] { gf.createPoint(new Coordinate(0, 7)), 3.2, 1100.0 }, "feature1");
    SimpleFeature f7 = SimpleFeatureBuilder.build(typeGeoJson, new Object[] { 4.2, 1200, gf.createPoint(new Coordinate(0, 8)) }, "feature1");
    SimpleFeature f8 = SimpleFeatureBuilder.build(typeGeoJson2, new Object[] { 4.2, 1200, gf.createPoint(new Coordinate(0, 9)) }, "feature1");
    MemoryDataStore testDataStore = new MemoryDataStore();
    testDataStore.addFeature(f1);
    testDataStore.addFeature(f2);
    testDataStore.addFeature(f3);
    testDataStore.addFeature(f4);
    testDataStore.addFeature(f5);
    testDataStore.addFeature(f6);
    testDataStore.addFeature(f7);
    testDataStore.addFeature(f8);
    testDataStore.createSchema(builder4.buildFeatureType());
    final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
    when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(testDataStore);
    when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
    return factory;
}
Also used : AbstractDataStoreFactory(org.geotools.data.AbstractDataStoreFactory) Serializable(java.io.Serializable) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Matchers.anyString(org.mockito.Matchers.anyString) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 14 with SimpleFeatureTypeBuilder

use of org.geotools.feature.simple.SimpleFeatureTypeBuilder in project GeoGig by boundlessgeo.

the class MappingRule method getFeatureType.

/**
     * Returns the feature type defined by this rule. This is the feature type that features
     * transformed by this rule will have
     * 
     * @return
     */
public SimpleFeatureType getFeatureType() {
    if (featureType == null) {
        SimpleFeatureTypeBuilder fb = new SimpleFeatureTypeBuilder();
        fb.setName(name);
        fb.add("id", Long.class);
        if (defaultFields != null) {
            for (DefaultField df : defaultFields) {
                fb.add(df.name().toLowerCase(), df.getFieldClass());
            }
        }
        Set<String> keys = this.fields.keySet();
        for (String key : keys) {
            AttributeDefinition field = fields.get(key);
            Class<?> clazz = field.getType().getBinding();
            if (Geometry.class.isAssignableFrom(clazz)) {
                Preconditions.checkArgument(geometryType == null, "The mapping has more than one geometry attribute");
                CoordinateReferenceSystem epsg4326;
                try {
                    epsg4326 = CRS.decode("EPSG:4326", true);
                    fb.add(field.getName(), clazz, epsg4326);
                } catch (NoSuchAuthorityCodeException e) {
                } catch (FactoryException e) {
                }
                geometryType = clazz;
            } else {
                fb.add(field.getName(), clazz);
            }
        }
        Preconditions.checkNotNull(geometryType, "The mapping rule does not define a geometry field");
        if (!geometryType.equals(Point.class)) {
            fb.add("nodes", String.class);
        }
        featureType = fb.buildFeatureType();
        featureBuilder = new SimpleFeatureBuilder(featureType);
    }
    return featureType;
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) FactoryException(org.opengis.referencing.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(com.vividsolutions.jts.geom.Point) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 15 with SimpleFeatureTypeBuilder

use of org.geotools.feature.simple.SimpleFeatureTypeBuilder 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;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Aggregations

SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)17 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)12 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)6 Test (org.junit.Test)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)4 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)3 Serializable (java.io.Serializable)3 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)3 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 Feature (org.opengis.feature.Feature)3 Point (com.vividsolutions.jts.geom.Point)2 AbstractDataStoreFactory (org.geotools.data.AbstractDataStoreFactory)2 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)2 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)2 NameImpl (org.geotools.feature.NameImpl)2 RevCommit (org.locationtech.geogig.api.RevCommit)2 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)2