Search in sources :

Example 1 with CustomCRSSpatialField

use of org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField in project geowave by locationtech.

the class SpatialDimensionalityTypeProvider method createIndexFromOptions.

public static Index createIndexFromOptions(final SpatialOptions options) {
    NumericDimensionDefinition[] dimensions;
    boolean isDefaultCRS;
    String crsCode = null;
    NumericDimensionField<?>[] fields = null;
    NumericDimensionField<?>[] fields_temporal = null;
    final Integer geometryPrecision = options.getGeometryPrecision();
    if ((options.crs == null) || options.crs.isEmpty() || options.crs.equalsIgnoreCase(GeometryUtils.DEFAULT_CRS_STR)) {
        dimensions = SPATIAL_DIMENSIONS;
        fields = getSpatialFields(geometryPrecision);
        isDefaultCRS = true;
        crsCode = "EPSG:4326";
    } else {
        final CoordinateReferenceSystem crs = GeometryUtils.decodeCRS(options.crs);
        final CoordinateSystem cs = crs.getCoordinateSystem();
        isDefaultCRS = false;
        crsCode = options.crs;
        dimensions = new NumericDimensionDefinition[cs.getDimension()];
        if (options.storeTime) {
            fields_temporal = new NumericDimensionField[dimensions.length + 1];
            for (int d = 0; d < dimensions.length; d++) {
                final CoordinateSystemAxis csa = cs.getAxis(d);
                if (!isUnbounded(csa)) {
                    dimensions[d] = new CustomCRSBoundedSpatialDimension((byte) d, csa.getMinimumValue(), csa.getMaximumValue());
                    fields_temporal[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimension) dimensions[d], geometryPrecision, crs);
                } else {
                    dimensions[d] = new CustomCRSUnboundedSpatialDimension(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                    fields_temporal[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimension) dimensions[d], geometryPrecision, crs);
                }
            }
            fields_temporal[dimensions.length] = new TimeField(Unit.YEAR);
        } else {
            fields = new NumericDimensionField[dimensions.length];
            for (int d = 0; d < dimensions.length; d++) {
                final CoordinateSystemAxis csa = cs.getAxis(d);
                if (!isUnbounded(csa)) {
                    if (d == 0) {
                        dimensions[d] = new CustomCRSBoundedSpatialDimensionX(csa.getMinimumValue(), csa.getMaximumValue());
                        fields[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimensionX) dimensions[d], geometryPrecision, crs);
                    }
                    if (d == 1) {
                        dimensions[d] = new CustomCRSBoundedSpatialDimensionY(csa.getMinimumValue(), csa.getMaximumValue());
                        fields[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimensionY) dimensions[d], geometryPrecision, crs);
                    }
                } else {
                    if (d == 0) {
                        dimensions[d] = new CustomCRSUnboundedSpatialDimensionX(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                        fields[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimensionX) dimensions[d], geometryPrecision, crs);
                    }
                    if (d == 1) {
                        dimensions[d] = new CustomCRSUnboundedSpatialDimensionY(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                        fields[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimensionY) dimensions[d], geometryPrecision, crs);
                    }
                }
            }
        }
    }
    BasicIndexModel indexModel = null;
    if (isDefaultCRS) {
        indexModel = new BasicIndexModel(options.storeTime ? getSpatialTemporalFields(geometryPrecision) : getSpatialFields(geometryPrecision));
    } else {
        indexModel = new CustomCrsIndexModel(options.storeTime ? fields_temporal : fields, crsCode);
    }
    return new CustomNameIndex(XZHierarchicalIndexFactory.createFullIncrementalTieredStrategy(dimensions, new int[] { // flexible enough to handle n-dimensions
    LONGITUDE_BITS, LATITUDE_BITS }, SFCType.HILBERT), indexModel, // TODO append CRS code to ID if its overridden
    isDefaultCRS ? (options.storeTime ? DEFAULT_SPATIAL_ID + "_TIME" : DEFAULT_SPATIAL_ID) : (options.storeTime ? DEFAULT_SPATIAL_ID + "_TIME" : DEFAULT_SPATIAL_ID) + "_" + crsCode.substring(crsCode.indexOf(":") + 1));
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) CustomCRSSpatialField(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) CustomCrsIndexModel(org.locationtech.geowave.core.geotime.store.dimension.CustomCrsIndexModel) TimeField(org.locationtech.geowave.core.geotime.store.dimension.TimeField) CustomCRSBoundedSpatialDimension(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimension) CustomCRSBoundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionX) CustomCRSBoundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionY) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CustomCRSUnboundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionY) CustomCRSUnboundedSpatialDimension(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimension) CustomCRSUnboundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionX)

Example 2 with CustomCRSSpatialField

use of org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField in project geowave by locationtech.

the class IndexOptimizationUtils method hasAtLeastSpatial.

public static boolean hasAtLeastSpatial(final Index index) {
    if ((index == null) || (index.getIndexModel() == null) || (index.getIndexModel().getDimensions() == null)) {
        return false;
    }
    boolean hasLatitude = false;
    boolean hasLongitude = false;
    for (final NumericDimensionField dimension : index.getIndexModel().getDimensions()) {
        if (dimension instanceof LatitudeField) {
            hasLatitude = true;
        }
        if (dimension instanceof LongitudeField) {
            hasLongitude = true;
        }
        if (dimension instanceof CustomCRSSpatialField) {
            if (((CustomCRSSpatialDimension) dimension.getBaseDefinition()).getAxis() == 0) {
                hasLongitude = true;
            } else {
                hasLatitude = true;
            }
        }
    }
    return hasLatitude && hasLongitude;
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) LatitudeField(org.locationtech.geowave.core.geotime.store.dimension.LatitudeField) LongitudeField(org.locationtech.geowave.core.geotime.store.dimension.LongitudeField) CustomCRSSpatialField(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField)

Example 3 with CustomCRSSpatialField

use of org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField in project geowave by locationtech.

the class MigrationTest method testLegacySpatialFields.

@Test
public void testLegacySpatialFields() throws NoSuchAuthorityCodeException, FactoryException {
    LegacyLatitudeField latitudeFullRange = new LegacyLatitudeField(4, false);
    byte[] fieldBytes = PersistenceUtils.toBinary(latitudeFullRange);
    latitudeFullRange = (LegacyLatitudeField) PersistenceUtils.fromBinary(fieldBytes);
    LatitudeField updatedLatitudeField = latitudeFullRange.getUpdatedField(null);
    assertEquals(GeometryUtils.getDefaultCRS(), updatedLatitudeField.getCRS());
    assertEquals(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME, updatedLatitudeField.getFieldName());
    assertEquals(180, updatedLatitudeField.getRange(), 0.0001);
    assertEquals(-90, updatedLatitudeField.getFullRange().getMin(), 0.0001);
    assertEquals(90, updatedLatitudeField.getFullRange().getMax(), 0.0001);
    assertEquals(4, (int) updatedLatitudeField.getGeometryPrecision());
    LegacyLatitudeField latitudeHalfRange = new LegacyLatitudeField(4, true);
    fieldBytes = PersistenceUtils.toBinary(latitudeHalfRange);
    latitudeHalfRange = (LegacyLatitudeField) PersistenceUtils.fromBinary(fieldBytes);
    updatedLatitudeField = latitudeHalfRange.getUpdatedField(null);
    assertEquals(GeometryUtils.getDefaultCRS(), updatedLatitudeField.getCRS());
    assertEquals(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME, updatedLatitudeField.getFieldName());
    assertEquals(360, updatedLatitudeField.getRange(), 0.0001);
    assertEquals(-180, updatedLatitudeField.getFullRange().getMin(), 0.0001);
    assertEquals(180, updatedLatitudeField.getFullRange().getMax(), 0.0001);
    assertEquals(4, (int) updatedLatitudeField.getGeometryPrecision());
    LegacyLongitudeField longitudeField = new LegacyLongitudeField(4);
    fieldBytes = PersistenceUtils.toBinary(longitudeField);
    longitudeField = (LegacyLongitudeField) PersistenceUtils.fromBinary(fieldBytes);
    final LongitudeField updatedLongitudeField = longitudeField.getUpdatedField(null);
    assertEquals(GeometryUtils.getDefaultCRS(), updatedLongitudeField.getCRS());
    assertEquals(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME, updatedLongitudeField.getFieldName());
    assertEquals(360, updatedLongitudeField.getRange(), 0.0001);
    assertEquals(-180, updatedLongitudeField.getFullRange().getMin(), 0.0001);
    assertEquals(180, updatedLongitudeField.getFullRange().getMax(), 0.0001);
    assertEquals(4, (int) updatedLongitudeField.getGeometryPrecision());
    final SpatialOptions options = new SpatialOptions();
    options.setCrs("EPSG:3257");
    options.setGeometryPrecision(4);
    final CoordinateReferenceSystem crs = CRS.decode("EPSG:3257", true);
    final Index index = SpatialDimensionalityTypeProvider.createIndexFromOptions(options);
    for (int i = 0; i < crs.getCoordinateSystem().getDimension(); i++) {
        final CoordinateSystemAxis csa = crs.getCoordinateSystem().getAxis(i);
        LegacyCustomCRSSpatialField customCRSField;
        if (i == 0) {
            customCRSField = new LegacyCustomCRSSpatialField(new CustomCRSBoundedSpatialDimensionX(csa.getMinimumValue(), csa.getMaximumValue()), 4);
        } else {
            customCRSField = new LegacyCustomCRSSpatialField(new CustomCRSBoundedSpatialDimensionY(csa.getMinimumValue(), csa.getMaximumValue()), 4);
        }
        fieldBytes = PersistenceUtils.toBinary(customCRSField);
        customCRSField = (LegacyCustomCRSSpatialField) PersistenceUtils.fromBinary(fieldBytes);
        final CustomCRSSpatialField updatedCRSField = customCRSField.getUpdatedField(index);
        assertEquals(crs, updatedCRSField.getCRS());
        assertEquals(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME, updatedCRSField.getFieldName());
        assertEquals(csa.getMaximumValue() - csa.getMinimumValue(), updatedCRSField.getRange(), 0.0001);
        assertEquals(csa.getMinimumValue(), updatedCRSField.getFullRange().getMin(), 0.0001);
        assertEquals(csa.getMaximumValue(), updatedCRSField.getFullRange().getMax(), 0.0001);
        assertEquals(4, (int) updatedCRSField.getGeometryPrecision());
        if (i == 0) {
            assertTrue(CustomCRSBoundedSpatialDimensionX.class.isAssignableFrom(updatedCRSField.getBaseDefinition().getClass()));
        } else {
            assertTrue(CustomCRSBoundedSpatialDimensionY.class.isAssignableFrom(updatedCRSField.getBaseDefinition().getClass()));
        }
    }
}
Also used : LegacyLatitudeField(org.locationtech.geowave.migration.legacy.core.geotime.LegacyLatitudeField) LegacyLongitudeField(org.locationtech.geowave.migration.legacy.core.geotime.LegacyLongitudeField) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) Index(org.locationtech.geowave.core.store.api.Index) LegacyLongitudeField(org.locationtech.geowave.migration.legacy.core.geotime.LegacyLongitudeField) LongitudeField(org.locationtech.geowave.core.geotime.store.dimension.LongitudeField) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) CustomCRSSpatialField(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField) LegacyCustomCRSSpatialField(org.locationtech.geowave.migration.legacy.core.geotime.LegacyCustomCRSSpatialField) Point(org.locationtech.jts.geom.Point) LegacyLatitudeField(org.locationtech.geowave.migration.legacy.core.geotime.LegacyLatitudeField) LatitudeField(org.locationtech.geowave.core.geotime.store.dimension.LatitudeField) CustomCRSBoundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionX) CustomCRSBoundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionY) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) LegacyCustomCRSSpatialField(org.locationtech.geowave.migration.legacy.core.geotime.LegacyCustomCRSSpatialField) Test(org.junit.Test)

Example 4 with CustomCRSSpatialField

use of org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField in project geowave by locationtech.

the class SpatialTemporalDimensionalityTypeProvider method createIndexFromOptions.

public static Index createIndexFromOptions(final SpatialTemporalOptions options) {
    NumericDimensionDefinition[] dimensions;
    NumericDimensionField<?>[] fields = null;
    CoordinateReferenceSystem crs = null;
    boolean isDefaultCRS;
    String crsCode = null;
    final Integer geometryPrecision = options.getGeometryPrecision();
    if ((options.crs == null) || options.crs.isEmpty() || options.crs.equalsIgnoreCase(GeometryUtils.DEFAULT_CRS_STR)) {
        dimensions = SPATIAL_TEMPORAL_DIMENSIONS;
        fields = getSpatialTemporalFields(geometryPrecision);
        isDefaultCRS = true;
        crsCode = "EPSG:4326";
    } else {
        crs = GeometryUtils.decodeCRS(options.crs);
        final CoordinateSystem cs = crs.getCoordinateSystem();
        isDefaultCRS = false;
        crsCode = options.crs;
        dimensions = new NumericDimensionDefinition[cs.getDimension() + 1];
        fields = new NumericDimensionField[dimensions.length];
        for (int d = 0; d < (dimensions.length - 1); d++) {
            final CoordinateSystemAxis csa = cs.getAxis(d);
            if (!isUnbounded(csa)) {
                if (d == 0) {
                    dimensions[d] = new CustomCRSBoundedSpatialDimensionX(csa.getMinimumValue(), csa.getMaximumValue());
                    fields[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimensionX) dimensions[d], geometryPrecision, crs);
                }
                if (d == 1) {
                    dimensions[d] = new CustomCRSBoundedSpatialDimensionY(csa.getMinimumValue(), csa.getMaximumValue());
                    fields[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimensionY) dimensions[d], geometryPrecision, crs);
                }
            } else {
                if (d == 0) {
                    dimensions[d] = new CustomCRSUnboundedSpatialDimensionX(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                    fields[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimensionX) dimensions[d], geometryPrecision, crs);
                }
                if (d == 1) {
                    dimensions[d] = new CustomCRSUnboundedSpatialDimensionY(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                    fields[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimensionY) dimensions[d], geometryPrecision, crs);
                }
            }
        }
        dimensions[dimensions.length - 1] = new TimeDefinition(options.periodicity);
        fields[dimensions.length - 1] = new TimeField(options.periodicity);
    }
    BasicIndexModel indexModel = null;
    if (isDefaultCRS) {
        indexModel = new BasicIndexModel(fields);
    } else {
        indexModel = new CustomCrsIndexModel(fields, crsCode);
    }
    String combinedArrayID;
    if (isDefaultCRS) {
        combinedArrayID = DEFAULT_SPATIAL_TEMPORAL_ID_STR + "_" + options.bias + "_" + options.periodicity;
    } else {
        combinedArrayID = DEFAULT_SPATIAL_TEMPORAL_ID_STR + "_" + (crsCode.substring(crsCode.indexOf(":") + 1)) + "_" + options.bias + "_" + options.periodicity;
    }
    final String combinedId = combinedArrayID;
    return new CustomNameIndex(XZHierarchicalIndexFactory.createFullIncrementalTieredStrategy(dimensions, new int[] { options.bias.getSpatialPrecision(), options.bias.getSpatialPrecision(), options.bias.getTemporalPrecision() }, SFCType.HILBERT, options.maxDuplicates), indexModel, combinedId);
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) CustomCRSSpatialField(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) CustomCrsIndexModel(org.locationtech.geowave.core.geotime.store.dimension.CustomCrsIndexModel) TimeField(org.locationtech.geowave.core.geotime.store.dimension.TimeField) CustomCRSBoundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionX) CustomCRSBoundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionY) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CustomCRSUnboundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionY) TimeDefinition(org.locationtech.geowave.core.geotime.index.dimension.TimeDefinition) CustomCRSUnboundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionX)

Aggregations

CustomCRSSpatialField (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField)4 CustomCRSBoundedSpatialDimensionX (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionX)3 CustomCRSBoundedSpatialDimensionY (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionY)3 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)3 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)3 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)3 CustomCRSUnboundedSpatialDimensionX (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionX)2 CustomCRSUnboundedSpatialDimensionY (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionY)2 CustomCrsIndexModel (org.locationtech.geowave.core.geotime.store.dimension.CustomCrsIndexModel)2 LatitudeField (org.locationtech.geowave.core.geotime.store.dimension.LatitudeField)2 LongitudeField (org.locationtech.geowave.core.geotime.store.dimension.LongitudeField)2 TimeField (org.locationtech.geowave.core.geotime.store.dimension.TimeField)2 NumericDimensionDefinition (org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition)2 BasicIndexModel (org.locationtech.geowave.core.store.index.BasicIndexModel)2 CustomNameIndex (org.locationtech.geowave.core.store.index.CustomNameIndex)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 Test (org.junit.Test)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 TimeDefinition (org.locationtech.geowave.core.geotime.index.dimension.TimeDefinition)1 CustomCRSBoundedSpatialDimension (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimension)1