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());
}
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;
}
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());
}
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()]);
}
Aggregations