Search in sources :

Example 16 with SimpleFeatureTypeBuilder

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

the class ImportOp method forceFeatureTypeName.

private SimpleFeatureType forceFeatureTypeName(SimpleFeatureType featureType, String path) {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setAttributes(featureType.getAttributeDescriptors());
    builder.setName(new NameImpl(featureType.getName().getNamespaceURI(), path));
    builder.setCRS(featureType.getCoordinateReferenceSystem());
    featureType = builder.buildFeatureType();
    return featureType;
}
Also used : NameImpl(org.geotools.feature.NameImpl) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder)

Example 17 with SimpleFeatureTypeBuilder

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

the class TestPubSubOgcFilter method generateSampleFeature.

private SimpleFeature generateSampleFeature() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("PubSubFeature");
    // add properties
    b.add("name", String.class);
    b.add("classification", Integer.class);
    b.add("height", Double.class);
    com.vividsolutions.jts.geom.GeometryFactory geoFactory = JTSFactoryFinder.getGeometryFactory(null);
    // add geo
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("geo", Point.class);
    final SimpleFeatureType pubSubFeature = b.buildFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(pubSubFeature);
    featureBuilder.set("name", "FirstFeature");
    featureBuilder.set("classification", 10);
    featureBuilder.set("height", 5.8);
    com.vividsolutions.jts.geom.Point point = geoFactory.createPoint(new Coordinate(-112, 28));
    featureBuilder.set("geo", point);
    SimpleFeature feature = featureBuilder.buildFeature("f1");
    // it looks like if I add an attribute into the feature that is of geometry type, it
    // automatically
    // becomes the default geo property. If no geo is specified, getDefaultGeometryProperty
    // returns null
    GeometryAttribute defaultGeo = feature.getDefaultGeometryProperty();
    LOGGER.debug("geo name: {}", defaultGeo.getName());
    LOGGER.debug("geo: {}", defaultGeo);
    return feature;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryAttribute(org.opengis.feature.GeometryAttribute) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

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