Search in sources :

Example 1 with AttributeTypeBuilder

use of org.geotools.feature.AttributeTypeBuilder in project core-geonetwork by geonetwork.

the class GeonetTestFixture method registerServiceConfigAndInitDatastoreTable.

protected ServiceConfig registerServiceConfigAndInitDatastoreTable(AbstractCoreIntegrationTest test) throws IOException {
    final ArrayList<Element> params = test.getServiceConfigParameterElements();
    final ServiceConfig serviceConfig = new ServiceConfig(params);
    final String initializedString = "initialized";
    try {
        _applicationContext.getBean(initializedString);
    } catch (NoSuchBeanDefinitionException e) {
        _applicationContext.getBeanFactory().registerSingleton("serviceConfig", serviceConfig);
        _applicationContext.getBeanFactory().registerSingleton(initializedString, initializedString);
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        AttributeDescriptor geomDescriptor = new AttributeTypeBuilder().crs(DefaultGeographicCRS.WGS84).binding(MultiPolygon.class).buildDescriptor("the_geom");
        builder.setName("spatialIndex");
        builder.add(geomDescriptor);
        builder.add(SpatialIndexWriter._IDS_ATTRIBUTE_NAME, String.class);
        this.dataStore.createSchema(builder.buildFeatureType());
    }
    return serviceConfig;
}
Also used : AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) ServiceConfig(jeeves.server.ServiceConfig) Element(org.jdom.Element) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 2 with AttributeTypeBuilder

use of org.geotools.feature.AttributeTypeBuilder in project geonetwork by georchestra.

the class OgcGenericFilters method reprojectGeometryType.

private static SimpleFeatureType reprojectGeometryType(Name geometryAttName) {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    AttributeTypeBuilder attBuilder = new AttributeTypeBuilder();
    attBuilder.crs(DefaultGeographicCRS.WGS84);
    attBuilder.binding(MultiPolygon.class);
    GeometryDescriptor geomDescriptor = attBuilder.buildDescriptor(geometryAttName, attBuilder.buildGeometryType());
    builder.setName("dummy");
    builder.setCRS(DefaultGeographicCRS.WGS84);
    builder.add(geomDescriptor);
    return builder.buildFeatureType();
}
Also used : AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder)

Example 3 with AttributeTypeBuilder

use of org.geotools.feature.AttributeTypeBuilder in project geo-platform by geosdi.

the class ShapeAppender method buildSchemaAttribute.

/**
 * Builds a single attribute for the output Feature schema. By default it
 * uses the original source attribute definition, if not overridden by
 * configuration.
 *
 * @param attributeName
 * @param crs crs to use for geometric attributes
 * @param schema
 * @return
 */
private AttributeDescriptor buildSchemaAttribute(String attributeName, SimpleFeatureType schema, CoordinateReferenceSystem crs) {
    AttributeDescriptor attr;
    if (configuration.getAttributeMappings().containsKey(attributeName) && !isExpression(configuration.getAttributeMappings().get(attributeName).toString())) {
        attr = schema.getDescriptor(configuration.getAttributeMappings().get(attributeName).toString());
    } else {
        attr = schema.getDescriptor(attributeName);
    }
    AttributeTypeBuilder builder = new AttributeTypeBuilder();
    builder.setName(attr.getLocalName());
    builder.setBinding(attr.getType().getBinding());
    if (attr instanceof GeometryDescriptor) {
        if (crs == null) {
            crs = ((GeometryDescriptor) attr).getCoordinateReferenceSystem();
        }
        builder.setCRS(crs);
    }
    // set descriptor information
    builder.setMinOccurs(attr.getMinOccurs());
    builder.setMaxOccurs(attr.getMaxOccurs());
    builder.setNillable(attr.isNillable());
    return builder.buildDescriptor(attributeName);
}
Also used : AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 4 with AttributeTypeBuilder

use of org.geotools.feature.AttributeTypeBuilder in project geowave by locationtech.

the class KMeansUtils method writeClusterHulls.

public static DataTypeAdapter writeClusterHulls(final JavaRDD<Vector> inputCentroids, final KMeansModel clusterModel, final DataStorePluginOptions outputDataStore, final String hullAdapterName, final boolean computeMetadata) {
    final JavaPairRDD<Integer, Iterable<Vector>> groupByRdd = KMeansHullGenerator.groupByIndex(inputCentroids, clusterModel);
    final JavaPairRDD<Integer, Geometry> hullRdd = KMeansHullGenerator.generateHullsRDD(groupByRdd);
    final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.setName(hullAdapterName);
    typeBuilder.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE);
    try {
        typeBuilder.setCRS(CRS.decode("EPSG:4326", true));
    } catch (final FactoryException e) {
        LOGGER.error(e.getMessage(), e);
    }
    final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
    typeBuilder.add(attrBuilder.binding(Geometry.class).nillable(false).buildDescriptor(Geometry.class.getName().toString()));
    typeBuilder.add(attrBuilder.binding(Integer.class).nillable(false).buildDescriptor("ClusterIndex"));
    typeBuilder.add(attrBuilder.binding(Integer.class).nillable(false).buildDescriptor("Count"));
    typeBuilder.add(attrBuilder.binding(Double.class).nillable(false).buildDescriptor("Area"));
    typeBuilder.add(attrBuilder.binding(Double.class).nillable(false).buildDescriptor("Density"));
    final SimpleFeatureType sfType = typeBuilder.buildFeatureType();
    final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);
    final FeatureDataAdapter featureAdapter = new FeatureDataAdapter(sfType);
    final DataStore featureStore = outputDataStore.createDataStore();
    final Index featureIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    final PolygonAreaCalculator polyCalc = (computeMetadata ? new PolygonAreaCalculator() : null);
    featureStore.addType(featureAdapter, featureIndex);
    try (Writer writer = featureStore.createWriter(featureAdapter.getTypeName())) {
        for (final Tuple2<Integer, Geometry> hull : hullRdd.collect()) {
            final Integer index = hull._1;
            final Geometry geom = hull._2;
            sfBuilder.set(Geometry.class.getName(), geom);
            sfBuilder.set("ClusterIndex", index);
            int count = 0;
            double area = 0.0;
            double density = 0.0;
            if (computeMetadata) {
                for (final Iterable<Vector> points : groupByRdd.lookup(index)) {
                    final Vector[] pointVec = Iterables.toArray(points, Vector.class);
                    count += pointVec.length;
                }
                try {
                    // HP Fortify "NULL Pointer Dereference" false positive
                    // Exception handling will catch if polyCalc is null
                    area = polyCalc.getAreaDensify(geom);
                    density = count / area;
                } catch (final Exception e) {
                    LOGGER.error("Problem computing polygon area: " + e.getMessage());
                }
            }
            sfBuilder.set("Count", count);
            sfBuilder.set("Area", area);
            sfBuilder.set("Density", density);
            final SimpleFeature sf = sfBuilder.buildFeature("Hull-" + index);
            writer.write(sf);
        }
    }
    return featureAdapter;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) FactoryException(org.opengis.referencing.FactoryException) Index(org.locationtech.geowave.core.store.api.Index) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) DataStore(org.locationtech.geowave.core.store.api.DataStore) Vector(org.apache.spark.mllib.linalg.Vector) PolygonAreaCalculator(org.locationtech.geowave.adapter.vector.util.PolygonAreaCalculator) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) FactoryException(org.opengis.referencing.FactoryException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(org.locationtech.jts.geom.Geometry) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Writer(org.locationtech.geowave.core.store.api.Writer) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 5 with AttributeTypeBuilder

use of org.geotools.feature.AttributeTypeBuilder in project geowave by locationtech.

the class SpatialBinningAggregationExample method getSimpleFeatureType.

/**
 * A helper that constructs the SimpleFeatureType used in this example.
 */
private static SimpleFeatureType getSimpleFeatureType() {
    final String name = "ExampleSimpleFeatureType";
    final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
    final AttributeTypeBuilder atBuilder = new AttributeTypeBuilder();
    sftBuilder.setName(name);
    // the location name isn't used in this example, its just here for show!
    sftBuilder.add(atBuilder.binding(String.class).nillable(false).buildDescriptor("locationName"));
    // this is used for the grouping (the `.bin` call).
    sftBuilder.add(atBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geometry"));
    // this is the field that is summed in each group, as defined by the `.aggregate` call.
    sftBuilder.add(atBuilder.binding(Integer.class).nillable(false).buildDescriptor("population"));
    return sftBuilder.buildFeatureType();
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder)

Aggregations

AttributeTypeBuilder (org.geotools.feature.AttributeTypeBuilder)48 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)47 Geometry (org.locationtech.jts.geom.Geometry)23 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)19 Date (java.util.Date)17 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)12 SimpleFeature (org.opengis.feature.simple.SimpleFeature)12 Point (org.locationtech.jts.geom.Point)10 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)9 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)7 TimeDescriptorConfiguration (org.locationtech.geowave.core.geotime.util.TimeDescriptors.TimeDescriptorConfiguration)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 File (java.io.File)4 SpatialIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder)4 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 DataStore (org.locationtech.geowave.core.store.api.DataStore)3 Index (org.locationtech.geowave.core.store.api.Index)3 Writer (org.locationtech.geowave.core.store.api.Writer)3