use of org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor in project geowave by locationtech.
the class MigrationTest method testLegacyFeatureDataAdapterMigration.
@Test
public void testLegacyFeatureDataAdapterMigration() {
final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();
builder.setName("testType");
builder.setNamespaceURI("geowave.namespace");
builder.add(attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("strAttr"));
builder.add(attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor("intAttr"));
builder.add(attributeTypeBuilder.binding(Date.class).nillable(false).buildDescriptor("dateAttr"));
builder.add(attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor("geom"));
builder.crs(GeometryUtils.getDefaultCRS());
final SimpleFeatureType featureType = builder.buildFeatureType();
final AttributeDescriptor stringAttr = featureType.getDescriptor("strAttr");
// Configure legacy visiblity
stringAttr.getUserData().put("visibility", Boolean.TRUE);
featureType.getUserData().put("visibilityManagerClass", "org.locationtech.geowave.adapter.vector.plugin.visibility.JsonDefinitionColumnVisibilityManagement");
LegacyFeatureDataAdapter adapter = new LegacyFeatureDataAdapter(featureType, "EPSG:3257");
final byte[] adapterBinary = PersistenceUtils.toBinary(adapter);
final Persistable persistableAdapter = PersistenceUtils.fromBinary(adapterBinary);
assertTrue(persistableAdapter instanceof LegacyFeatureDataAdapter);
adapter = (LegacyFeatureDataAdapter) persistableAdapter;
assertNotNull(adapter.getUpdatedAdapter());
final FeatureDataAdapter updatedAdapter = adapter.getUpdatedAdapter();
assertEquals(4, updatedAdapter.getFieldDescriptors().length);
assertEquals(String.class, updatedAdapter.getFieldDescriptor("strAttr").bindingClass());
assertEquals(Integer.class, updatedAdapter.getFieldDescriptor("intAttr").bindingClass());
assertTrue(TemporalFieldDescriptor.class.isAssignableFrom(updatedAdapter.getFieldDescriptor("dateAttr").getClass()));
final TemporalFieldDescriptor<?> temporalField = (TemporalFieldDescriptor<?>) updatedAdapter.getFieldDescriptor("dateAttr");
assertEquals(Date.class, temporalField.bindingClass());
assertTrue(temporalField.indexHints().contains(TimeField.TIME_DIMENSION_HINT));
assertTrue(SpatialFieldDescriptor.class.isAssignableFrom(updatedAdapter.getFieldDescriptor("geom").getClass()));
final SpatialFieldDescriptor<?> spatialField = (SpatialFieldDescriptor<?>) updatedAdapter.getFieldDescriptor("geom");
assertEquals(Point.class, spatialField.bindingClass());
assertEquals(GeometryUtils.getDefaultCRS(), spatialField.crs());
assertTrue(spatialField.indexHints().contains(SpatialField.LATITUDE_DIMENSION_HINT));
assertTrue(spatialField.indexHints().contains(SpatialField.LONGITUDE_DIMENSION_HINT));
assertEquals("testType", updatedAdapter.getTypeName());
assertEquals(SimpleFeature.class, updatedAdapter.getDataClass());
assertTrue(updatedAdapter.hasTemporalConstraints());
assertNotNull(adapter.getVisibilityHandler());
final VisibilityHandler visibilityHandler = adapter.getVisibilityHandler();
assertTrue(visibilityHandler instanceof JsonFieldLevelVisibilityHandler);
assertEquals("strAttr", ((JsonFieldLevelVisibilityHandler) visibilityHandler).getVisibilityAttribute());
}
use of org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor in project geowave by locationtech.
the class FeatureDataAdapter method newRowBuilder.
@Override
public RowBuilder<SimpleFeature> newRowBuilder(final FieldDescriptor<?>[] outputFieldDescriptors) {
CoordinateReferenceSystem outputCRS = featureType.getCoordinateReferenceSystem();
final String defaultGeometryField = featureType.getGeometryDescriptor().getLocalName();
for (final FieldDescriptor<?> field : outputFieldDescriptors) {
if (field.fieldName().equals(defaultGeometryField) && (field instanceof SpatialFieldDescriptor)) {
outputCRS = ((SpatialFieldDescriptor<?>) field).crs();
break;
}
}
CoordinateReferenceSystem persistedCRS = featureType.getCoordinateReferenceSystem();
if (outputCRS == null) {
outputCRS = GeometryUtils.getDefaultCRS();
}
if (persistedCRS == null) {
persistedCRS = GeometryUtils.getDefaultCRS();
}
final SimpleFeatureType reprojectedFeatureType;
if (outputCRS.equals(persistedCRS)) {
reprojectedFeatureType = SimpleFeatureTypeBuilder.retype(featureType, persistedCRS);
} else {
reprojectedFeatureType = SimpleFeatureTypeBuilder.retype(featureType, outputCRS);
}
return new FeatureRowBuilder(reprojectedFeatureType);
}
use of org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor in project geowave by locationtech.
the class SpatialTemporalAnnotationsTest method testSpatialTemporalAnnotations.
@Test
public void testSpatialTemporalAnnotations() throws NoSuchAuthorityCodeException, FactoryException {
BasicDataTypeAdapter<TestType> adapter = BasicDataTypeAdapter.newAdapter("myType", TestType.class, "name");
final CoordinateReferenceSystem testCRS = CRS.decode(TEST_CRS_CODE);
assertEquals("myType", adapter.getTypeName());
assertEquals(TestType.class, adapter.getDataClass());
assertEquals(3, adapter.getFieldDescriptors().length);
assertNotNull(adapter.getFieldDescriptor("name"));
assertTrue(String.class.isAssignableFrom(adapter.getFieldDescriptor("name").bindingClass()));
SpatialFieldDescriptor<?> geometryDescriptor = (SpatialFieldDescriptor<?>) adapter.getFieldDescriptor("geometry");
assertNotNull(geometryDescriptor);
assertTrue(Geometry.class.isAssignableFrom(geometryDescriptor.bindingClass()));
assertTrue(geometryDescriptor.indexHints().contains(SpatialField.LATITUDE_DIMENSION_HINT));
assertTrue(geometryDescriptor.indexHints().contains(SpatialField.LONGITUDE_DIMENSION_HINT));
assertEquals(testCRS, geometryDescriptor.crs());
assertNotNull(adapter.getFieldDescriptor("date"));
assertTrue(Date.class.isAssignableFrom(adapter.getFieldDescriptor("date").bindingClass()));
assertTrue(adapter.getFieldDescriptor("date").indexHints().contains(TimeField.TIME_DIMENSION_HINT));
final byte[] adapterBytes = PersistenceUtils.toBinary(adapter);
adapter = (BasicDataTypeAdapter) PersistenceUtils.fromBinary(adapterBytes);
assertEquals("myType", adapter.getTypeName());
assertEquals(TestType.class, adapter.getDataClass());
assertEquals(3, adapter.getFieldDescriptors().length);
assertNotNull(adapter.getFieldDescriptor("name"));
assertTrue(String.class.isAssignableFrom(adapter.getFieldDescriptor("name").bindingClass()));
geometryDescriptor = (SpatialFieldDescriptor<?>) adapter.getFieldDescriptor("geometry");
assertTrue(Geometry.class.isAssignableFrom(geometryDescriptor.bindingClass()));
assertTrue(geometryDescriptor.indexHints().contains(SpatialField.LATITUDE_DIMENSION_HINT));
assertTrue(geometryDescriptor.indexHints().contains(SpatialField.LONGITUDE_DIMENSION_HINT));
assertEquals(testCRS, geometryDescriptor.crs());
assertNotNull(adapter.getFieldDescriptor("date"));
assertTrue(Date.class.isAssignableFrom(adapter.getFieldDescriptor("date").bindingClass()));
assertTrue(adapter.getFieldDescriptor("date").indexHints().contains(TimeField.TIME_DIMENSION_HINT));
final TestType testEntry = new TestType(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(5, 5)), new Date(100), "id1");
assertEquals("id1", adapter.getFieldValue(testEntry, "name"));
assertTrue(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(5, 5)).equalsExact((Geometry) adapter.getFieldValue(testEntry, "geometry")));
assertEquals(new Date(100), adapter.getFieldValue(testEntry, "date"));
final Object[] fields = new Object[3];
for (int i = 0; i < fields.length; i++) {
switch(adapter.getFieldDescriptors()[i].fieldName()) {
case "name":
fields[i] = "id1";
break;
case "geometry":
fields[i] = GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(10, 10));
break;
case "date":
fields[i] = new Date(500);
break;
}
}
final TestType builtEntry = adapter.buildObject("id1", fields);
assertEquals("id1", adapter.getFieldValue(builtEntry, "name"));
assertTrue(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(10, 10)).equalsExact((Geometry) adapter.getFieldValue(builtEntry, "geometry")));
assertEquals(new Date(500), adapter.getFieldValue(builtEntry, "date"));
}
use of org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor in project geowave by locationtech.
the class SpatialAttributeIndexProvider method buildIndex.
@Override
public AttributeIndex buildIndex(final String indexName, final DataTypeAdapter<?> adapter, final FieldDescriptor<?> fieldDescriptor) {
final SpatialOptions options = new SpatialOptions();
if (fieldDescriptor instanceof SpatialFieldDescriptor) {
options.setCrs(GeometryUtils.getCrsCode(((SpatialFieldDescriptor<?>) fieldDescriptor).crs()));
}
final Index index = SpatialDimensionalityTypeProvider.createIndexFromOptions(options);
return new AttributeIndexImpl(index.getIndexStrategy(), index.getIndexModel(), indexName, fieldDescriptor.fieldName());
}
Aggregations