use of org.locationtech.spatial4j.context.SpatialContextFactory in project janusgraph by JanusGraph.
the class SerializerTest method testLegacyNonJtsSerialization.
@Test
public void testLegacyNonJtsSerialization() throws Exception {
final SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = true;
final SpatialContext context = new SpatialContext(factory);
BinaryCodec binaryCodec = new BinaryCodec(context, factory);
Shape[] shapes = new Shape[] { context.getShapeFactory().pointXY(2.5, 0.5), context.getShapeFactory().rect(2.5, 3.5, 0.5, 1.5), context.getShapeFactory().circle(2.5, 0.5, DistanceUtils.dist2Degrees(5, DistanceUtils.EARTH_MEAN_RADIUS_KM)) };
DataOutput out = serialize.getDataOutput(128);
for (final Shape shape : shapes) {
// manually serialize with non-JTS codec
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(1);
try (DataOutputStream dataOutput = new DataOutputStream(outputStream)) {
binaryCodec.writeShape(dataOutput, shape);
dataOutput.flush();
}
outputStream.flush();
byte[] bytes = outputStream.toByteArray();
VariableLong.writePositive(out, bytes.length);
out.putBytes(bytes);
}
// deserialize with standard serializer
ReadBuffer b = out.getStaticBuffer().asReadBuffer();
assertEquals(Geoshape.geoshape(shapes[0]), serialize.readObjectNotNull(b, Geoshape.class));
assertEquals(Geoshape.geoshape(shapes[1]), serialize.readObjectNotNull(b, Geoshape.class));
assertEquals(Geoshape.geoshape(shapes[2]), serialize.readObjectNotNull(b, Geoshape.class));
}
Aggregations