private static Slice geometryFromText(String wkt) { return serialize(OGCGeometry.fromText(wkt)); }
private static OGCGeometry geometryFromText(Slice input) { OGCGeometry geometry; try { geometry = OGCGeometry.fromText(input.toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKT: " + input.toStringUtf8(), e); } geometry.setSpatialReference(null); return geometry; }
@Test public void testCreateSingleStatePresent() { GeometryState state = factory.createSingleState(); state.setGeometry(OGCGeometry.fromText("POINT (1 2)")); assertEquals(OGCGeometry.fromText("POINT (1 2)"), state.getGeometry()); assertTrue(state.getEstimatedSize() > 0, String.format("Estimated memory size was %d", state.getEstimatedSize())); }
public void eval() { String wktText = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer); com.esri.core.geometry.ogc.OGCGeometry geom; geom = com.esri.core.geometry.ogc.OGCGeometry.fromText(wktText); java.nio.ByteBuffer pointBytes = geom.asBinary(); int outputSize = pointBytes.remaining(); buffer = out.buffer = buffer.reallocIfNeeded(outputSize); out.start = 0; out.end = outputSize; buffer.setBytes(0, pointBytes); } }
@Test public void testCreateGroupedStatePresent() { GeometryState state = factory.createGroupedState(); assertNull(state.getGeometry()); assertTrue(state instanceof GeometryStateFactory.GroupedGeometryState); GeometryStateFactory.GroupedGeometryState groupedState = (GeometryStateFactory.GroupedGeometryState) state; groupedState.setGroupId(1); assertNull(state.getGeometry()); groupedState.setGeometry(OGCGeometry.fromText("POINT (1 2)")); assertEquals(state.getGeometry(), OGCGeometry.fromText("POINT (1 2)")); groupedState.setGroupId(2); assertNull(state.getGeometry()); groupedState.setGeometry(OGCGeometry.fromText("POINT (3 4)")); assertEquals(state.getGeometry(), OGCGeometry.fromText("POINT (3 4)")); groupedState.setGroupId(1); assertNotNull(state.getGeometry()); } }
private static void testEsriSerialization(String wkt) { OGCGeometry expected = OGCGeometry.fromText(wkt); OGCGeometry actual = deserialize(serialize(expected)); assertGeometryEquals(actual, expected); }
public void eval() { int srid = sridParam.value; String wktText = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer); com.esri.core.geometry.ogc.OGCGeometry geom; geom = com.esri.core.geometry.ogc.OGCGeometry.fromText(wktText); geom.setSpatialReference(com.esri.core.geometry.SpatialReference.create(srid)); java.nio.ByteBuffer pointBytes = geom.asBinary(); int outputSize = pointBytes.remaining(); buffer = out.buffer = buffer.reallocIfNeeded(outputSize); out.start = 0; out.end = outputSize; buffer.setBytes(0, pointBytes); } }
point = fromText(POINT); pointSerialized = serialize(point); simpleMultipoint = fromText(MULTIPOINT); simpleMultipointSerialized = serialize(simpleMultipoint); complexMultipoint = fromText(readResource("complex-multipoint.txt")); complexMultipointSerialized = serialize(complexMultipoint); simpleLineString = fromText(LINESTRING); simpleLineStringSerialized = serialize(simpleLineString); complexLineString = fromText(readResource("complex-linestring.txt")); complexLineStringSerialized = serialize(complexLineString); simpleMultiLineString = fromText(MULTILINESTRING); simpleMultiLineStringSerialized = serialize(simpleMultiLineString); complexMultiLineString = fromText(readResource("complex-multilinestring.txt")); complexMultiLineStringSerialized = serialize(complexMultiLineString); simplePolygon = fromText(POLYGON); simplePolygonSerialized = serialize(simplePolygon); complexPolygon = fromText(readResource("complex-polygon.txt")); complexPolygonSerialized = serialize(complexPolygon); simpleMultiPolygon = fromText(MULTIPOLYGON); simpleMultiPolygonSerialized = serialize(simpleMultiPolygon); complexMultiPolygon = fromText(readResource("complex-multipolygon.txt")); complexMultiPolygonSerialized = serialize(complexMultiPolygon); simpleGeometryCollection = fromText(GEOMETRYCOLLECTION);
protected void assertAggregatedGeometries(String testDescription, String expectedWkt, String... wkts) { List<Slice> geometrySlices = Arrays.stream(wkts) .map(text -> text == null ? null : OGCGeometry.fromText(text)) .map(input -> input == null ? null : GeometrySerde.serialize(input)) .collect(Collectors.toList()); // Add a custom equality assertion because the resulting geometry may have // its constituent points in a different order BiFunction<Object, Object, Boolean> equalityFunction = (left, right) -> { if (left == null && right == null) { return true; } if (left == null || right == null) { return false; } OGCGeometry leftGeometry = OGCGeometry.fromText(left.toString()); OGCGeometry rightGeometry = OGCGeometry.fromText(right.toString()); // Check for equality by getting the difference return leftGeometry.difference(rightGeometry).isEmpty() && rightGeometry.difference(leftGeometry).isEmpty(); }; // Test in forward and reverse order to verify that ordering doesn't affect the output assertAggregation(function, equalityFunction, testDescription, new Page(BlockAssertions.createSlicesBlock(geometrySlices)), expectedWkt); Collections.reverse(geometrySlices); assertAggregation(function, equalityFunction, testDescription, new Page(BlockAssertions.createSlicesBlock(geometrySlices)), expectedWkt); }
private static void testJtsSerialization(String wkt) { Geometry jtsGeometry = createJtsGeometry(wkt); OGCGeometry esriGeometry = OGCGeometry.fromText(wkt); Slice jtsSerialized = JtsGeometrySerde.serialize(jtsGeometry); Slice esriSerialized = GeometrySerde.serialize(esriGeometry); assertEquals(jtsSerialized, esriSerialized); Geometry jtsDeserialized = JtsGeometrySerde.deserialize(jtsSerialized); assertGeometryEquals(jtsDeserialized, jtsGeometry); OGCGeometry esriDeserialized = GeometrySerde.deserialize(esriSerialized); assertGeometryEquals(esriDeserialized, esriGeometry); }
@Test public void testSerializeDeserialize() { AccumulatorStateFactory<GeometryState> factory = StateCompiler.generateStateFactory(GeometryState.class); AccumulatorStateSerializer<GeometryState> serializer = StateCompiler.generateStateSerializer(GeometryState.class); GeometryState state = factory.createSingleState(); state.setGeometry(OGCGeometry.fromText("POINT (1 2)")); BlockBuilder builder = GeometryType.GEOMETRY.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); assertEquals(GeometryType.GEOMETRY.getObjectValue(null, block, 0), "POINT (1 2)"); state.setGeometry(null); serializer.deserialize(block, 0, state); assertEquals(state.getGeometry().asText(), "POINT (1 2)"); }
private static OGCGeometry geometryFromText(Slice input) { OGCGeometry geometry; try { geometry = OGCGeometry.fromText(input.toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKT: " + input.toStringUtf8(), e); } geometry.setSpatialReference(null); return geometry; }
private static OGCGeometry geometryFromText(Slice input) { OGCGeometry geometry; try { geometry = OGCGeometry.fromText(input.toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKT: " + input.toStringUtf8(), e); } geometry.setSpatialReference(null); return geometry; }
@Test public void testCreateSingleStatePresent() { GeometryState state = factory.createSingleState(); state.setGeometry(OGCGeometry.fromText("POINT (1 2)")); assertEquals(OGCGeometry.fromText("POINT (1 2)"), state.getGeometry()); assertTrue(state.getEstimatedSize() > 0, String.format("Estimated memory size was %d", state.getEstimatedSize())); }
@Test public void testCreateSingleStatePresent() { GeometryState state = factory.createSingleState(); state.setGeometry(OGCGeometry.fromText("POINT (1 2)")); assertEquals(OGCGeometry.fromText("POINT (1 2)"), state.getGeometry()); assertTrue(state.getEstimatedSize() > 0, String.format("Estimated memory size was %d", state.getEstimatedSize())); }
private static void testEsriSerialization(String wkt) { OGCGeometry expected = OGCGeometry.fromText(wkt); OGCGeometry actual = deserialize(serialize(expected)); assertGeometryEquals(actual, expected); }
private static void testEsriSerialization(String wkt) { OGCGeometry expected = OGCGeometry.fromText(wkt); OGCGeometry actual = deserialize(serialize(expected)); assertGeometryEquals(actual, expected); }
private static void testJtsSerialization(String wkt) { Geometry jtsGeometry = createJtsGeometry(wkt); OGCGeometry esriGeometry = OGCGeometry.fromText(wkt); Slice jtsSerialized = JtsGeometrySerde.serialize(jtsGeometry); Slice esriSerialized = GeometrySerde.serialize(esriGeometry); assertEquals(jtsSerialized, esriSerialized); Geometry jtsDeserialized = JtsGeometrySerde.deserialize(jtsSerialized); assertGeometryEquals(jtsDeserialized, jtsGeometry); OGCGeometry esriDeserialized = GeometrySerde.deserialize(esriSerialized); assertGeometryEquals(esriDeserialized, esriGeometry); }
private static void testJtsSerialization(String wkt) { Geometry jtsGeometry = createJtsGeometry(wkt); OGCGeometry esriGeometry = OGCGeometry.fromText(wkt); Slice jtsSerialized = JtsGeometrySerde.serialize(jtsGeometry); Slice esriSerialized = GeometrySerde.serialize(esriGeometry); assertEquals(jtsSerialized, esriSerialized); Geometry jtsDeserialized = JtsGeometrySerde.deserialize(jtsSerialized); assertGeometryEquals(jtsDeserialized, jtsGeometry); OGCGeometry esriDeserialized = GeometrySerde.deserialize(esriSerialized); assertGeometryEquals(esriDeserialized, esriGeometry); }