use of org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder in project geowave by locationtech.
the class SpatialAnnotatedFieldDescriptorBuilder method buildFieldDescriptor.
@Override
public FieldDescriptor<?> buildFieldDescriptor(Field field) {
if (field.isAnnotationPresent(GeoWaveSpatialField.class)) {
final GeoWaveSpatialField fieldAnnotation = field.getAnnotation(GeoWaveSpatialField.class);
final String fieldName;
if (fieldAnnotation.name().isEmpty()) {
fieldName = field.getName();
} else {
fieldName = fieldAnnotation.name();
}
final String[] indexHints = fieldAnnotation.indexHints();
final SpatialFieldDescriptorBuilder<?> builder = new SpatialFieldDescriptorBuilder<>(BasicDataTypeAdapter.normalizeClass(field.getType()));
for (final String hint : indexHints) {
builder.indexHint(new IndexDimensionHint(hint));
}
if (!fieldAnnotation.crs().isEmpty()) {
try {
builder.crs(CRS.decode(fieldAnnotation.crs()));
} catch (FactoryException e) {
throw new RuntimeException("Unable to decode CRS: " + fieldAnnotation.crs(), e);
}
}
if (fieldAnnotation.spatialIndexHint()) {
builder.spatialIndexHint();
}
if (fieldAnnotation.latitudeIndexHint()) {
builder.latitudeIndexHint();
}
if (fieldAnnotation.longitudeIndexHint()) {
builder.longitudeIndexHint();
}
return builder.fieldName(fieldName).build();
}
throw new RuntimeException("Field is missing GeoWaveSpatialField annotation.");
}
use of org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder in project geowave by locationtech.
the class FeatureDataAdapter method initializeFieldDescriptors.
private void initializeFieldDescriptors() {
final List<AttributeDescriptor> attributes = featureType.getAttributeDescriptors();
fieldDescriptors = new FieldDescriptor[attributes.size()];
for (int i = 0; i < attributes.size(); i++) {
final AttributeDescriptor attribute = attributes.get(i);
if (attribute instanceof GeometryDescriptor) {
final SpatialFieldDescriptorBuilder<?> builder = new SpatialFieldDescriptorBuilder<>(attribute.getType().getBinding());
builder.fieldName(attribute.getName().getLocalPart());
builder.crs(((GeometryDescriptor) attribute).getCoordinateReferenceSystem());
if ((featureType.getGeometryDescriptor() != null) && featureType.getGeometryDescriptor().equals(attribute)) {
builder.spatialIndexHint();
}
fieldDescriptors[i] = builder.build();
} else if ((timeDescriptors != null) && attribute.equals(timeDescriptors.getTime())) {
fieldDescriptors[i] = new TemporalFieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).timeIndexHint().build();
} else if ((timeDescriptors != null) && attribute.equals(timeDescriptors.getStartRange())) {
fieldDescriptors[i] = new TemporalFieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).startTimeIndexHint().build();
} else if ((timeDescriptors != null) && attribute.equals(timeDescriptors.getEndRange())) {
fieldDescriptors[i] = new TemporalFieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).endTimeIndexHint().build();
} else {
fieldDescriptors[i] = new FieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).build();
}
}
// this assumes attribute names are unique, which *should* be a fair assumption
descriptorsMap = Arrays.stream(fieldDescriptors).collect(Collectors.toMap(FieldDescriptor::fieldName, descriptor -> descriptor));
}
Aggregations