@Override public Geometry toParticle( ResultSet rs, int colIndex ) throws SQLException { Object sqlValue = rs.getObject( colIndex ); try { if ( sqlValue != null ) { if ( sqlValue instanceof byte[] ) { if ( is2d ) { return WKBReader.read( (byte[]) sqlValue, crs ); } // hur hur, not using cp1252 any more, are we? sqlValue = new String( (byte[]) sqlValue, "UTF-16LE" ); } return new WKTReader( crs ).read( sqlValue.toString() ); } } catch ( Throwable e ) { throw new SQLException( e ); } return null; }
public Geometry read( Reader reader ) throws ParseException { try { return read( IOUtils.toString( reader ) ); } catch ( IOException e ) { // wrap the exception nicely as to not break 172643521 API calls throw new ParseException( e ); } }
@Override public <T> TypedObjectNode[] evaluate( T obj, XPathEvaluator<T> xpathEvaluator ) throws FilterEvaluationException { TypedObjectNode[] crs = getParams()[0].evaluate( obj, xpathEvaluator ); TypedObjectNode[] geom = getParams()[1].evaluate( obj, xpathEvaluator ); if ( crs.length != 1 ) { throw new FilterEvaluationException( "The GeometryFromWKT function's first argument must " + "evaluate to exactly one value." ); } if ( geom.length != 1 ) { throw new FilterEvaluationException( "The GeometryFromWKT function's second argument must " + "evaluate to exactly one value." ); } ICRS srs = CRSManager.getCRSRef( crs[0].toString() ); String wkt = geom[0].toString(); WKTReader reader = new WKTReader( srs ); try { return new TypedObjectNode[] { reader.read( wkt ) }; } catch ( ParseException e ) { LOG.trace( "Stack trace:", e ); throw new FilterEvaluationException( "GeometryFromWKT error while parsing WKT: " + e.getLocalizedMessage() ); } } };