Skip to content

Commit

Permalink
Follow pattern for number of longs in property block used by Points
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner authored and MishaDemianenko committed Nov 27, 2017
1 parent c92098d commit 6bde263
Showing 1 changed file with 14 additions and 5 deletions.
Expand Up @@ -76,7 +76,7 @@ public Value decode( CoordinateReferenceSystem crs, int dimension, long[] valueB
public int calculateNumberOfBlocksUsedForGeometry( long firstBlock )
{
int dimension = getDimension( firstBlock );
if ( dimension > 3 )
if ( dimension > GeometryType.getMaxSupportedDimensions() )
{
return PropertyType.BLOCKS_USED_FOR_BAD_TYPE_OR_ENCODING;
}
Expand Down Expand Up @@ -205,6 +205,11 @@ private static boolean isFloatPrecision( long firstBlock )
return ((firstBlock & PRECISION_MASK) >> 56) == 1;
}

private static int getMaxSupportedDimensions()
{
return PropertyType.getPayloadSizeLongs() - 1;
}

public static int calculateNumberOfBlocksUsed( long firstBlock )
{
GeometryType geometryType = find( getGeometryType( firstBlock ) );
Expand Down Expand Up @@ -252,20 +257,24 @@ public static Value decode( long[] valueBlocks, int offset )
{
throw new UnsupportedOperationException( "Float precision is unsupported in Geometry properties" );
}
if ( dimension > 3 )
if ( dimension > GeometryType.getMaxSupportedDimensions() )
{
throw new UnsupportedOperationException( "Points with more than 3 dimensions are not supported" );
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 );
}

public static long[] encodePoint( int keyId, CoordinateReferenceSystem crs, double[] coordinate )
{
if ( coordinate.length > 3 )
if ( coordinate.length > GeometryType.getMaxSupportedDimensions() )
{
// One property block can only contains at most 4x8 byte parts, one for header and 3 for coordinates
throw new UnsupportedOperationException( "Points with more than 3 dimensions are not supported" );
throw new UnsupportedOperationException(
"Points with more than " + GeometryType.getMaxSupportedDimensions() +
" dimensions are not supported" );
}

int idBits = StandardFormatSettings.PROPERTY_TOKEN_MAXIMUM_ID_BITS;
Expand Down

0 comments on commit 6bde263

Please sign in to comment.