public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); String geomWKT = geom1.asText(); int outputSize = geomWKT.getBytes().length; buffer = out.buffer = buffer.reallocIfNeeded(outputSize); out.start = 0; out.end = outputSize; buffer.setBytes(0, geomWKT.getBytes()); } }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, block.getSliceLength(position)); return deserialize(slice).asText(); } }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, block.getSliceLength(position)); return deserialize(slice).asText(); } }
@Description("Returns the Well-Known Text (WKT) representation of the geometry") @ScalarFunction("ST_AsText") @SqlType(VARCHAR) public static Slice stAsText(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { return utf8Slice(deserialize(input).asText()); }
@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)"); }
@Override public String toString() { return geom.asText(); }
@Override protected Object evaluateOGCGeometry(OGCGeometry geometry) throws HyracksDataException { return geometry.asText(); }
public GeoException(OGCGeometry geom, Exception e) { super("Error processing the shape " + (geom == null? "<null>" : geom.asText()), e); }
public GeoException(OGCGeometry geom) { super("Error processing the shape " + (geom == null? "<null>" : geom.asText())); }
@Override public String toString() { String snippet = asText(); if (snippet.length() > 200) { snippet = snippet.substring(0, 197) + "..."; } return String .format("%s: %s", this.getClass().getSimpleName(), snippet); }
@Override public String toString() { String snippet = asText(); if (snippet.length() > 200) { snippet = snippet.substring(0, 197) + "..."; } return String .format("%s: %s", this.getClass().getSimpleName(), snippet); }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, block.getSliceLength(position)); return deserialize(slice).asText(); } }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, block.getSliceLength(position)); return deserialize(slice).asText(); } }
@Override public String exec(Tuple t) throws IOException { if (t.size() != 1) throw new GeoException("ST_AsText expects one geometry argument"); OGCGeometry geom = geometryParser.parseGeom(t.get(0)); try { return geom.asText(); } catch (Exception e) { throw new GeoException(e); } }
@Description("Returns the Well-Known Text (WKT) representation of the geometry") @ScalarFunction("ST_AsText") @SqlType(VARCHAR) public static Slice stAsText(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { return utf8Slice(deserialize(input).asText()); }
@Description("Returns the Well-Known Text (WKT) representation of the geometry") @ScalarFunction("ST_AsText") @SqlType(VARCHAR) public static Slice stAsText(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { return utf8Slice(deserialize(input).asText()); }
@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)"); }
@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)"); }