@Override public int length( Object value ) { return 2 * Integer.BYTES + ((PointValue) value).coordinate().length * Double.BYTES; }
public static PointValue maxPointValue( PointValue reference ) { double[] coordinates = new double[reference.coordinate().length]; Arrays.fill( coordinates, Double.MAX_VALUE ); return pointValue( reference.getCoordinateReferenceSystem(), coordinates ); }
public static PointValue minPointValue( PointValue reference ) { double[] coordinates = new double[reference.coordinate().length]; Arrays.fill( coordinates, -Double.MAX_VALUE ); return pointValue( reference.getCoordinateReferenceSystem(), coordinates ); }
double[] c1Coord = p1.coordinate(); double[] c2Coord = p2.coordinate(); double[] c1 = new double[]{toRadians( c1Coord[0] ), toRadians( c1Coord[1] )}; double[] c2 = new double[]{toRadians( c2Coord[0] ), toRadians( c2Coord[1] )}; double avgHeight = (p1.coordinate()[2] + p2.coordinate()[2]) / 2; double distance2D = (EARTH_RADIUS_METERS + avgHeight) * greatCircleDistance;
public static byte[] encodePointArray( PointValue[] points ) { int dimension = points[0].coordinate().length; CoordinateReferenceSystem crs = points[0].getCoordinateReferenceSystem(); for ( int i = 1; i < points.length; i++ ) { if ( dimension != points[i].coordinate().length ) { throw new IllegalArgumentException( "Attempting to store array of points with inconsistent dimension. Point " + i + " has a different dimension." ); } if ( !crs.equals( points[i].getCoordinateReferenceSystem() ) ) { throw new IllegalArgumentException( "Attempting to store array of points with inconsistent CRS. Point " + i + " has a different CRS." ); } } double[] data = new double[points.length * dimension]; for ( int i = 0; i < data.length; i++ ) { data[i] = points[i / dimension].coordinate()[i % dimension]; } GeometryHeader geometryHeader = new GeometryHeader( GeometryType.GEOMETRY_POINT.gtype, dimension, crs ); byte[] bytes = DynamicArrayStore.encodeFromNumbers( data, DynamicArrayStore.GEOMETRY_HEADER_SIZE ); geometryHeader.writeArrayHeaderTo( bytes ); return bytes; }
@Override public double distance( PointValue p1, PointValue p2 ) { assert p1.getCoordinateReferenceSystem().getDimension() == dimension; assert p2.getCoordinateReferenceSystem().getDimension() == dimension; return pythagoras( p1.coordinate(), p2.coordinate() ); }
double lat = center.coordinate()[1]; double lon = center.coordinate()[0];
public static <E extends Exception> void writeTo( ValueWriter<E> writer, Point[] values ) throws E { writer.beginArray( values.length, ValueWriter.ArrayType.POINT ); for ( Point x : values ) { PointValue value = Values.point( x ); writer.writePoint( value.getCoordinateReferenceSystem(), value.coordinate() ); } writer.endArray(); } }
private void assertDerivedValue( Long targetDerivedValue, PointValue... values ) { for ( PointValue value : values ) { Long derivedValueForValue = curve.derivedValueFor( value.coordinate() ); assertEquals( targetDerivedValue, derivedValueForValue, "expected random value to belong to same tile as center point" ); } }
@Override public List<Pair<PointValue,PointValue>> boundingBox( PointValue center, double distance ) { assert center.getCoordinateReferenceSystem().getDimension() == dimension; double[] coordinates = center.coordinate(); double[] min = new double[dimension]; double[] max = new double[dimension]; for ( int i = 0; i < dimension; i++ ) { min[i] = coordinates[i] - distance; max[i] = coordinates[i] + distance; } CoordinateReferenceSystem crs = center.getCoordinateReferenceSystem(); return Collections.singletonList( Pair.of( Values.pointValue( crs, min ), Values.pointValue( crs, max ) ) ); } }
@Override public void write( Object value, FlushableChannel into ) throws IOException { PointValue pointValue = (PointValue) value; // using code is not a future-proof solution like the one we have in the PropertyStore. // But then again, this is not used from procution code. into.putInt( pointValue.getCoordinateReferenceSystem().getCode() ); double[] coordinate = pointValue.coordinate(); into.putInt( coordinate.length ); for ( double c : coordinate ) { into.putDouble( c ); } } } );
DoubleValue getNthCoordinate( int n, String fieldName, boolean onlyGeographic ) { if ( onlyGeographic && !this.getCoordinateReferenceSystem().isGeographic() ) { throw new InvalidValuesArgumentException( "Field: " + fieldName + " is not available on cartesian point: " + this ); } else if ( n >= this.coordinate().length ) { throw new InvalidValuesArgumentException( "Field: " + fieldName + " is not available on point: " + this ); } else { return Values.doubleValue( coordinate[n] ); } }
private Pair<PointValue,PointValue> boundingBoxOf( double minLon, double maxLon, double minLat, double maxLat, PointValue center, double distance ) { CoordinateReferenceSystem crs = center.getCoordinateReferenceSystem(); int dimension = center.getCoordinateReferenceSystem().getDimension(); double[] min = new double[dimension]; double[] max = new double[dimension]; min[0] = minLon; min[1] = minLat; max[0] = maxLon; max[1] = maxLat; if ( dimension > 2 ) { double[] coordinates = center.coordinate(); for ( int i = 2; i < dimension; i++ ) { min[i] = coordinates[i] - distance; max[i] = coordinates[i] + distance; } } return Pair.of( Values.pointValue( crs, min ), Values.pointValue( crs, max ) ); } }
client.initialize( descriptor, multiProgressor, query, IndexOrder.NONE, false ); SpaceFillingCurve curve = spatial.getSpaceFillingCurve(); double[] from = rangePredicate.from() == null ? null : rangePredicate.from().coordinate(); double[] to = rangePredicate.to() == null ? null : rangePredicate.to().coordinate(); List<SpaceFillingCurve.LongRange> ranges = curve.getTilesIntersectingEnvelope( from, to, configuration ); for ( SpaceFillingCurve.LongRange range : ranges )
private void assertPointArrayHasCorrectFormat( PointValue[] array, int numberOfBitsUsedForDoubles ) { Collection<DynamicRecord> records = new ArrayList<>(); arrayStore.allocateRecords( records, array ); Pair<byte[],byte[]> loaded = loadArray( records ); assertGeometryHeader( loaded.first(), GeometryType.GEOMETRY_POINT.getGtype(), 2, array[0].getCoordinateReferenceSystem().getTable().getTableId(), array[0].getCoordinateReferenceSystem().getCode() ); final int dimension = array[0].coordinate().length; double[] pointDoubles = new double[array.length * dimension]; for ( int i = 0; i < pointDoubles.length; i++ ) { pointDoubles[i] = array[i / dimension].coordinate()[i % dimension]; } byte[] doubleHeader = Arrays.copyOf( loaded.other(), DynamicArrayStore.NUMBER_HEADER_SIZE ); byte[] doubleBody = Arrays.copyOfRange( loaded.other(), DynamicArrayStore.NUMBER_HEADER_SIZE, loaded.other().length ); assertNumericArrayHeaderAndContent( pointDoubles, PropertyType.DOUBLE, numberOfBitsUsedForDoubles, Pair.of( doubleHeader, doubleBody ) ); }
double[] from = geometryRangePredicate.from() == null ? null : geometryRangePredicate.from().coordinate(); double[] to = geometryRangePredicate.to() == null ? null : geometryRangePredicate.to().coordinate(); CoordinateReferenceSystem crs = geometryRangePredicate.crs(); SpaceFillingCurve curve = spaceFillingCurveSettings.forCrs( crs, false );
Long derivedValueForCenterPoint = curve.derivedValueFor( origin.coordinate() ); double[] centerPoint = curve.centerPointFor( derivedValueForCenterPoint ); double xWidthMultiplier = curve.getTileWidth( 0, curve.getMaxLevel() ) / 2;
Long derivedValueForCenterPoint = curve.derivedValueFor( origin.coordinate() ); double[] centerPoint = curve.centerPointFor( derivedValueForCenterPoint ); double xWidthMultiplier = curve.getTileWidth( 0, curve.getMaxLevel() ) / 2;
@Test void comparePointsMustOnlyReturnZeroForEqualPoints() { PointValue firstPoint = random.randomValues().nextPointValue(); PointValue equalPoint = Values.point( firstPoint ); CoordinateReferenceSystem crs = firstPoint.getCoordinateReferenceSystem(); SpaceFillingCurve curve = noSpecificIndexSettings.forCrs( crs, false ); Long spaceFillingCurveValue = curve.derivedValueFor( firstPoint.coordinate() ); PointValue centerPoint = Values.pointValue( crs, curve.centerPointFor( spaceFillingCurveValue ) ); GenericKey firstKey = newKeyState(); firstKey.writeValue( firstPoint, NEUTRAL ); GenericKey equalKey = newKeyState(); equalKey.writeValue( equalPoint, NEUTRAL ); GenericKey centerKey = newKeyState(); centerKey.writeValue( centerPoint, NEUTRAL ); GenericKey noCoordsKey = newKeyState(); noCoordsKey.writeValue( equalPoint, NEUTRAL ); GeometryType.setNoCoordinates( noCoordsKey ); assertEquals( 0, firstKey.compareValueTo( equalKey ), "expected keys to be equal" ); assertEquals( firstPoint.compareTo( centerPoint ) != 0, firstKey.compareValueTo( centerKey ) != 0, "expected keys to be equal if and only if source points are equal" ); assertEquals( 0, firstKey.compareValueTo( noCoordsKey ), "expected keys to be equal" ); }
@Test void comparePointArraysMustOnlyReturnZeroForEqualArrays() { PointArray firstArray = random.randomValues().nextPointArray(); PointValue[] sourcePointValues = firstArray.asObjectCopy(); PointArray equalArray = Values.pointArray( sourcePointValues ); PointValue[] centerPointValues = new PointValue[sourcePointValues.length]; for ( int i = 0; i < sourcePointValues.length; i++ ) { PointValue sourcePointValue = sourcePointValues[i]; CoordinateReferenceSystem crs = sourcePointValue.getCoordinateReferenceSystem(); SpaceFillingCurve curve = noSpecificIndexSettings.forCrs( crs, false ); Long spaceFillingCurveValue = curve.derivedValueFor( sourcePointValue.coordinate() ); centerPointValues[i] = Values.pointValue( crs, curve.centerPointFor( spaceFillingCurveValue ) ); } PointArray centerArray = Values.pointArray( centerPointValues ); GenericKey firstKey = newKeyState(); firstKey.writeValue( firstArray, NEUTRAL ); GenericKey equalKey = newKeyState(); equalKey.writeValue( equalArray, NEUTRAL ); GenericKey centerKey = newKeyState(); centerKey.writeValue( centerArray, NEUTRAL ); GenericKey noCoordsKey = newKeyState(); noCoordsKey.writeValue( equalArray, NEUTRAL ); GeometryType.setNoCoordinates( noCoordsKey ); assertEquals( 0, firstKey.compareValueTo( equalKey ), "expected keys to be equal" ); assertEquals( firstArray.compareToSequence( centerArray, AnyValues.COMPARATOR ) != 0, firstKey.compareValueTo( centerKey ) != 0, "expected keys to be equal if and only if source points are equal" ); assertEquals( 0, firstKey.compareValueTo( noCoordsKey ), "expected keys to be equal" ); }