Search in sources :

Example 1 with SpatialFieldDescriptorBuilder

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.");
}
Also used : FactoryException(org.opengis.referencing.FactoryException) SpatialFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder) IndexDimensionHint(org.locationtech.geowave.core.index.IndexDimensionHint)

Example 2 with SpatialFieldDescriptorBuilder

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));
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) TemporalFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptorBuilder) SpatialFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) TemporalFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptorBuilder) SpatialFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder) FieldDescriptorBuilder(org.locationtech.geowave.core.store.adapter.FieldDescriptorBuilder) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor)

Aggregations

SpatialFieldDescriptorBuilder (org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder)2 SpatialFieldDescriptor (org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor)1 TemporalFieldDescriptorBuilder (org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptorBuilder)1 IndexDimensionHint (org.locationtech.geowave.core.index.IndexDimensionHint)1 FieldDescriptor (org.locationtech.geowave.core.store.adapter.FieldDescriptor)1 FieldDescriptorBuilder (org.locationtech.geowave.core.store.adapter.FieldDescriptorBuilder)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)1 FactoryException (org.opengis.referencing.FactoryException)1