Search in sources :

Example 1 with AvroFeatureDefinition

use of org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition in project geowave by locationtech.

the class GeoWaveAvroFeatureUtils method deserializeAvroSimpleFeature.

/**
 * * Deserialize byte array into an AvroSimpleFeature then convert to a SimpleFeature
 *
 * @param avroData serialized bytes of a AvroSimpleFeature
 * @return Collection of GeoTools SimpleFeature instances.
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws ParseException
 */
public static synchronized SimpleFeature deserializeAvroSimpleFeature(final byte[] avroData) throws IOException, ClassNotFoundException, ParseException {
    // Deserialize
    final AvroSimpleFeature sfc = deserializeASF(avroData, null);
    final AvroFeatureDefinition featureDefinition = sfc.getFeatureType();
    return avroSimpleFeatureToGTSimpleFeature(avroFeatureDefinitionToGTSimpleFeatureType(featureDefinition), featureDefinition.getAttributeTypes(), sfc.getValue());
}
Also used : AvroFeatureDefinition(org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition) AvroSimpleFeature(org.locationtech.geowave.adapter.vector.avro.AvroSimpleFeature)

Example 2 with AvroFeatureDefinition

use of org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition in project geowave by locationtech.

the class GeoWaveAvroFeatureUtils method buildFeatureDefinition.

/**
 * Add the attributes, types and classifications for the SimpleFeatureType to the provided
 * FeatureDefinition
 *
 * @param fd - existing Feature Definition (or new one if null)
 * @param sft - SimpleFeatureType of the simpleFeature being serialized
 * @param defaultClassifications - map of attribute names to classification
 * @param defaultClassification - default classification if one could not be found in the map
 * @return the feature definition
 * @throws IOException
 */
public static AvroFeatureDefinition buildFeatureDefinition(AvroFeatureDefinition fd, final SimpleFeatureType sft, final Map<String, String> defaultClassifications, final String defaultClassification) throws IOException {
    if (fd == null) {
        fd = new AvroFeatureDefinition();
    }
    fd.setFeatureTypeName(sft.getTypeName());
    final List<String> attributes = new ArrayList<>(sft.getAttributeCount());
    final List<String> types = new ArrayList<>(sft.getAttributeCount());
    final List<String> classifications = new ArrayList<>(sft.getAttributeCount());
    for (final AttributeDescriptor attr : sft.getAttributeDescriptors()) {
        final String localName = attr.getLocalName();
        attributes.add(localName);
        types.add(attr.getType().getBinding().getCanonicalName());
        classifications.add(getClassification(localName, defaultClassifications, defaultClassification));
    }
    fd.setAttributeNames(attributes);
    fd.setAttributeTypes(types);
    fd.setAttributeDefaultClassifications(classifications);
    return fd;
}
Also used : AvroFeatureDefinition(org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition) ArrayList(java.util.ArrayList) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 3 with AvroFeatureDefinition

use of org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition in project geowave by locationtech.

the class GeoWaveAvroIngestPlugin method toGeoWaveDataInternal.

@Override
protected CloseableIterator<GeoWaveData<SimpleFeature>> toGeoWaveDataInternal(final AvroSimpleFeatureCollection featureCollection, final String[] indexNames) {
    final AvroFeatureDefinition featureDefinition = featureCollection.getFeatureType();
    final List<GeoWaveData<SimpleFeature>> retVal = new ArrayList<>();
    SimpleFeatureType featureType;
    try {
        featureType = GeoWaveAvroFeatureUtils.avroFeatureDefinitionToGTSimpleFeatureType(featureDefinition);
        final FeatureDataAdapter adapter = new FeatureDataAdapter(featureType);
        final List<String> attributeTypes = featureDefinition.getAttributeTypes();
        for (final AvroAttributeValues attributeValues : featureCollection.getSimpleFeatureCollection()) {
            try {
                final SimpleFeature simpleFeature = GeoWaveAvroFeatureUtils.avroSimpleFeatureToGTSimpleFeature(featureType, attributeTypes, attributeValues);
                retVal.add(new GeoWaveData<>(adapter, indexNames, simpleFeature));
            } catch (final Exception e) {
                LOGGER.warn("Unable to read simple feature from Avro", e);
            }
        }
    } catch (final ClassNotFoundException e) {
        LOGGER.warn("Unable to read simple feature type from Avro", e);
    }
    return new Wrapper<>(retVal.iterator());
}
Also used : Wrapper(org.locationtech.geowave.core.store.CloseableIterator.Wrapper) AvroAttributeValues(org.locationtech.geowave.adapter.vector.avro.AvroAttributeValues) ArrayList(java.util.ArrayList) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) AvroFeatureDefinition(org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) GeoWaveData(org.locationtech.geowave.core.store.ingest.GeoWaveData) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter)

Example 4 with AvroFeatureDefinition

use of org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition in project geowave by locationtech.

the class GeoWaveAvroIngestPlugin method getDataAdapters.

@Override
public DataTypeAdapter<SimpleFeature>[] getDataAdapters(final URL url) {
    final Map<String, FeatureDataAdapter> adapters = Maps.newHashMap();
    try (final CloseableIterator<AvroSimpleFeatureCollection> avroObjects = toAvroObjects(url)) {
        while (avroObjects.hasNext()) {
            final AvroFeatureDefinition featureDefinition = avroObjects.next().getFeatureType();
            try {
                final SimpleFeatureType featureType = GeoWaveAvroFeatureUtils.avroFeatureDefinitionToGTSimpleFeatureType(featureDefinition);
                final FeatureDataAdapter adapter = new FeatureDataAdapter(featureType);
                adapters.put(adapter.getTypeName(), adapter);
            } catch (final ClassNotFoundException e) {
                LOGGER.warn("Unable to read simple feature type from Avro", e);
            }
        }
    }
    return adapters.values().toArray(new FeatureDataAdapter[adapters.size()]);
}
Also used : AvroFeatureDefinition(org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) AvroSimpleFeatureCollection(org.locationtech.geowave.adapter.vector.avro.AvroSimpleFeatureCollection)

Aggregations

AvroFeatureDefinition (org.locationtech.geowave.adapter.vector.avro.AvroFeatureDefinition)4 ArrayList (java.util.ArrayList)2 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 IOException (java.io.IOException)1 AvroAttributeValues (org.locationtech.geowave.adapter.vector.avro.AvroAttributeValues)1 AvroSimpleFeature (org.locationtech.geowave.adapter.vector.avro.AvroSimpleFeature)1 AvroSimpleFeatureCollection (org.locationtech.geowave.adapter.vector.avro.AvroSimpleFeatureCollection)1 Wrapper (org.locationtech.geowave.core.store.CloseableIterator.Wrapper)1 GeoWaveData (org.locationtech.geowave.core.store.ingest.GeoWaveData)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1