Search in sources :

Example 1 with SpatialFieldDescriptor

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());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) Persistable(org.locationtech.geowave.core.index.persist.Persistable) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Point(org.locationtech.jts.geom.Point) Date(java.util.Date) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) JsonFieldLevelVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler) JsonFieldLevelVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler) TemporalFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptor) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) Test(org.junit.Test)

Example 2 with SpatialFieldDescriptor

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);
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 3 with SpatialFieldDescriptor

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"));
}
Also used : Date(java.util.Date) Geometry(org.locationtech.jts.geom.Geometry) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 4 with SpatialFieldDescriptor

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());
}
Also used : AttributeIndexImpl(org.locationtech.geowave.core.store.index.AttributeIndexImpl) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor) Index(org.locationtech.geowave.core.store.api.Index) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex)

Aggregations

SpatialFieldDescriptor (org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor)4 Date (java.util.Date)2 Test (org.junit.Test)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 AttributeTypeBuilder (org.geotools.feature.AttributeTypeBuilder)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)1 TemporalFieldDescriptor (org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptor)1 Persistable (org.locationtech.geowave.core.index.persist.Persistable)1 AttributeIndex (org.locationtech.geowave.core.store.api.AttributeIndex)1 Index (org.locationtech.geowave.core.store.api.Index)1 VisibilityHandler (org.locationtech.geowave.core.store.api.VisibilityHandler)1 JsonFieldLevelVisibilityHandler (org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler)1 AttributeIndexImpl (org.locationtech.geowave.core.store.index.AttributeIndexImpl)1 LegacyFeatureDataAdapter (org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Geometry (org.locationtech.jts.geom.Geometry)1 Point (org.locationtech.jts.geom.Point)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1