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 java.lang.Object implements S2Coder<S2ShapeIndex>
An encoder/decoder ofS2ShapeIndex
s.Values from the
S2ShapeIndex
returned bydecode(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 thanS2ShapeIndex
, but uses dramatically less memory when accessing only a few cells of the index.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
S2ShapeIndexCoder.EncodedS2ShapeIndex
Represents an encodedS2ShapeIndex
.
-
Field Summary
Fields Modifier and Type Field Description static S2ShapeIndexCoder
INSTANCE
An instance of aS2ShapeIndexCoder
which can encode anS2ShapeIndex
but will throw anIllegalArgumentException
if used to decode anS2ShapeIndex
.private java.util.List<S2Shape>
shapes
-
Constructor Summary
Constructors Constructor Description S2ShapeIndexCoder(java.util.List<S2Shape> shapes)
Constructs aS2ShapeIndexCoder
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description S2ShapeIndex
decode(PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor)
private static S2ShapeIndex.S2ClippedShape[]
decodeClippedShapes(java.util.List<S2Shape> shapes, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor)
private static int[]
decodeEdges(int numEdges, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor)
DecodesnumEdges
edge IDs of aS2ShapeIndex.S2ClippedShape
.void
encode(S2ShapeIndex value, java.io.OutputStream output)
Encodesvalue
tooutput
.private static void
encodeCell(S2ShapeIndex.Cell cell, com.google.common.collect.Multimap<S2Shape,java.lang.Integer> shapeIds, java.io.OutputStream output)
private static void
encodeEdges(S2ShapeIndex.S2ClippedShape clipped, java.io.OutputStream output)
Encodes the edge IDs of the givenS2ShapeIndex.S2ClippedShape
.
-
-
-
Field Detail
-
INSTANCE
public static final S2ShapeIndexCoder INSTANCE
An instance of aS2ShapeIndexCoder
which can encode anS2ShapeIndex
but will throw anIllegalArgumentException
if used to decode anS2ShapeIndex
.
-
shapes
private final java.util.List<S2Shape> shapes
-
-
Constructor Detail
-
S2ShapeIndexCoder
public S2ShapeIndexCoder(@Nullable java.util.List<S2Shape> shapes)
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 {@link VectorCoder#FAST_SHAPE#decode(Bytes, Cursor)}.
-
-
Method Detail
-
encode
public void encode(S2ShapeIndex value, java.io.OutputStream output) throws java.io.IOException
Description copied from interface:S2Coder
Encodesvalue
tooutput
.- Specified by:
encode
in interfaceS2Coder<S2ShapeIndex>
- Throws:
java.io.IOException
-
decode
public S2ShapeIndex decode(PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor)
Description copied from interface:S2Coder
Decodes a value of typeS2Coder
fromdata
starting atcursor.position
.cursor.position
is updated to the position of the first byte indata
following the encoded value.- Specified by:
decode
in interfaceS2Coder<S2ShapeIndex>
-
encodeCell
private static void encodeCell(S2ShapeIndex.Cell cell, com.google.common.collect.Multimap<S2Shape,java.lang.Integer> shapeIds, java.io.OutputStream output) throws java.io.IOException
- Throws:
java.io.IOException
-
encodeEdges
private static void encodeEdges(S2ShapeIndex.S2ClippedShape clipped, java.io.OutputStream output) throws java.io.IOException
Encodes the edge IDs of the givenS2ShapeIndex.S2ClippedShape
.- Throws:
java.io.IOException
-
decodeEdges
private static int[] decodeEdges(int numEdges, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor)
DecodesnumEdges
edge IDs of aS2ShapeIndex.S2ClippedShape
.
-
decodeClippedShapes
private static S2ShapeIndex.S2ClippedShape[] decodeClippedShapes(java.util.List<S2Shape> shapes, PrimitiveArrays.Bytes data, PrimitiveArrays.Cursor cursor)
Decodes an array ofS2ShapeIndex.S2ClippedShape
frominput
from the givenshapes
. TheS2ShapeIndex.S2ClippedShape
at index 0 will storecellId
.
-
-