private GeometryHeader( int geometryType, int dimension, int crsTableId, int crsCode ) { this( geometryType, dimension, CoordinateReferenceSystem.get( crsTableId, crsCode ) ); }
private static PointValue readPoint( ByteBuffer chunk, int offset ) { final int crsCode = chunk.getInt( offset ); offset += Integer.BYTES; final CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( crsCode ); final double[] coordinate = new double[crs.getDimension()]; for ( int i = 0; i < coordinate.length; i++ ) { coordinate[i] = chunk.getDouble( offset ); offset += Double.BYTES; } return pointValue( crs, coordinate ); }
@Override public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) { if ( !isArray ) { setType( Types.GEOMETRY ); updateCurve( crs.getTable().getTableId(), crs.getCode() ); Types.GEOMETRY.write( this, spaceFillingCurve.derivedValueFor( coordinate ), coordinate ); } else { if ( currentArrayOffset == 0 ) { updateCurve( crs.getTable().getTableId(), crs.getCode() ); } else if ( this.long1 != crs.getTable().getTableId() || this.long2 != crs.getCode() ) { throw new IllegalStateException( format( "Tried to assign a geometry array containing different coordinate reference systems, first:%s, violating:%s at array position:%d", CoordinateReferenceSystem.get( (int) long1, (int) long2 ), crs, currentArrayOffset ) ); } Types.GEOMETRY_ARRAY.write( this, currentArrayOffset++, spaceFillingCurve.derivedValueFor( coordinate ), coordinate ); } }
public static CoordinateReferenceSystem crs( CRS crs ) { return CoordinateReferenceSystem.get( crs ); }
public static CoordinateReferenceSystem get( CRS crs ) { Objects.requireNonNull( crs ); return get( crs.getHref() ); }
/** * Gets {@link SpaceFillingCurve} for a particular coordinate reference system's crsTableId and code point. * * @param crsTableId table id of the {@link CoordinateReferenceSystem}. * @param crsCodePoint code of the {@link CoordinateReferenceSystem}. * @param assignToIndexIfNotYetAssigned whether or not to make a snapshot of this index-specific setting if this is the * first time it's accessed for this index. It will then show up in {@link #visitIndexSpecificSettings(SettingVisitor)}. * @return the {@link SpaceFillingCurve} for the given coordinate reference system. */ public SpaceFillingCurve forCrs( int crsTableId, int crsCodePoint, boolean assignToIndexIfNotYetAssigned ) { CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( crsTableId, crsCodePoint ); return forCrs( crs, assignToIndexIfNotYetAssigned ); }
private void readNext( ByteBuffer headerBytes ) { int tableId = headerBytes.get() & 0xFF; int code = headerBytes.getInt(); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( tableId, code ); int maxLevels = headerBytes.getShort() & 0xFFFF; int dimensions = headerBytes.getShort() & 0xFFFF; double[] min = new double[dimensions]; double[] max = new double[dimensions]; for ( int i = 0; i < dimensions; i++ ) { min[i] = Double.longBitsToDouble( headerBytes.getLong() ); max[i] = Double.longBitsToDouble( headerBytes.getLong() ); } Envelope extents = new Envelope( min, max ); settings.put( crs, new SpaceFillingCurveSettings( dimensions, extents, maxLevels ) ); } }
private void addExistingFiles( List<SpatialFile> existing ) { File[] files = fs.listFiles( indexDirectory ); if ( files != null ) { for ( File file : files ) { String name = file.getName(); Matcher matcher = CRS_DIR_PATTERN.matcher( name ); if ( matcher.matches() ) { int tableId = Integer.parseInt( matcher.group( 1 ) ); int code = Integer.parseInt( matcher.group( 2 ) ); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( tableId, code ); existing.add( forCrs( crs ) ); } } } }
@Override Value asValue( GenericKey state ) { assertHasCoordinates( state ); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( (int) state.long1, (int) state.long2 ); return asValue( state, crs, 0 ); }
private static PointValue toPoint( Geometry geometry ) { List<Double> coordinate = geometry.getCoordinates().get( 0 ).getCoordinate(); double[] primitiveCoordinate = new double[coordinate.size()]; for ( int i = 0; i < coordinate.size(); i++ ) { primitiveCoordinate[i] = coordinate.get( i ); } return Values.pointValue( CoordinateReferenceSystem.get( geometry.getCRS() ), primitiveCoordinate ); }
@Test void shouldFindByTableAndCode() { assertThat( CoordinateReferenceSystem.get( 1, 4326 ), equalTo( CoordinateReferenceSystem.WGS84 ) ); assertThat( CoordinateReferenceSystem.get( 1, 4979 ), equalTo( CoordinateReferenceSystem.WGS84_3D ) ); assertThat( CoordinateReferenceSystem.get( 2, 7203 ), equalTo( CoordinateReferenceSystem.Cartesian ) ); assertThat( CoordinateReferenceSystem.get( 2, 9157 ), equalTo( CoordinateReferenceSystem.Cartesian_3D ) ); }
private static CoordinateReferenceSystem findSpecifiedCRS( PointBuilder fields ) { String crsValue = fields.crs; int sridValue = fields.srid; if ( crsValue != null && sridValue != -1 ) { throw new InvalidValuesArgumentException( "Cannot specify both CRS and SRID" ); } else if ( crsValue != null ) { return CoordinateReferenceSystem.byName( crsValue ); } else if ( sridValue != -1 ) { return CoordinateReferenceSystem.get( sridValue ); } else { return null; } }
private PointValue unpackPoint2D() throws IOException { int crsCode = unpackInteger(); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( crsCode ); double[] coordinates = {unpackDouble(), unpackDouble()}; return pointValue( crs, coordinates ); }
@Override public Object read( ReadableClosableChannel from ) throws IOException { int code = from.getInt(); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( code ); int length = from.getInt(); double[] coordinate = new double[length]; for ( int i = 0; i < length; i++ ) { coordinate[i] = from.getDouble(); } return Values.pointValue( crs, coordinate ); }
@Override Value asValue( GenericKey state ) { Point[] points = new Point[state.arrayLength]; if ( points.length > 0 ) { assertHasCoordinates( state ); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( (int) state.long1, (int) state.long2 ); int dimensions = dimensions( state ); for ( int i = 0; i < points.length; i++ ) { points[i] = GeometryType.asValue( state, crs, dimensions * i ); } } return Values.pointArray( points ); }
private PointValue unpackPoint3D() throws IOException { int crsCode = unpackInteger(); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( crsCode ); double[] coordinates = {unpackDouble(), unpackDouble(), unpackDouble()}; return pointValue( crs, coordinates ); }
public static Value decode( long[] valueBlocks, int offset ) { long firstBlock = valueBlocks[offset]; int gtype = getGeometryType( firstBlock ); int dimension = getDimension( firstBlock ); if ( isFloatPrecision( firstBlock ) ) { throw new UnsupportedOperationException( "Float precision is unsupported in Geometry properties" ); } if ( dimension > GeometryType.getMaxSupportedDimensions() ) { throw new UnsupportedOperationException( "Points with more than " + GeometryType.getMaxSupportedDimensions() + " dimensions are not supported" ); } CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( getCRSTable( firstBlock ), getCRSCode( firstBlock ) ); return find( gtype ).decode( crs, dimension, valueBlocks, offset ); }
@Test void shouldFailToGetWithIncorrectCode() { InvalidValuesArgumentException exception = assertThrows( InvalidValuesArgumentException.class, () -> CoordinateReferenceSystem.get( 42 ) ); assertEquals( "Unknown coordinate reference system code: 42", exception.getMessage() ); }
@Override Value asValue( GenericKey state ) { assertHasCoordinates( state ); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( (int) state.long1, (int) state.long2 ); return asValue( state, crs, 0 ); }