Package com.google.common.geometry
Class S2ShapeIndexCoder
java.lang.Object
com.google.common.geometry.S2ShapeIndexCoder
- All Implemented Interfaces:
S2Coder<S2ShapeIndex>
@GwtIncompatible("S2LaxPolylineShape and S2LaxPolygonShape")
public class S2ShapeIndexCoder
extends Object
implements S2Coder<S2ShapeIndex>
An encoder/decoder of
S2ShapeIndexs.
Values from the S2ShapeIndex returned by decode(Bytes, Cursor) are decoded
only when they are accessed. This allows for very fast initialization and no additional memory
use beyond the encoded data, and a cache of the clipped shapes that have been accessed. When
accessing the entire index, this uses slightly more memory than S2ShapeIndex, but uses
dramatically less memory when accessing only a few cells of the index.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final S2ShapeIndexCoderAn instance of aS2ShapeIndexCoderwhich can encode anS2ShapeIndexbut will throw anIllegalArgumentExceptionif used to decode anS2ShapeIndex. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecode(PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor) private static S2ShapeIndex.S2ClippedShape[]decodeClippedShapes(List<S2Shape> shapes, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor) private static int[]decodeEdges(int numEdges, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor) DecodesnumEdgesedge IDs of aS2ShapeIndex.S2ClippedShape.voidencode(S2ShapeIndex value, OutputStream output) Encodesvaluetooutput.private static voidencodeCell(S2ShapeIndex.Cell cell, com.google.common.collect.Multimap<S2Shape, Integer> shapeIds, OutputStream output) private static voidencodeEdges(S2ShapeIndex.S2ClippedShape clipped, OutputStream output) Encodes the edge IDs of the givenS2ShapeIndex.S2ClippedShape.
-
Field Details
-
INSTANCE
An instance of aS2ShapeIndexCoderwhich can encode anS2ShapeIndexbut will throw anIllegalArgumentExceptionif used to decode anS2ShapeIndex. -
shapes
-
-
Constructor Details
-
S2ShapeIndexCoder
Constructs aS2ShapeIndexCoder.- Parameters:
shapes- the list of shapes, used only bydecode(com.google.common.geometry.PrimitiveArrays.Bytes, com.google.common.geometry.PrimitiveArrays.Cursor), commonly the result of invalid input: '{@link VectorCoder#FAST_SHAPE#decode(Bytes, Cursor)'}.
-
-
Method Details
-
encode
Description copied from interface:S2CoderEncodesvaluetooutput.- Specified by:
encodein interfaceS2Coder<S2ShapeIndex>- Throws:
IOException
-
decode
Description copied from interface:S2CoderDecodes a value of typeS2Coderfromdatastarting atcursor.position.cursor.positionis updated to the position of the first byte indatafollowing the encoded value.- Specified by:
decodein interfaceS2Coder<S2ShapeIndex>
-
encodeCell
private static void encodeCell(S2ShapeIndex.Cell cell, com.google.common.collect.Multimap<S2Shape, Integer> shapeIds, OutputStream output) throws IOException- Throws:
IOException
-
encodeEdges
private static void encodeEdges(S2ShapeIndex.S2ClippedShape clipped, OutputStream output) throws IOException Encodes the edge IDs of the givenS2ShapeIndex.S2ClippedShape.- Throws:
IOException
-
decodeEdges
private static int[] decodeEdges(int numEdges, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor) DecodesnumEdgesedge IDs of aS2ShapeIndex.S2ClippedShape. -
decodeClippedShapes
private static S2ShapeIndex.S2ClippedShape[] decodeClippedShapes(List<S2Shape> shapes, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor) Decodes an array ofS2ShapeIndex.S2ClippedShapefrominputfrom the givenshapes. TheS2ShapeIndex.S2ClippedShapeat index 0 will storecellId.
-